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.

29 次查看(过去 30 天)
%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');
  7 个评论
VISHNU VARDHAN
VISHNU VARDHAN 2020-4-29
%arithmatic mean filter
clc;
clear all;
close all;
x=imread('1.jpg');
x1=imresize(x,[256,256]);
figure;imshow(x1)
title('original image')%loading image.
x2=rgb2gray(x1);
figure;imshow(x2);title('gray image');
[m,n]=size(x2);%storing size of image.
for i=1:m-3
for j=1:n-3
a=x(i:i+3,j:j+3);
v(i,j)=sum(sum(a));
end
end
y=mat2gray(v);
figure;imshow(y);
title('average image');
this is useful for average of the any hd image.if u want to increase size,change pixcels in imresize command...................
Jahid Hasan
Jahid Hasan 2022-4-19
Is this loop similar to finding mean as well, how about median, what way I can write a Mexican function? Any suggestions

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018-12-20
编辑:KALYAN ACHARJYA 2018-12-20
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);
  13 个评论

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2018-12-20
编辑:Jan 2018-12-20
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
This is a 2x2 window starting right and top of the current pixel. You divide the result repeatedly by 9. I assume you mean:
for i = 2:row-1
for j = 2:col - 1
a = 0;
for u = -1:1
for v = -1:1
a = a + im(i + u, j + v);
end
end
im(i, j) = a / 9;
end
end
conv2 and filter2 will me more efficient.

Community Treasure Hunt

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

Start Hunting!

Translated by