Matlab中图片加入噪声
1、添加的是20%的随即噪声
小波变换,加噪,去噪,增强
% 《Denoising and contrast enhancement via wavelet shrinkage and nonlinear adaptive gain》 clear; clc
image=imread('555.jpg'); image=imread('555.jpg');
figure; imshow(image); title('the original image');
% 加噪
image=double(image);
I=image+20*randn(size(image));
figure; imshow(uint8(I)); title('noised image');
% 小波分解 dwtmode('per');
[a1,h1,v1,d1]=dwt2(I,'sym8'); % 从1到3分辨率递减 [a2,h2,v2,d2]=dwt2(a1,'sym8'); [a3,h3,v3,d3]=dwt2(a2,'sym8');
% 计算去噪时的阈值
sigma=median(abs(d1(:)))/0.6745; % 确定噪声标准差 thr=2*sigma; % 权值根据实际情况选取
thr1=thr*2^(-(3-1)/2); % 分层阈值, 从1到3分辨率递增,即这里的th1对应于小波系数的第3层
thr2=thr*2^(-(3-2)/2); thr3=thr*2^(-(3-3)/2);
% 去噪
ccch=soft_t(h3,thr1); cccv=soft_t(v3,thr1); cccd=soft_t(d3,thr1); cch=soft_t(h2,thr2); ccv=soft_t(v2,thr2); ccd=soft_t(d2,thr2); ch=soft_t(h1,thr3); cv=soft_t(v1,thr3); cd=soft_t(d1,thr3);
% 重构去噪图像
cca=idwt2(a3,ccch,cccv,cccd,'sym8'); ca=idwt2(cca,cch,ccv,ccd,'sym8'); J1=idwt2(ca,ch,cv,cd,'sym8'); J1=uint8(J1);
figure; imshow(J1); title('denoised image'); p=psnr(image,J1)
2、加高斯白噪声
% 加噪
image=double(image);
I=awgn(image,5);%加入信噪比为5分贝的高斯白噪声 figure; imshow(uint8(I)); title('noised image');