【求助】求matlab小波变换图像处理实现程序~ 50
我邮箱是58085410@qq.com
和7224029@163.com~ 展开
%这个是2D-DWT的函数,是haar小波
%c是图像像素矩阵 steps是变换的阶数
function dwtc = dwt_haar(c, steps)
% DWTC = CWT_HARR(C) - Discrete Wavelet Transform using Haar filter
%
% M D Plumbley Nov 2003
N = length(c)-1; % Max index for filter: 0 .. N
% If no steps to do, or the sequence is a single sample, the DWT is itself
if (0==N | steps == 0)
dwtc = c;
return
end
% Check that N+1 is divisible by 2
if (mod(N+1,2)~=0)
disp(['Not divisible 2: ' num2str(N+1)]);
return
end
% Set the Haar analysis filter
h0 = [1/2 1/2]; % Haar Low-pass filter
h1 = [-1/2 1/2]; % Haar High-pass filter
% Filter the signal
lowpass_c = conv(h0, c);
hipass_c = conv(h1, c);
% Subsample by factor of 2 and scale
c1 = sqrt(2)*lowpass_c(2:2:end);
d1 = sqrt(2)*hipass_c(2:2:end);
% Recursively call dwt_haar on the low-pass part, with 1 fewer steps
dwtc1 = dwt_haar(c1, steps-1);
% Construct the DWT from c1 and d1
dwtc = [dwtc1 d1];
% Done
return
-------------------------- 分割线 --------------------------
调用这个函数的例子 下面的东西放在另一个文档里
读入一个图像 ‘lena’ 应该是个最基础的图像了~
之后分别作0阶 和 1阶 2D-DWT 的变换
改变阶数 可以做更高阶的
clear all
im = imreadreal('lena.bmp'); %read image data
% Plot
figure
dwt2_step0=dwt2_haar(im, 0); %2D DWT step=0
imagesc(dwt2_step0);
colormap gray;
axis image;
figure
dwt2_step1=dwt2_haar(im, 1); %2D DWT step=1
imagesc(dwt2_step1);
colormap gray;
axis image;
--------------------- 分割线 ---------------------
结果如下 1阶的结果
这是我的一个实验 希望有所帮助
2023-08-15 广告