内容:
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)