小波图像去噪后每次算出来的psnr都不一样。。
每次算出来的峰值信噪有时候比中值滤波的大,有时候还小。怎么回事啊。请各位看看。。A=imread('concordorthophoto.png');
%--------------------------------------------------------------------------
%为源图像加上高斯噪声
B=imnoise(A,'gaussian',0,0.006);
imwrite(B,'concordorthophoto.png','png');
A1=im2double(A);
B1=im2double(B);
%--------------------------------------------------------------------------
%计算去噪前的PSNR值
=size(A);
err=0;
sum=0;
for i=1:m,
for j=1:n,
err=err+(A1(i,j)-B1(i,j))*(A1(i,j)-B1(i,j));
sum=sum+A1(i,j)*A1(i,j);
end
end
psnr=err/sum;
psnr_before_noisedelete=-10*log10(psnr)
PSNR1=num2str(psnr_before_noisedelete);
%--------------------------------------------------------------------------
%小波分解去噪。使用wdcbm2获得图像去噪阈值,然后用函数wdencmp实现图像去噪
%使用haar小波进行二层分解
wname='haar';lev=2;
=wavedec2(B1,lev,wname);
%使用wdcbm2获得去噪阈值
alpha=3;m=3.5*prod(s(1,:));
=wdcbm2(c,s,alpha,m);
%对信号进行去噪
sorh='s';
xd=wdencmp('lvd',c,s,wname,lev,thr,sorh);
imwrite(xd,'concordorthophoto.png','png');
%--------------------------------------------------------------------------
%计算软阈值小波去噪后的PSNR值
=size(A1);
err=0;
sum=0;
for i=1:m,
for j=1:n,
err=err+(A1(i,j)-xd(i,j))*(A1(i,j)-xd(i,j));
sum=sum+A1(i,j)*A1(i,j);
end
end
psnr=err/sum;
psnr_after_noisedelete=-10*log10(psnr)
PSNR2=num2str(psnr_after_noisedelete);
%小波分解去噪。使用wdcbm2获得图像去噪阈值,然后用函数wdencmp实现图像去噪
%使用haar小波进行二层分解
wname='haar';lev=2;
=wavedec2(B1,lev,wname);
%使用wdcbm2获得去噪阈值
alpha=3;m=3.5*prod(s(1,:));
=wdcbm2(c,s,alpha,m);
%对信号进行去噪
sorh='h';
xd1=wdencmp('lvd',c,s,wname,lev,thr,sorh);
imwrite(xd1,'concordorthophoto.png','png');
%计算硬阈值小波去噪后的PSNR值
=size(A1);
err=0;
sum=0;
for i=1:m,
for j=1:n,
err=err+(A1(i,j)-xd1(i,j))*(A1(i,j)-xd1(i,j));
sum=sum+A1(i,j)*A1(i,j);
end
end
psnr=err/sum;
psnr_after_noisedelete=-10*log10(psnr)
PSNR3=num2str(psnr_after_noisedelete);
%--------------------------------------------------------------------------
%采用中值去噪并计算去噪后的PSNR值
C=medfilt2(B1);
=size(A1);
err=0;
sum=0;
for i=1:m,
for j=1:n,
err=err+(A1(i,j)-C(i,j))*(A1(i,j)-C(i,j));
sum=sum+A1(i,j)*A1(i,j);
end
end
psnr=err/sum;
psnr_after_medfiltering=-10*log10(psnr)
PSNR4=num2str(psnr_after_medfiltering);
imwrite(C,'concordorthophoto.png','png');
clf;
subplot(2,3,1),imshow(A);title('原始图像');
subplot(2,3,2),imshow(C);title('中值去噪后的图像');xlabel(['PSNR=',PSNR4]);
subplot(2,3,3),imshow(B);title('加入高斯噪声后图像');xlabel(['PSNR=',PSNR1]);
subplot(2,3,4),imshow(xd);title('软阈值去噪图像');xlabel(['PSNR=',PSNR2]);
subplot(2,3,5),imshow(xd1);title('硬阈值去噪图像');xlabel(['PSNR=',PSNR3]); 因为所加噪声为随机分布,其实每次加的噪声都是不一样的,当然PSNR值不一样了
页:
[1]