?1,基于小波变换的图像低通滤波
%小波变换进行滤波变换
clc,clear,close all;
Image = rgb2gray(imread('baboon.jpg'));
nIg = imnoise(Image,'gaussian');
[C,S] = wavedec2(nIg,3,'db4');%采用db4小波对噪声图像进行3级分解
len = length(C);
C1 = C;C2 = C;C3 = C;
C1(S(1,1)*S(1,2)+1:len) = 0;%设置所有高频系数为0
C2(S(1,1)*S(1,2)+1:len) = C(S(1,1)*S(1,2)+1:len)/2;%所有高频衰减一半
C3(len-3*S(4,1)*S(4,2)+1:len) = 0;%一级高频系数为0
result1 = waverec2(C1,S,'db4');
result2 = waverec2(C2,S,'db4');
result3 = waverec2(C3,S,'db4');
subplot(221),imshow(nIg),title('噪声图像');
subplot(222),imshow(result1,[]),title('去除高频重构');
subplot(223),imshow(result2,[]),title('高频衰减一半重构');
subplot(224),imshow(result3,[]),title('去除一级高频重构');
结果:
?2,基于小波变换的图像高通滤波
%基于小波变换的图像高通滤波
clc,clear,close all;
Image = rgb2gray(imread('pic01.bmp'));
[C,S] = wavedec2(Image,3,'db4');
len = length(C);
C1 = C;C1(1:S(1,1)*S(1,2))=0;
C2 = C;C2(1:len-3*S(4,1)*S(4,2))=0;
result1=waverec2(C1,S,'db4');
result2=waverec2(C2,S,'db4');
subplot(131),imshow(Image),title('原图像');
subplot(132),imshow(result1,[]),title('保留所有高频重构');
subplot(133),imshow(result2,[]),title('保留一级高频重构');
结果:
3,对小波变换的低频系数进行增强,对高频系数进行弱化
%对小波变换的低频系数进行增强,对高频系数进行弱化
clc,clear,close all;
Image = rgb2gray(imread('pic01.bmp'));
[C,S] = wavedec2(Image,3,'db4');
len = length(C);
T = 150;
pos = S(1,1)*S(1,2);
C1 = C(1:pos);C1(C1>T)=C1(C1>T)*1.5;%低频系数增强
C2 = C(pos+1:len);C2(C2<T)=C2(C2<T)*0.75;%高频系数弱化
C(1:pos)=C1;C(pos+1:len)=C2;
result = waverec2(C,S,'db4');
subplot(121),imshow(uint8(result),[]),title('对比度增强');
subplot(122),imshow(uint8(Image),[]),title('原图');
?结果:
4,利用小波变换实现图像边缘检测
%利用小波变换实现图像边缘检测
clear,clc,close all;
Image = imread('pic01.bmp');
[ca,ch,cv,cd] = dwt2(Image,'db4');%用db4小波对图像进行一级小波分解
result = idwt2(ca*0,ch,cv,cd,'db4')/256;%将低频系数置零
result = result+0.2;%增大0.2,加强细节
subplot(121),imshow(Image),title('原图');
subplot(122),imshow(result),title('边缘检测');
结果:
?
|