首页 > 化工知识 > 【图像去噪】基于改进小波阈值实现图像去噪matlab代码

【图像去噪】基于改进小波阈值实现图像去噪matlab代码

时间:2021-11-25 来源: 浏览:

【图像去噪】基于改进小波阈值实现图像去噪matlab代码

原创 天天Matlab 天天Matlab
天天Matlab

TT_Matlab

每天分享一点Matlab资料,一起成长进步。需要定制程序添加qq1575304183

收录于话题 #图像处理matlab源码 254个 内容

1 简介

基于 Donoho经典小波阈值去除图像噪声基本思路,分析常用硬阈值法和软阈值法在图像去噪中的缺陷。针对这些缺陷,提出一种改进的阈值去噪法,该方法不仅可克服硬阈值不连续的缺点,还能够有效解决小波分解预估计系数与真实小波系数间存有的恒定误差。通过 Matlab仿真实验,使用改进的小波阈值法对图像去噪处理后,除 噪效果比较理想,在去噪性能指标上,PSNR(峰值信噪比)和 EPI(边缘保护指数)均好于传统阈值方法。

采集、编码或者传输图像时,图像容易遭受噪声污染,因此图像去噪尤为重要。随着对小波理论研究的深入,其应用也日趋广泛,利用小波变换进行图像去噪成为研究热点。目前,小波图像去噪 基 本 方 法 有:①利用小波变换模极大值方法进行图像去噪;②利用小波变换尺度相关性方法进行图像去 噪;③利用小波阈值去噪法进行图像去噪。上述3种基 本 方 法 中,小波阈值去噪法相对于小波模极大值法与小波变换尺度相关性法,其 运 算 量 小,实现简单且使用广泛。小波阈值去噪法也有其不足:在小波硬阈值去噪处理过程中,获取的小波系 数 预 估 计 连 续 性 差,会 造 成 重 构 信号波动,而软阈值法算出的估计小波系数虽然连续性较好,但其与真实小波系数有恒定偏差,造成重构信号精度变低,导致图像模糊。本文结合经典硬阈值和软阈值法各自的优缺点,提出一种改进的小波阈值图像去噪算法。

2 部分代码

% 对彩色图像进行去噪 clc clear all close all 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 ; subplot ( 341 ); imshow ( X );           title ( ’原图像’ ); subplot ( 342 ); imshow ( x_noise );     title ( ’带噪声图像’ ); subplot ( 343 ); imshow ( x_soft );     title ([ ’Donoho 软阈值,信噪比=’ , num2str ( psnr_soft )]); subplot ( 344 ); imshow ( x_hard );     title ([ ’Donoho 硬阈值,信噪比=’ , num2str ( psnr_hard )]); subplot ( 345 ); imshow ( x_soft_lvd ); title ([ ’Birge-Massart 软阈值,信噪比=’ , num2str ( psnr_soft_lvd )]); subplot ( 346 ); imshow ( x_hard_lvd ); title ([ ’Birge-Massart 硬阈值,信噪比=’ , num2str ( psnr_hard_lvd )]); subplot ( 347 ); imshow ( x1 );         title ([ ’半软阈值,信噪比=’ , num2str ( psnr1 )]) ; subplot ( 348 ); imshow ( x1_5 );       title ([ ’半软阈值+均值滤波,信噪比=’ , num2str ( psnr1_5 )]); subplot ( 349 ); imshow ( x4 );         title ([ ’自适应阈值,信噪比=’ , num2str ( psnr4 )]); % 中值滤波 均值滤波======================================================== 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 ); subplot ( 3 , 4 , 10 ); imshow ( x_mean ); title ([ ’均值滤波,信噪比=’ , num2str ( psnr_mean )]); subplot ( 3 , 4 , 11 ); imshow ( x_med );   title ([ ’中值滤波,信噪比=’ , num2str ( psnr_med )]); % =========================================================================

3 仿真结果

4 参考文献

[1]林东升. 基于Matlab的小波阈值图像去噪方法研究[J]. 电脑知识与技术, 2013(4X):3.

天天Matlab

赞赏二维码 微信扫一扫赞赏作者 赞赏

已喜欢, 对作者说句悄悄话
最多40字,当前共

  人赞赏

1 / 3

长按二维码向我转账

赞赏二维码

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

版权:如无特殊注明,文章转载自网络,侵权请联系cnmhg168#163.com删除!文件均为网友上传,仅供研究和学习使用,务必24小时内删除。
相关推荐