本程序提供了利用MATLAB进行小波变换的基本方法和应用示例,适用于信号处理、图像压缩等领域的分析与研究。
以下是使用MATLAB进行二维小波变换的示例程序:
```matlab
% FWT_DB.M; 此示意程序用DWT实现二维小波变换。
% 编程时间2004-4-10,编程人沙威
clear;
clc;
T = 256; % 图像维数
SUB_T = T / 2; % 子图维数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 调用原始图像矩阵
load wbarb; % 下载图像
f = X; % 原始图像
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 进行二维小波分解
l = wfilt(db10, d); % db10(消失矩为10)低通分解滤波器冲击响应(长度为20)
L = T - length(l);
l_zeros = [l zeros(1,L)]; % 矩阵行数与输入图像一致,为2的整数幂
h = wfilt(db10, r); % db10(消失矩为10)高通分解滤波器冲击响应(长度为20)
h_zeros = [h zeros(1,L)]; % 矩阵行数与输入图像一致,为2的整数幂
for i=1:T;
row(1:SUB_T,i)=dyaddown(ifft(fft(l_zeros) .* fft(f(:,i)))); % 圆周卷积<->FFT
row(SUB_T+1:T,i)=dyaddown(ifft(fft(h_zeros) .* fft(f(:,i)))); % 圆周卷积<->FFT
end;
for j=1:T;
line(j,1:SUB_T)=dyaddown(ifft(fft(l_zeros) .* fft(row(j,:))));
line(j,SUB_T+1:T)=dyaddown(ifft(fft(h_zeros) .* fft(row(j,:))));
end;
decompose_pic = line; % 分解矩阵
% 图像分为四块
lt_pic=decompose_pic(1:SUB_T, 1:SUB_T); % 在矩阵左上方为低频分量--fi(x)*fi(y)
rt_pic=decompose_pic(1:SUB_T, SUB_T+1:T); % 矩阵右上为--fi(x)*psi(y)
lb_pic=decompose_pic(SUB_T+1:T, 1:SUB_T); % 矩阵左下为--psi(x)*fi(y)
rb_pic=decompose_pic(SUB_T+1:T, SUB_T+1:T); % 右下方为高频分量--psi(x)*psi(y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 分解结果显示
figure(1);
colormap(map);
subplot(2, 1, 1);
image(f);
title(原始图像);
subplot(2, 1, 2);
image(abs(decompose_pic)); % 分解后图像
title(分解后的图像);
figure(2);
colormap(map);
subplot(2, 2, 1);
image(abs(lt_pic));
title(\Phi(x)*\Phi(y));
subplot(2, 2, 2);
image(abs(rt_pic));
title(\Phi(x)*\Psi(y));
subplot(2, 2, 3);
image(abs(lb_pic));
title(\Psi(x)*\Phi(y));
subplot(2, 2, 4);
image(abs(rb_pic));
title(\Psi(x)*\Psi(y));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 重构源图像及结果显示
l_re = l_zeros(end:-1:1); % 重构低通滤波
l_r = circshift(l_re, [0, 1]);
h_re=h_zeros(end:-1:1); % 重构高通滤波
h_r=circshift(h_re, [0, 1]);
top_pic=[lt_pic rt_pic]; % 图像上半部分
t=0;
for i=1:T;
if (mod(i,2)==0)
topll(i,:)=top_pic(t,:);
else t=t+1;
topll(i,:)=zeros(1,T);
end
end;
for i=1:T; % 列变换
topcl_re(:,i)=ifft(fft(l_r).*fft(topll(:,i)));
end;
bottom_pic=[lb_pic rb_pic];
t=0;
for i=1:T;
if (mod(i,2)==0)
bottomlh(i,:)=bottom_pic(t,:);
else t=t+1;
bottomlh(i,:)=zeros(1,T);
end
end;
for i=1:T; % 列变换
bottomch_re(:,i)=ifft(fft(h_r).*fft(bottomlh(:,i)));
end;
construct1 = bottom