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
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
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
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
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!