2级小波LeGall 5/3 2D变换系数的范围

时间:2016-07-14 21:26:58

标签: matlab math wavelet wavelet-transform

如标题所示,如果输入矩阵的值是,则我对Wavelet LeGall 5/3(必须精确地为此滤波器)2D变换(仅适用于8 * 8块)的系数范围感到困惑。在0-255之间。

对于公式,链接位于:Wavelet LeGall 5/3

以下是我现在所做的事情:

  1. 所有值减去128(更容易计算低频值,见后文);

  2. 沿水平方向进行变换。这将在所有行中生成所有系数:前4个是低频,后4个是高频。很容易发现高频范围是-255到+255(输入范围的两倍)。低频范围实际上是-192到+192(1.5 *输入范围)。

  3. 垂直方向转换。这将在垂直方向上执行相同的操作。并且产生了四个块:LL(低低),LH(低高),HL,HH。很容易计算出HH最大的范围:-511到+511,LL的范围是1.5 * 1.5 =输入范围的2.25倍(-128到+127)。

  4. 然后,问题就出现了。如果我再次为LL块做这个小波怎么办?从理论上讲,LL块的HH(第二级系数)的范围应该是LL范围的4倍,它是输入范围的10倍(-128到+127),即-1280到+1270。

    但是,我多次尝试随机计算,最大值永远不会超过-511到+511(参见最后的代码)。我想这是因为无法达到理论值,因为所有计算都是基于前一个计算。但这个似乎很容易的问题对我来说很难在理论上证明。有人可以帮我出去吗?

    我使用过的代码(将两个文件放在一个目录中并随时运行测试文件,但最大值不超过512 ......):

    1. waveletlegall53的功能:

      function X = waveletlegall53(X, Level)
      %WAVELETLEGALL53  Le Gall 5/3 (Spline 2.2) wavelet transform.
      %   Y = WAVELETLEGALL53(X, L) decomposes X with L stages of the
      %   Le Gall 5/3 wavelet.  For the inverse transform, 
      %   WAVELETLEGALL53(X, -L) inverts L stages.  Filter boundary
      %   handling is half-sample symmetric.
      %
      %   X may be of any size; it need not have size divisible by 2^L.
      %   For example, if X has length 9, one stage of decomposition
      %   produces a lowpass subband of length 5 and a highpass subband
      %   of length 4.  Transforms of any length have perfect
      %   reconstruction (exact inversion).
      %
      %   If X is a matrix, WAVELETLEGALL53 performs a (tensor) 2D
      %   wavelet transform.  If X has three dimensions, the 2D
      %   transform is applied along the first two dimensions.
      %
      %   Example:
      %   Y = waveletlegall53(X, 5);    % Transform image X using 5 stages
      %   R = waveletlegall53(Y, -5);   % Reconstruct from Y
      
      
      X = double(X);
      if nargin < 2, error('Not enough input arguments.'); end
      if ndims(X) > 3, error('Input must be a 2D or 3D array.'); end
      if any(size(Level) ~= 1), error('Invalid transform level.'); end
      
      N1 = size(X,1);
      N2 = size(X,2);
      
      % Lifting scheme filter coefficients for Le Gall 5/3
      LiftFilter = [-1/2,1/4];
      ScaleFactor =1; sqrt(2);
      
      LiftFilter = LiftFilter([1,1],:);
      
      if Level >= 0   % Forward transform
          for k = 1:Level
          M1 = ceil(N1/2);
          M2 = ceil(N2/2);
      
      %%% Transform along columns %%%
      if N1 > 1         
       RightShift = [2:M1,M1];
       X0 = X(1:2:N1,1:N2,:);
      
       % Apply lifting stages
       if rem(N1,2)
          X1 = [X(2:2:N1,1:N2,:);X0(M1,:,:)]...
             +floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
             X0(1,:,:)*LiftFilter(1,1),1));
       else
          X1 = X(2:2:N1,1:N2,:) ...
             +floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
             X0(1,:,:)*LiftFilter(1,1),1));
       end
      
       X0 = X0 + floor(filter(LiftFilter(:,2),1,...
          X1,X1(1,:,:)*LiftFilter(1,2),1)+0.5);
      
       if rem(N1,2)
          X1(M1,:,:) = [];
       end
      
       X(1:N1,1:N2,:) = [X0*ScaleFactor;X1/ScaleFactor];
      
      end
      
      %%% Transform along rows %%%
      if N2 > 1
       RightShift = [2:M2,M2];
       X0 = permute(X(1:N1,1:2:N2,:),[2,1,3]);
      
       % Apply lifting stages
       if rem(N2,2)
          X1 = permute([X(1:N1,2:2:N2,:),X(1:N1,N2,:)],[2,1,3])...
             + floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
             X0(1,:,:)*LiftFilter(1,1),1));
       else
          X1 = permute(X(1:N1,2:2:N2,:),[2,1,3]) ...
             + floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
             X0(1,:,:)*LiftFilter(1,1),1));
       end
      
       X0 = X0 +floor( filter(LiftFilter(:,2),1,...
          X1,X1(1,:,:)*LiftFilter(1,2),1)+0.5);
      
       if rem(N2,2)
          X1(M2,:,:) = [];
       end
      
       X(1:N1,1:N2,:) = permute([X0*ScaleFactor;X1/ScaleFactor],[2,1,3]);
       end
      
       N1 = M1;
      N2 = M2;
      end
      else           % Inverse transform
      for k = 1+Level:0
      M1 = ceil(N1*pow2(k));
      M2 = ceil(N2*pow2(k));
      
      %%% Inverse transform along rows %%%
      if M2 > 1
       Q = ceil(M2/2);
       RightShift = [2:Q,Q];
       X1 = permute(X(1:M1,Q+1:M2,:)*ScaleFactor,[2,1,3]);
      
       if rem(M2,2)
          X1(Q,1,1) = 0;
       end
      
       % Undo lifting stages
       X0 = permute(X(1:M1,1:Q,:)/ScaleFactor,[2,1,3]) ...
          - floor(filter(LiftFilter(:,2),1,X1,X1(1,:,:)*LiftFilter(1,2),1)+0.5);
       X1 = X1 - floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
          X0(1,:,:)*LiftFilter(1,1),1));
      
       if rem(M2,2)
          X1(Q,:,:) = [];
       end
      
       X(1:M1,[1:2:M2,2:2:M2],:) = permute([X0;X1],[2,1,3]);
      end
      
      %%% Inverse transform along columns %%%
      if M1 > 1
       Q = ceil(M1/2);
       RightShift = [2:Q,Q];
       X1 = X(Q+1:M1,1:M2,:)*ScaleFactor;
      
       if rem(M1,2)
          X1(Q,1,1) = 0;
       end
      
       % Undo lifting stages
       X0 = X(1:Q,1:M2,:)/ScaleFactor ...
          - floor(filter(LiftFilter(:,2),1,X1,X1(1,:,:)*LiftFilter(1,2),1)+0.5);
       X1 = X1 - floor(filter(LiftFilter(:,1),1,X0(RightShift,:,:),...
          X0(1,:,:)*LiftFilter(1,1),1));
      
       if rem(M1,2)
          X1(Q,:,:) = [];
       end
      
       X([1:2:M1,2:2:M1],1:M2,:) = [X0;X1];
      end
      end
      end
      
    2. 测试.m文件:

      clear all
      close all
      clc
      
      n=100000;
      maxt=zeros(1,n);
      maxt2=zeros(1,n);
      for it=1:n
          X=floor(rand(8,8)*256);
          X = X-128;
          a = waveletlegall53(X,2);
          maxt(it)=max(max(abs(a)));
          if max(max(abs(a))) > 470
              max(max(abs(a)))
           end
      
      end
      [fr ind]=hist(maxt,length(unique(maxt)));
      pr = length(find(maxt>512))/n
      fr=fr/n;
      
      figure()
      plot(ind, fr)
      grid on
      
      Maxvalue = max(maxt)
      

0 个答案:

没有答案