博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

图像小波变换去噪——MATLAB实现

Posted on 2017-11-09 15:46  warmbeast  阅读(16874)  评论(0编辑  收藏  举报

 

clear;                   
[A,map]=imread('C:\Users\wangd\Documents\MATLAB\1.jpg');                
X=rgb2gray(A);  
%画出原始图像  
subplot(2,2,1);imshow(X);
title('原始图像');  
%产生含噪图像  
x=imnoise(X ,'gaussian',0,0.003);
%画出含噪图像  
subplot(2,2,2);imshow(x);  
title('含噪声图像');  
%下面进行图像的去噪处理  
%用小波函数sym4对x进行2层小波分解  
[c,s]=wavedec2(x,2,'sym4');  
%提取小波分解中第一层的低频图像,即实现了低通滤波去噪  
a1=wrcoef2('a',c,s,'sym4');  % a1为 double 型数据;
%画出去噪后的图像  
subplot(2,2,3); imshow(uint8(a1)); % 注意 imshow()和image()显示图像有区别,imshow()不能显示 double 型数据,必须进行转换 uint8(a1);
title('第一次去噪图像');           % 并且image() 显示图像有坐标;
%提取小波分解中第二层的低频图像,即实现了低通滤波去噪  
%相当于把第一层的低频图像经过再一次的低频滤波处理  
a2=wrcoef2('a',c,s,'sym4',2);  
%画出去噪后的图像  
subplot(2,2,4); imshow(uint8(a2)); %image(a2);
title('第二次去噪图像');
%保存图像  
imwrite(x,'C:\Users\wangd\Desktop\2.jpg');
imwrite(uint8(a1),'C:\Users\wangd\Desktop\3.jpg'); %imwrite()保存图像,也需要将数据类型转化为uint8
imwrite(uint8(a2),'C:\Users\wangd\Desktop\4.jpg');