contourlet2tree.m
上传用户:l56789
上传日期:2022-02-25
资源大小:2422k
文件大小:2k
源码类别:

图形图像处理

开发平台:

Matlab

  1. % contourlet2tree.m
  2. % written by: Duncan Po
  3. % Date: August 24, 2002
  4. % convert the contourlet coefficients from subband structure to tree structure
  5. % Usage: [tree, scaling] = contourlet2tree(coef, dir)
  6. % Inputs:   coef        - contourlet coefficients
  7. %           dir         - the directional coefficients to be processed
  8. % Output:   tree        - the resulting tree structure
  9. %           scaling     - the scaling function of the coefficients
  10. function [tree, scaling] = contourlet2tree(coef, dir) 
  11. M = length(coef{2});
  12. nlevel = length(coef)-1;
  13. for l = 2:nlevel+1
  14.     levndir(l-1) = log2(length(coef{l}));
  15. end;
  16. scaling = coef{1};
  17. for r = 1:(length(levndir)-1)
  18.     if levndir(r+1)==levndir(r)
  19.         split(r) = 0;
  20.     elseif levndir(r+1)-levndir(r)==1
  21.         split(r) = 1;
  22.     else
  23.         return;
  24.     end;
  25. end;
  26.     
  27. for l=2:nlevel+1 
  28.     if dir> M/2  
  29.       for i=1+2^(levndir(l-1)-levndir(1))*(dir-1):2^(levndir(l-1)-levndir(1))*dir
  30.           coef{l}{i} = coef{l}{i}.';
  31.       end;
  32.     end;
  33. end;
  34.     
  35. for l=2:nlevel+1 
  36.     if (l>2) & (levndir(l-1)~=levndir(1))
  37.         j=1;
  38.         if split(l-2)==1
  39.             for i=1+2^(levndir(l-1)-levndir(1))*(dir-1):2:2^(levndir(l-1)-levndir(1))*dir
  40.                 coef{l}{j} = type3transform(coef{l}{i},coef{l}{i+1}); 
  41.                 j = j + 1;
  42.             end;
  43.         else
  44.             for i=1+2^(levndir(l-1)-levndir(1))*(dir-1):2:2^(levndir(l-1)-levndir(1))*dir
  45.                 coef{l}{j} = type4transform(coef{l}{i},coef{l}{i+1});
  46.                 j = j + 1;
  47.             end;
  48.         end;
  49.         
  50.         i=length(coef{l})/length(coef{2})/2;
  51.         while i>1
  52.             j=1;
  53.             for k=1:2:i
  54.                 coef{l}{j} = type4transform(coef{l}{k}, coef{l}{k+1});
  55.                 j = j+1;
  56.             end;
  57.             i = i/2;
  58.         end;
  59.         interimstructure{l-1} = coef{l}{1};        
  60.     else;
  61.         interimstructure{l-1} = coef{l}{dir};
  62.     end;
  63. end;
  64. tree{1} = interimstructure{1}(:);
  65. for l = 2:nlevel
  66.     tree{l} = [];
  67.     for col = 1:2:size(interimstructure{l}, 2)
  68.         temp = interimstructure{l}(:,col:col+1);
  69.         temp = temp.';
  70.         tree{l} = [tree{l}; temp(:)];
  71.     end;
  72. end;