20 views (last 30 days)

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

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.

Image Analyst
on 8 Jun 2020

Image Analyst
on 9 Jun 2020

Thiago Henrique Gomes Lobato
on 7 Jun 2020

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');

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940779

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940779

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940785

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940785

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940833

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/543803-7x7-arithmetic-mean-filter#comment_940833

Sign in to comment.