Creating 9x9 average filter and applying it to an image with certain values.

198 views (last 30 days)
Hi again, first how to create a 9x9 average filter. I know how to create 3x3 average filter -
>> F = fspecial('average');
But how do I make it to be 9x9?
Also for the boundaries do I just put the value like that(I will show the whole code):
>> I = imread('cameraman.tif');
>> F = fspecial('average');
>> J = imfilter(I,F,255);
The last line creates the boundary to be with value X=255. Also when I do it, why I don't see any change in the picture, it shows the same picture just filtered?

Accepted Answer

Image Analyst
Image Analyst on 19 Oct 2015
I told you how to do a 9x9 in your duplicate question. It's just ones(9)/81.
grayImage = imread('cameraman.tif');
subplot(2,1,1);
imshow(grayImage);
title('Original Image', 'FontSize', 15);
blurredImage = imfilter(grayImage, ones(9)/81, 'symmetric');
subplot(2,1,2);
imshow(blurredImage);
title('Blurred Image', 'FontSize', 15);
  3 Comments
Atalay Asa
Atalay Asa on 7 Jun 2020
Do average filter and average mean filter are same thing? Can we use your code for 9x9 arithmetic mean filter?
Image Analyst
Image Analyst on 7 Jun 2020
Yes, as far as I know they're the same. average and mean are just two words for the same thing and doubling them up doesn't really change the meaning. Yes, my code does a 9x9 filter. More generally
grayImage = imread('cameraman.tif');
subplot(2,1,1);
imshow(grayImage);
title('Original Image', 'FontSize', 15);
windowSize = 9; % Whatever you want.
kernel = ones(windowSize, windowSize) / windowSize ^ 2;
blurredImage = imfilter(grayImage, kernel, 'symmetric');
subplot(2,1,2);
imshow(blurredImage);
title('Blurred Image', 'FontSize', 15);

Sign in to comment.

More Answers (2)

Santhosh Prasad M
Santhosh Prasad M on 26 Jan 2019
Edited: Santhosh Prasad M on 26 Jan 2019
I = imread('cameraman.tif');
figure,imshow(I);title('Original Image');
C=fspecial('average',[9,9]); %exact 9x9 average filter
d=imfilter(I,C);
figure,imshow(d);title('9x9 average filter');

Simran  Kumari
Simran Kumari on 10 Feb 2022
img = imread('exp3.jpeg');
subplot(2,2,1);
imshow(img);
title('Original Image');
I=rgb2gray(img);
subplot(2,2,2);
imshow(I);
title('gray image');
windowSize = 3; % Whatever you want.
kernel = ones(windowSize, windowSize) / windowSize ^ 2;
d = imfilter(I, kernel, 'symmetric');
subplot(2,2,3);
imshow(d);
title('image after filter');

Tags

Community Treasure Hunt

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

Start Hunting!