MATLAB: How to apply the arithmetic mean filter to a medical image to improve it? I have wrote this code but it did not work, there is an error which I could not figure it out.

digital image processingfilterimage processing

%arithmatic mean filter
im=imread('chest.tif');%loading image
figure,imshow(im);
title('original');
[row col]=size(im);%storing size of image
for i=1:1:row-2;%sweeping through rows
for j=1:1:col-2;%sweeping through columns
for u=1:1:2;%sweeping through window
for v=1:1:2;
%taking arithmetic mean
im(i,j)=im(i,j)+im(i+u,j+v);
im(i,j)=im(i,j)/9;
end
end
end
end
%showing final image
figure,imshow(im);
title('arthmean');

Best Answer

Avoid multiple for loops, use inbuilt imfilter function for masking operation.
The concept is same in all images. For image enhancement you can perform numerous operation depends on input image.
%arithmetic mean filter
im=rgb2gray(imread('chest.tif'));
h=fspecial('average',3);
filter_image=imfilter(im,h);
Related Question