Median filter
古いコメントを表示
I am trying to understand the working of median filter. this is the code %start
A = imread('/*path name*/') ;
A = im2double(A);
[m n] = size(A);
Med = [];
%Modified filter
for i=2:m-1
for j=2:n-1
Med(1) = A(i-1,j-1);
Med(2) =A(i-1,j) ;
Med(3) = A(i-1,j+1);
Med(4) = A(i,j-1);
Med(5) = A(i,j+1);
Med(6) = A(i+1, j-1);
Med(7) = A(i+1,j);
Med(8) = A(i+1,j+1);
A(i,j) = median(Med);
end
end
imshow(A);
but the output is not as expected. it is blurry. need help..
2 件のコメント
Ahmed
2013 年 3 月 28 日
I tried this code in my research for 2-D medical images and i get a good results better than the standard function of median in matlab and i can send the result to compare between the standard median and this modified one
Changa Hettiarachchi
2020 年 3 月 6 日
Why i get an error in line Med(1)???

採用された回答
その他の回答 (1 件)
Bjorn Gustavsson
2011 年 5 月 17 日
1 投票
The way you do your itterative medians lead to not taking the median of the input image for pixel [i,j] except for the very first pixel (i=2, j=2). After that (say i=2, j=3) you have overwritten the original pixel value in some of the neighbouring pixels (for the example pixel you'd have the 3-by-3 median in pixel A(2,2), not the original pixel intensity). You should assign the median filtered intensities to pixels in another image array, say Afiltered(i,j).
HTH, Bjeorn
4 件のコメント
Darshan A
2011 年 5 月 17 日
Bjorn Gustavsson
2011 年 5 月 17 日
What have you tried? Your code "worked", just replace everywhere you assign to A in the median-filtering loop, and the imshow call.
Darshan A
2011 年 5 月 18 日
Andrei Bobrov
2011 年 5 月 18 日
analog function medfil2 <http://www.mathworks.com/matlabcentral/answers/5656-program-to-find-the-median-of-the-matrix-need-to-use-for-loop>
カテゴリ
ヘルプ センター および File Exchange で Matched Filter and Ambiguity Function についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!