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 ビュー (過去 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 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 12 月 20 日
編集済み: KALYAN ACHARJYA 2018 年 12 月 20 日
Welcome !

サインインしてコメントする。

その他の回答 (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