denoise0701.m
上传用户:lcj80317
上传日期:2007-01-26
资源大小:625k
文件大小:5k
- % 对彩色图像进行去噪
- I = imread('lena_color.png', 'png'); % 读入图像
- X = im2double(I); % 转换成双精度类型
- x_noise = noise(X, 'gaussian', 0.01); % 加入高斯噪声
- % 提取三个通道信息
- xr = x_noise(:, :, 1); % R通道
- xg = x_noise(:, :, 2); % G通道
- xb = x_noise(:, :, 3); % B通道
- % 估计三个通道的阈值
- [Cr, Sr] = wavedec2(xr, 2, 'sym4');
- [Cg, Sg] = wavedec2(xg, 2, 'sym4');
- [Cb, Sb] = wavedec2(xb, 2, 'sym4');
- thr_r = Donoho(xr); % R通道全局阈值
- thr_g = Donoho(xg); % G通道全局阈值
- thr_b = Donoho(xb); % B通道全局阈值
- thr_lvd_r = Birge_Massart(Cr, Sr); % R通道局部阈值
- thr_lvd_g = Birge_Massart(Cg, Sg); % G通道局部阈值
- thr_lvd_b = Birge_Massart(Cb, Sb); % B通道局部阈值
- % 对三个通道分别进行去噪===================================================
- % Donoho全局阈值 软阈值公式----------------------------------------------
- x_soft_r = wdenoise(xr, 'gbl', 's', thr_r, 'sym4', 2);
- x_soft_g = wdenoise(xg, 'gbl', 's', thr_g, 'sym4', 2);
- x_soft_b = wdenoise(xb, 'gbl', 's', thr_b, 'sym4', 2);
- % -----------------------------------------------------------------------
- % Donoho全局阈值 硬阈值公式----------------------------------------------
- x_hard_r = wdenoise(xr, 'gbl', 'h', thr_r, 'sym4', 2);
- x_hard_g = wdenoise(xg, 'gbl', 'h', thr_g, 'sym4', 2);
- x_hard_b = wdenoise(xb, 'gbl', 'h', thr_b, 'sym4', 2);
- % -----------------------------------------------------------------------
- % Bige-Massa策略 软阈值公式----------------------------------------------
- x_soft_lvd_r = wdenoise(xr, 'lvd', 's', thr_lvd_r, 'sym4', 2);
- x_soft_lvd_g = wdenoise(xg, 'lvd', 's', thr_lvd_g, 'sym4', 2);
- x_soft_lvd_b = wdenoise(xb, 'lvd', 's', thr_lvd_b, 'sym4', 2);
- % -----------------------------------------------------------------------
- % Bige-Massa策略 硬阈值公式----------------------------------------------
- x_hard_lvd_r = wdenoise(xr, 'lvd', 'h', thr_lvd_r, 'sym4', 2);
- x_hard_lvd_g = wdenoise(xg, 'lvd', 'h', thr_lvd_g, 'sym4', 2);
- x_hard_lvd_b = wdenoise(xb, 'lvd', 'h', thr_lvd_b, 'sym4', 2);
- % -----------------------------------------------------------------------
- % 半软阈值---------------------------------------------------------------
- x1_r = den1(xr, 'sym4', 2, thr_r);
- x1_g = den1(xg, 'sym4', 2, thr_g);
- x1_b = den1(xb, 'sym4', 2, thr_b);
- % -----------------------------------------------------------------------
- % 半软阈值 + 均值滤波----------------------------------------------------
- x1_5_r = den1_5_1(xr, 'sym4', 2, thr_r, 0.5*thr_r);
- x1_5_g = den1_5_1(xg, 'sym4', 2, thr_g, 0.5*thr_g);
- x1_5_b = den1_5_1(xb, 'sym4', 2, thr_b, 0.5*thr_b);
- % -----------------------------------------------------------------------
- % 自适应阈值-------------------------------------------------------------
- x4_r = den4(xr, 'sym4', 2);
- x4_g = den4(xg, 'sym4', 2);
- x4_b = den4(xb, 'sym4', 2);
- % -----------------------------------------------------------------------
- % =========================================================================
- % 恢复去噪后的图像=========================================================
- x_soft = cat(3, x_soft_r, x_soft_g, x_soft_b); % Donoho 软阈值
- x_hard = cat(3, x_hard_r, x_hard_g, x_hard_b); % Donoho 硬阈值
- x_soft_lvd = cat(3, x_soft_lvd_r, x_soft_lvd_g, x_soft_lvd_b); %Birge-Massart 软阈值
- x_hard_lvd = cat(3, x_hard_lvd_r, x_hard_lvd_g, x_hard_lvd_b); % Birge-Massart 硬阈值
- x1 = cat(3, x1_r, x1_g, x1_b); % 半软阈值
- x1_5 = cat(3, x1_5_r, x1_5_g, x1_5_b); % 半软阈值 + 均值滤波
- x4 = cat(3, x4_r, x4_g, x4_b); % 自适应阈值
- % =========================================================================
- psnr_soft = PSNR_color(x_soft, X)
- psnr_hard = PSNR_color(x_hard, X)
- psnr_soft_lvd = PSNR_color(x_soft_lvd, X)
- psnr_hard_lvd = PSNR_color(x_hard_lvd, X)
- psnr1 = PSNR_color(x1, X)
- psnr1_5 = PSNR_color(x1_5, X)
- psnr4 = PSNR_color(x4, X)
- figure; imshow(X); title('原图像');
- figure; imshow(x_noise); title('带噪声图像');
- figure; imshow(x_soft); title('Donoho 软阈值');
- figure; imshow(x_hard); title('Donoho 硬阈值');
- figure; imshow(x_soft_lvd); title('Birge-Massart 软阈值');
- figure; imshow(x_hard_lvd); title('Birge-Massart 硬阈值');
- figure; imshow(x1); title('半软阈值')';
- figure; imshow(x1_5); title('半软阈值 均值滤波');
- figure; imshow(x4); title('自适应阈值');
- % 中值滤波 均值滤波========================================================
- f = ones(3);
- % filter2函数用于图像均值滤波
- x_mean_r = meanfilter(xr,f);
- x_mean_g = meanfilter(xg,f);
- x_mean_b = meanfilter(xb,f);
- x_mean = cat(3, x_mean_r, x_mean_g, x_mean_b);
- % medfilt2函数用于图像中值滤波
- x_med_r = medfilter(xr, f);
- x_med_g = medfilter(xg, f);
- x_med_b = medfilter(xb, f);
- x_med = cat(3, x_med_r, x_med_g, x_med_b);
- psnr_mean = PSNR_color(x_mean, X)
- psnr_med = PSNR_color(x_med, X)
- figure; imshow(x_mean); title('均值滤波');
- figure; imshow(x_med); title('中值滤波');
- % =========================================================================