BlockMean

版本 1.2.0.0 (9.8 KB) 作者: Jan
Mean of rectangular submatrices, fast C-Mex (no running mean)
2.5K 次下载
更新时间 2010/11/5

查看许可证

BLOCKMEAN - Fast mean of rectangular submatrices

The mean of V*W elements along the 1st and 2nd dimension is calculated. This is no running mean filter: The sizes of the 1st and 2nd dimension are reduced by the factors V and W.
I use this as cheap anti-aliasing of RGB images, therefore it is implemented for DOUBLE and UINT8 input.

Y = BlockMean(X, V, W)
Input:
X: UINT8 or DOUBLE array of any size.
V, W: 2 scalars as size of the window. Each element of the output is the
mean over V*W neighbouring elements of the input.
V and W are limited to 256 to limit memory usage.
Output:
Y: UINT8 or DOUBLE array, the 1st and 2nd dimensions are V and W times shorter:
[FIX(X / V) x FIX(Y / W) x (further dims...)]
If the size of the 1st or 2nd dimension is not a multiple of V and W, the
remaining elements at the end are skipped.

E.g. for 4x4 blocks of a 1024x768x3 double array, this MEX implementation is about 5 times faster than the corresponding Matlab method (Matlab 2009a, 1.5GHz Pentium-M, WinXP, MSVC 2008):
reshape(sum(sum(reshape(X, 4, 256, 4, 192, 3), 1), 3), 256, 192, 3).
Run the unit-test uTest_BlockMean to check validity and speed.

Tested with: LCC v2.4, v3.8, Open Watcom 1.8, BCC 5.5, MSVC 2008, Matlab 6.5, 7.7, 7.8, WinXP 32 bit
Compatibility assumed: Linux, MacOS, 64bit.

Pre-compiled Mex: http://www.n-simon.de/mex

I'd appreciate suggestions for improvements and bug reports sent through email - thanks.

引用格式

Jan (2024). BlockMean (https://www.mathworks.com/matlabcentral/fileexchange/24812-blockmean), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux
致谢

启发作品: Conservative regridding

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.2.0.0

No need to enable 80bit extended precision under Linux. This avoids troubles during the compilation.

1.1.0.0

64 bit addressing supported, rectangular blocks: V ~= W, isEqualTol included in the test function

1.0.0.0