MATLAB: 7×7 arithmetic mean filter

blurringImage Processing Toolboxmanual convolutionmeanfilterspatial filtering

How can I apply 7×7 arithmetic mean filter to following image?

Best Answer

You can do this:
windowWidth = 7;
kernel = ones(windowWidth) / windowWidth^2;
outputImage = imfilter(grayImage, kernel);
If you use conv2() you'll need to make sure your input image is not of integer class, so cast it to double first:
outputImage = conv2(double(grayImage), kernel, 'same');
imfilter() does not require casting to double in advance. Also imfilter() does not flip the kernel like convolution does, though for a symmetric filter like this box filter, it doesn't matter if it's flipped or not.