www.pudn.com > DWM.rar > DWMfilter.m, change:2007-07-20,size:1424b


%%% Paper "A new directional weighted median filter for removal of random-valued impulse noise" %%% 
%% the program written by Y. Q. DONG %% 
% function [I,Flag]=DWMfilter(I,Flag,thres,wm1,wm2)    
function [I,Flag]=DWMfilter(I,Flag,thres,wm1,wm2)        
 
[m,n]=size(I); 
% Expand I 
II = padarray(I,[3 3],'symmetric'); 
II(3,:)=[]; 
II(m+3,:)=[]; 
II(:,3)=[]; 
II(:,n+3)=[]; 
 
weight=ones(4,4); 
weight(2,:)=wm1; 
weight(3,:)=wm1; 
%f = waitbar(0,'Applying neighborhood operation...'); 
for i=1:m 
    for j=1:n 
        Direct=[II(i,j),II(i+2,j),II(i+4,j),II(i,j+2)       % each column represents the pixels in each direction without the center pixel; 
                II(i+1,j+1),II(i+2,j+1),II(i+3,j+1),II(i+1,j+2) 
                II(i+3,j+3),II(i+2,j+3),II(i+1,j+3),II(i+3,j+2) 
                II(i+4,j+4),II(i+2,j+4),II(i,j+4),II(i+4,j+2)]; 
        absdiff=abs(Direct-II(i+2,j+2)); 
        absdiff=weight.*absdiff; 
        droad=min(sum(absdiff,1)); 
        %% 
        temp=II(i:i+4,j:j+4); 
        stdval=std(temp(:)); 
        thresh=stdval; 
        %% 
        if droad>thres  
            Flag(i,j)=1; 
            diff=std(Direct,1); 
            [v,dirc]=min(diff); 
            fv=Direct(:,dirc); 
            x=II(i+1:i+3,j+1:j+3); 
            I(i,j)=median([x(:)',fv(2)*ones(1,wm2-1),fv(3)*ones(1,wm2-1)]); 
            II(i+2,j+2)=I(i,j); 
        end 
    end 
%  waitbar(i/n) 
end 
%close(f)