Help With Adaptive Median Filter
Ältere Kommentare anzeigen
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 Kommentare
Image Analyst
am 7 Okt. 2015
You forgot to attach the image. But why aren't you using medfilt2()?
Masoni
am 7 Okt. 2015
Image Analyst
am 7 Okt. 2015
So have you stepped through the code in the debugger to figure out where the wrong result is happening?
Masoni
am 7 Okt. 2015
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 7 Okt. 2015
0 Stimmen
Attached are my adaptive median filter demos for removing salt and pepper noise.
Kategorien
Mehr zu Image Filtering finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







