Help With Adaptive Median Filter
이전 댓글 표시
Could anyone help with this; I am trying to implement adaptive median filter ,and my code isn't generating the right result .
I= imread('Obama.jpg');
I=double(I);
I=I(:,:,1);
p3=0.05; %default
p4=0.95;
b = I;
x2 = rand(size(b));
d = find(x2 < p3/2);
b(d) = 0; % Minimum value
d = find(x2 >= p4);
b(d) = 1; % Maximum (saturated) value
A=b+I;
smax= 9;
K= zeros(size(A));
A=double(A);
[nrows ncols] = size(A);
for rows= smax:nrows-smax
for cols= smax:ncols-smax
for s=3:2:smax
inc=1;
ul=round(s/2);
for r= -ul:ul
for c= -ul:ul
region(inc)= A(rows+r,cols+c);
inc=inc+1;
end
end
kount= sort(region);
rmin= kount(1);
rmax= kount(inc-1);
rmed=kount(inc/2);
A1= rmed-rmin;
A2=rmed-rmax;
if A1>0 && A2<0 %%%go to stage B
B1= A(rows,cols)- rmin;
B2= A(rows,cols)-rmax;%
if B1>0 && B2<0
J= A(rows,cols);
else
J= rmed;
end
else
J=rmed;
end
end
%end
%end
K(rows,cols)=J;
end
end
figure (2),imshow (uint8(K))
figure (1),imshow (uint8(A))
댓글 수: 4
Image Analyst
2015년 10월 7일
You forgot to attach the image. But why aren't you using medfilt2()?
Masoni
2015년 10월 7일
Image Analyst
2015년 10월 7일
So have you stepped through the code in the debugger to figure out where the wrong result is happening?
Masoni
2015년 10월 7일
채택된 답변
추가 답변 (1개)
Image Analyst
2015년 10월 7일
0 개 추천
Attached are my adaptive median filter demos for removing salt and pepper noise.
카테고리
도움말 센터 및 File Exchange에서 Create Plots on Maps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







