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.
32 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lama Awawdeh
le 20 Déc 2018
Commenté : Jahid Hasan
le 19 Avr 2022
%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 commentaires
VISHNU VARDHAN
le 29 Avr 2020
%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
le 19 Avr 2022
Is this loop similar to finding mean as well, how about median, what way I can write a Mexican function? Any suggestions
Réponse acceptée
KALYAN ACHARJYA
le 20 Déc 2018
Modifié(e) : KALYAN ACHARJYA
le 20 Déc 2018
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 commentaires
Plus de réponses (1)
Jan
le 20 Déc 2018
Modifié(e) : Jan
le 20 Déc 2018
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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!