www.pudn.com > DWM.rar > DONG.m, change:2007-07-23,size:1441b


%%% Paper "A new directional weighted median filter for removal of random-valued impulse noise" %%% 
 
clear all, close all 
ImageOrg=imread('lennalocal.jpg'); 
ImageOrg=double(ImageOrg); 
ImageNoisy=impulsenoise(ImageOrg,0.4,'random-value',[0 255]); 
 
I=ImageNoisy; 
% initialize the parameters; 
thres=510; 
wm1=2; wm2=2; 
[Row,Col]=size(I); 
Flag=zeros(Row,Col);    % 0 represents the accurate detection; 1 represents the misdetection; 
 
iter=0; 
while iter<=7 
    [I,Flag]=DWMfilter(I,Flag,thres,wm1,wm2); 
    iter=iter+1; 
    thers=thres*0.8; 
end 
ImageDWM=I; 
 
% Performanece of the image 
PosNoisyPixel=ImageOrg~=ImageNoisy; PosDetectNoisyPixel=Flag~=0; 
SumOfNoise=PosNoisyPixel==1; SumOfNoise=sum(SumOfNoise(:)) 
MissDetect=0; FalseHit=0; HitDetect=0; 
for i=1:Row 
    for j=1:Col 
        if PosNoisyPixel(i,j)==0 & PosDetectNoisyPixel(i,j)~=0 
            FalseHit=FalseHit+1; 
        elseif PosNoisyPixel(i,j)~=0 & PosDetectNoisyPixel(i,j)==0 
            MissDetect=MissDetect+1; 
        elseif PosNoisyPixel(i,j)~=0 & PosDetectNoisyPixel(i,j)~=0 
            HitDetect=HitDetect+1; 
        end 
    end 
end 
FalseHit,MissDetect,HitDetect 
 
[MSE_PreDenoise,PSNR_PreDenoise]=msepsnr(ImageOrg,ImageNoisy); 
[MSE_DWM,PSNR_DWM]=msepsnr(ImageOrg,ImageDWM); 
PSNR_PreDenoise,PSNR_DWM 
figure 
subplot(1,2,1); imshow(ImageOrg,[]);title('the original image'); 
subplot(1,2,2); imshow(ImageDWM,[]);title('the DWM method');