📄 mhaar.m
字号:
function X = mhaar(X, Level, Dim)
%MHAAR Morphological Haar wavelet transform.
% Y = MHAAR(X,L) computes the L level decomposition of a signal X
% using the morphological Haar wavelet [1]. If the input is
% integer-valued, the transform coefficients are also integer-
% valued. The signal length must be divisible by 2^L. If X is a
% matrix, the transform is applied to each column.
%
% MHAAR(X,-L) is the inverse transform, reversing L levels.
%
% MHAAR(X,L,DIM) applies the transform across the dimension DIM.
%
% Example:
% Y = mhaar(X,3); % Perform 3 levels of decomposition on X
% R = mhaar(Y,-3); % Recover X from Y
%
% Reference:
% [1] Heijmans and Goutsias. ``Nonlinear Multiresolution Signal
% Decomposition Schemes--Part II: Morphological Wavelets.'' IEEE
% Transactions on Image Processing, Vol. 9, No. 11, Nov. 2000.
%
% See also SEQHAAR.
% Pascal Getreuer 2005
if nargin < 2, error('Not enough input arguments.'); end
if nargin < 3, Dim = min(find(size(X) ~= 1)); end
XSize = size(X);
N = XSize(Dim);
Perm = [Dim:max(length(XSize),Dim) 1:Dim-1];
X = reshape(permute(X,Perm),N,prod(XSize)/N);
if rem(N,pow2(abs(Level))), error('Invalid input size.'); end
if Level > 0
for k = 1:Level
N = size(X,1)*pow2(1-k);
X(1:N,:) = [min(X(1:2:N,:),X(2:2:N,:));X(1:2:N,:) - X(2:2:N,:)];
end
elseif Level < 0
for k = Level:-1
N = size(X,1)*pow2(k+1);
X([1:2:N,2:2:N],:) = [X(1:N/2,:) + max(X(N/2+1:N,:),0);
X(1:N/2,:) - min(X(N/2+1:N,:),0)];
end
end
X = ipermute(reshape(X,XSize(Perm)),Perm);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -