maxlift.m

来自「matlab程序」· M 代码 · 共 58 行

M
58
字号
function X = maxlift(X, Level, Dim)
%MAXLIFT  Max-lifting morphological wavelet transform.
%   Y = MAXLIFT(X,L) computes the L level decomposition of a signal
%   X using the max-lifting morphological wavelet [1].  This transform
%   has the property that local maxima are well preserved at lower
%   resolutions.  Also, if the input is integer-valued, the transform
%   coefficients are integer-valued.  The signal length must be divisible
%   by 2^L.  If X is a matrix, the transform is applied to each column.
%
%   MAXLIFT(X,-L) is the inverse transform, reversing L levels.
%
%   MAXLIFT(X,L,DIM) applies the transform across the dimension DIM.
%
%   Example:
%   Y = maxlift(X,3);   % Perform 3 levels of decomposition on X
%   R = maxlift(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 MAXLIFT2.

% 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(size(X,1),pow2(abs(Level))), error('Invalid input size.'); end

if Level > 0
   for k = 1:Level
      N = size(X,1)*pow2(1-k);
      Xe = X(1:2:N,:);
      Xo = X(2:2:N,:);
      Xo = Xo - max(Xe,[Xe(2:N/2,:);Xe(N/2,:)]);
      Xe = Xe + max(0,max([Xo(1,:);Xo(1:N/2-1,:)],Xo));
      X(1:N,:) = [Xe;Xo];
   end
elseif Level < 0
   for k = Level:-1
      N = size(X,1)*pow2(k+1);
      Xe = X(1:N/2,:);
      Xo = X(N/2+1:N,:);
      Xe = Xe - max(0,max([Xo(1,:);Xo(1:N/2-1,:)],Xo));
      Xo = Xo + max(Xe,[Xe(2:N/2,:);Xe(N/2,:)]);
      X([1:2:N,2:2:N],:) = [Xe;Xo];
   end
end

X = ipermute(reshape(X,XSize(Perm)),Perm);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?