%This file includes a function what is named Updated Median Filtering.
%The input should be a picture(g) and the size of moldboard(Smax).
function f=adpmedian(g,Smax)
%Smax is the size of filtering moldboard.It must be an odd integer.
if (Smax<=1)|(Smax/2==round(Smax/2))|(Smax~=round(Smax))
error('Smax must be an odd integer >1');
end
[M,N]=size(g);
%Initializing...
f=g;
f( : )=0;
alreadyProcessed=false(size(g));
%Start filtering
for k=3:2:Smax
%k*k Minimum filter
zmin=ordfilt2(g,1,ones(k,k),'symmetric');
%k*k Maximum filter
zmax=ordfilt2(g,k*k,ones(k,k),'symmetric');
%k*k Median filter
zmed=medfilt2(g,[k,k],'symmetric');
%Judge that if Zmed is a pulse
processUsingLevelB=(zmed>amin)&(zmax>zmed)&~alreadyProcessed;
%Judge that if Zxy is a pulse
zB=(g>zmin)&(zmax>g);
outputZxy=processUsingLevelB&zB;
outputZmed=processUsingLevelB&~zB;
f(outputZxy)=g(outputZxy);
f(outputZmed)=zmed(outputZmed);
alreadyProcessed=alreadyProcessed | processUsingLevelB;
if all(alreadyProcessed( : ))
break;
end
end
- 1
- 2
- 3
- 4
前往页