0377lilitian
2009-08-10, 20:45
i=imread('lena.png');
subplot(2,2,1);
imshow(i);
title('原始图像');
%生成含噪图像并显示
j=imnoise(i,'gaussian',0,0.001);
subplot(2,2,2);
imshow(j);
title('含噪图像');
%用sym4小波函数对j进行2层分解
[c,l]=wavedec2(j,2,'sym4');
%实现低通滤波消噪
a1=uint8(wrcoef2('a',c,l,'sym4',2));
%用coif2小波函数对j进行2层分解
[gc,gl]=wavedec2(a1,2,'coif2');
n=[1,2];%设置尺度向量
p=[10.28,24.08];%设置阈值向量
%对三个高频系数进行阈值处理
nc=wthcoef2('h',gc,gl,n,p,'s');
nc=wthcoef2('v',gc,gl,n,p,'s');
nc=wthcoef2('d',gc,gl,n,p,'s');
mc=wthcoef2('h',gc,gl,n,p,'s');
mc=wthcoef2('v',gc,gl,n,p,'s');
mc=wthcoef2('d',gc,gl,n,p,'s');
%对更新后的小波分解结构进行阈值处理
x2=waverec2(mc,gl,'coif2');
%进行中值滤波
for ii=1:252;
for jj=1:252;
temp=0;
for m=0:3
for n=0:3
temp=temp+double(x2(ii+m,jj+n));
end
end
temp=temp/16;
x4(ii,jj)=temp;
end
end
for ii=253:256
for jj=253:256
x4(ii,jj)=double(i(ii,jj));
end
end
%显示去噪图像
subplot(2,2,3);
imshow(uint8(x4));
title('消噪图像');
subplot(2,2,1);
imshow(i);
title('原始图像');
%生成含噪图像并显示
j=imnoise(i,'gaussian',0,0.001);
subplot(2,2,2);
imshow(j);
title('含噪图像');
%用sym4小波函数对j进行2层分解
[c,l]=wavedec2(j,2,'sym4');
%实现低通滤波消噪
a1=uint8(wrcoef2('a',c,l,'sym4',2));
%用coif2小波函数对j进行2层分解
[gc,gl]=wavedec2(a1,2,'coif2');
n=[1,2];%设置尺度向量
p=[10.28,24.08];%设置阈值向量
%对三个高频系数进行阈值处理
nc=wthcoef2('h',gc,gl,n,p,'s');
nc=wthcoef2('v',gc,gl,n,p,'s');
nc=wthcoef2('d',gc,gl,n,p,'s');
mc=wthcoef2('h',gc,gl,n,p,'s');
mc=wthcoef2('v',gc,gl,n,p,'s');
mc=wthcoef2('d',gc,gl,n,p,'s');
%对更新后的小波分解结构进行阈值处理
x2=waverec2(mc,gl,'coif2');
%进行中值滤波
for ii=1:252;
for jj=1:252;
temp=0;
for m=0:3
for n=0:3
temp=temp+double(x2(ii+m,jj+n));
end
end
temp=temp/16;
x4(ii,jj)=temp;
end
end
for ii=253:256
for jj=253:256
x4(ii,jj)=double(i(ii,jj));
end
end
%显示去噪图像
subplot(2,2,3);
imshow(uint8(x4));
title('消噪图像');