內容:
matlab編程小波變換進行圖像去噪處理,包括各種軟硬閾值的選取函數,%小波閾值去噪
clear all
clc;
f=imread('graylena.bmp');
f=double(f);
s=size(f);
r=imnoise2('gaussian',s(1),s(2),0,20);%填加高斯白噪聲
fnoisy=f+r;
%對圖像進行三層小波分解
[c,s]=wavedec2(fnoisy,3,'db8');
%cA3=appcoef2(c,s,'db8',3);
[cH3,cV3,cD3]=detcoef2('all',c,s,3);c3=[cH3,cV3,cD3];
[cH2,cV2,cD2]=detcoef2('all',c,s,2);c2=[cH2,cV2,cD2];
[cH1,cV1,cD1]=detcoef2('all',c,s,1);c1=[cH1,cV1,cD1];
%固定閾值(VisuShrink閾值):thr=delta*sqrt(2*log(n));
delta=median(abs(cD1(:)))/0.6745;
thr1c=delta*thselect(c,'minimaxi');
%thr1c=delta*3.5;
%thr1c3=delta*thselect(c3,'sqtwolog');
%thr1c2=delta*thselect(c2,'sqtwolog');
%thr1c1=delta*thselect(c1,'sqtwolog');
n=[1 2 3];p=[thr1c thr1c thr1c];
dnc0=wthcoef2('h',c,s,n,p,'s');
dnc0=wthcoef2('v',dnc0,s,n,p,'s');
dnc0=wthcoef2('d',dnc0,s,n,p,'s');
dnf0=waverec2(dnc0,s,'db8');
%基于Stein的無偏似然估計原理的自適應閾值(SUREShrink閾值):
%thr1cA3=thselect(cA3,'rigrsure');
%thr1=surethr(c,delta);
%最優預測變量閾值:
%極大極小閾值:thr=0.3936+0.1829*(log(n)/log(2));
%figure,subplot(221),imshow(dnf0,[]), ('VisuShrink閾值')
origif=cacupsnr(fnoisy,f)
%VSf0=cacupsnr(dnf0,f)
figure,subplot(121),imshow(f,[]), ('原始圖像')
subplot(122),imshow(fnoisy,[]), ('加噪圖像')
dnc1=wthresfunc(c,s,'hard',thr1c);
dnf1=waverec2(dnc1,s,'db8');
figure,subplot(221),imshow(dnf1,[]), ('硬閾值函數')
VSf1=cacupsnr(dnf1,f)
dnc2=wthresfunc(c,s,'soft',thr1c);
dnf2=waverec2(dnc2,s,'db8');
subplot(222),imshow(dnf2,[]), ('軟閾值函數')
VSf2=cacupsnr(dnf2,f)
dnc3=wthresfunc(c,s,'semisoft',thr1c);
dnf3=waverec2(dnc3,s,'db8');
subplot(224),imshow(dnf3,[]), ('折中閾值函數')
VSf3=cacupsnr(dnf3,f)
dnc4=wthresfunc(c,s,'halfsoft',thr1c);
dnf4=waverec2(dnc4,s,'db8');
subplot(223),imshow(dnf4,[]), ('半軟閾值函數')
VSf4=cacupsnr(dnf4,f)
dnc1=wthresfunc(c,s,'upsoft',thr1c);
dnf1=waverec2(dnc1,s,'db8');
figure,subplot(221),imshow(dnf1,[]), ('改進軟閾值函數')
VSf1=cacupsnr(dnf1,f)
dnc2=wthresfunc(c,s,'hfsmsoft',thr1c);
dnf2=waverec2(dnc2,s,'db8');
subplot(222),imshow(dnf2,[]), ('新閾值函數')
VSf2=cacupsnr(dnf2,f)
dnc3=wthresfunc(c,s,'newthr1',thr1c);
dnf3=waverec2(dnc3,s,'db8');
subplot(223),imshow(dnf3,[]), ('改進閾值函數一')
VSf3=cacupsnr(dnf3,f)
dnc4=wthresfunc(c,s,'newthr2',thr1c);
dnf4=waverec2(dnc4,s,'db8');
subplot(224),imshow(dnf4,[]), ('改進閾值函數二')
VSf4=cacupsnr(dnf4,f)