7x7 arithmetic mean filter

122 views (last 30 days)
Atalay Asa
Atalay Asa on 7 Jun 2020
Commented: Image Analyst on 17 Jul 2020
How can I apply 7x7 arithmetic mean filter to following image?
  3 Comments
Image Analyst
Image Analyst on 17 Jul 2020
faysal, are your two comments above "Answers"? If so, put them below in the official Answers area, not up here in comments. That way you can get credit (reputation points) for them. The comments section up here is where people are supposed to ask for clarification of a question, not offer solutions.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Jun 2020
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.
  4 Comments
Image Analyst
Image Analyst on 9 Jun 2020
You're welcome. Then since conv2() is a built-in function, it seems mine is the Answer that you should "Accept". Thanks in advance.

Sign in to comment.

More Answers (1)

Thiago Henrique Gomes Lobato
You can colvolve the image with a filter that will perform the average. In your case it will be something like this:
I = randn(50,50); % Substitute this by your image
N = 7;
F = ones(N)/(N.^2); % Each element is scaled so the sum of all will be 1
IFiltered = conv2(I,F,'same');

Community Treasure Hunt

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

Start Hunting!

Translated by