wpplotcf.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:8k
源码类别:

波变换

开发平台:

Matlab

  1. function wpplotcf(Ts,Ds,colorMode,axe,nb_colors)
  2. %WPPLOTCF Plot wavelet packets colored coefficients.
  3. %
  4. %   WPPLOTCF(TREE,DATA) OR
  5. %   WPPLOTCF(TREE,DATA,COLORMODE) OR
  6. %   WPPLOTCF(TREE,DATA,COLORMODE,AXE) OR
  7. %   WPPLOTCF(TREE,DATA,COLORMODE,AXE,NB_COLORS)
  8. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  9. %   Last Revision: 07-May-2003.
  10. %   Copyright 1995-2004 The MathWorks, Inc.
  11. % $Revision: 1.15.4.2 $
  12. % Tag for image of Coefficients.
  13. %--------------------------------
  14. tag_img_cfs = 'Img_WPCfs';
  15. DefNBColor = 128;
  16. if     nargin<3
  17.        colorMode = 1; axe = gca; nb_colors = DefNBColor;
  18. elseif nargin<4
  19.        axe = gca; nb_colors = DefNBColor;
  20. elseif nargin<5
  21.        nb_colors = DefNBColor;
  22. end
  23. tab            = wtreemgr('table',Ts,0)';
  24. nodes          = tab(1,:)';
  25. sizes          = wdatamgr('rsizes',Ds);
  26. nbtn           = size(tab,2);
  27. order          = wtreemgr('order',Ts);
  28. [depths,posis] = ind2depo(order,nodes);
  29. dmax           = size(tab,1)-1;
  30. cfs            = wdatamgr('rallcfs',Ds);
  31. switch order
  32.     case 2 , flg_line = 6;
  33.     case 4 , flg_line = 5;
  34. end
  35. if      dmax==flg_line   , lwidth = 0.5;
  36. elseif  dmax==flg_line-1 , lwidth = 1;
  37. else                     , lwidth = 2;
  38. end
  39. switch order
  40.     case 2
  41.         switch colorMode
  42.             case {1,2,3,4} , ord = wpfrqord(nodes);
  43.             case {5,6,7,8} , ord = [1:length(nodes)];
  44.         end
  45.         switch colorMode
  46.             case {1,2,5,6} , abs_val = 1;
  47.             case {3,4,7,8} , abs_val = 0;
  48.         end
  49.         switch colorMode
  50.             case {1,3,5,7} , cfs = wcodemat(cfs,nb_colors,'row',abs_val);
  51.         end
  52.         deb = [1];
  53.         fin = [];       
  54.         for k = 1:nbtn
  55.             fin(k) = deb(k)+sizes(1+depths(k))-1;
  56.             deb(k+1) = fin(k)+1;
  57.         end
  58.         nbrows = (2.^(dmax-depths));
  59.         NBrowtot = sum(nbrows);
  60.         NBcoltot = sizes(1);
  61.         matcfs  = zeros(NBrowtot,NBcoltot);
  62.         ypos    = zeros(nbtn,1);
  63.         if nbtn>1
  64.             for k = 1:nbtn
  65.                 ypos(ord(k)) = sum(nbrows(ord([1:k-1])));
  66.             end
  67.         end     
  68.         ypos = NBrowtot+1-ypos-nbrows;
  69.         ymin = (ypos-1)/NBrowtot;
  70.         ymax = (ypos-1+nbrows)/NBrowtot;
  71.         ylim = [0 1];
  72.         alfa = 1/(2*NBrowtot);
  73.         ydata = [(1-alfa)*ylim(1)+alfa*ylim(2) (1-alfa)*ylim(2)+alfa*ylim(1)];
  74.         if NBrowtot==1
  75.             ydata(1) = 1/2; ydata(2) = 1;
  76.         end
  77.         axes(axe);
  78.         tag_axe = get(axe,'Tag');
  79.         xlim = get(axe,'Xlim');
  80.         set(axe,'Xlim',xlim,'Ylim',ylim,'Nextplot','replace');
  81.         imgcfs = image(...
  82.                         'Parent',axe,                           ...
  83.                         'Xdata',[1:NBcoltot],                   ...
  84.                         'Ydata',ydata,                          ...
  85.                         'Cdata',matcfs,                         ...
  86.                         'Tag',tag_img_cfs,                      ...
  87.                         'Userdata',[depths posis ymin ymax]     ...
  88.                         );
  89.         NBdraw  = 0;
  90.         for k = 1:nbtn
  91.             d = depths(k);
  92.             z = cfs(deb(k):fin(k));
  93.             z = z(ones(1,2^d),:);
  94.             z = wkeep1(z(:)',NBcoltot);
  95.             if find(colorMode==[2 4 6 8])      
  96.                 z = wcodemat(z,nb_colors,'row',abs_val);
  97.             end
  98.             r1 = ypos(k);
  99.             r2 = ypos(k)+nbrows(k)-1;
  100.             matcfs(r1:r2,:) = z(ones(1,nbrows(k)),:);
  101.             if dmax<=flg_line & nbtn~=1
  102.                 line(...
  103.                         'Parent',axe,                   ...
  104.                         'Xdata',[0.5 NBcoltot+0.5],     ...
  105.                         'Ydata',[ymin(k) ymin(k)],      ...
  106.                         'Linewidth',lwidth              ...
  107.                         );
  108.             end
  109.             NBdraw = NBdraw+1;
  110.             if NBdraw==10 | k==nbtn
  111.                 set(imgcfs,'Xdata',[1:NBcoltot], ...
  112.                         'Ydata',ydata,'Cdata',matcfs);
  113.                 NBdraw = 0;
  114.             end
  115.         end
  116.         set(axe,'Ydir','reverse',...
  117.                 'layer','top',                  ...
  118.                 'Xlim',xlim,'Ylim',ylim,        ...
  119.                 'Ytick',[],'YtickLabel',[],     ...
  120.                 'Box','on','Tag',tag_axe);
  121.     case 4
  122.         % Image Coding Value.
  123.         %-------------------
  124.         codemat_v = wimgcode('get',get(axe,'Parent'));
  125.         Xbase = 1; Ybase = 1;
  126.         hight = (Ybase./(2.^depths))';
  127.         axes(axe);
  128.         tag_axe = get(axe,'Tag');
  129.         set(axe,'Xlim',[0 Xbase],'Ylim',[0 Ybase],'Nextplot','add');
  130.         % Trunc images.
  131.         %--------------
  132.         newsiz  = sizes;
  133.         s0      = newsiz(:,1);
  134.         for k=2:size(newsiz,2)
  135.             sx = s0;
  136.             for p = 1:k , sx = floor((sx+1)/2); end
  137.             newsiz(:,k) = sx;
  138.         end
  139.         newsiz = newsiz(:,depths+1);
  140.         size0 = sizes(:,1)';
  141.         sizes = sizes(:,depths+1);
  142.         deb = [1];
  143.         fin = [];
  144.         for k = 1:nbtn
  145.             fin(k)   = deb(k)+prod(sizes(:,k))-1;
  146.             deb(k+1) = fin(k)+1;
  147.         end
  148.         large   = (Xbase./(2.^depths))';
  149.         xpos    = zeros(1,nbtn);
  150.         ypos    = zeros(1,nbtn);
  151.         pos     = rem(tab,order);
  152.         vdiv    = 1./(2.^[1:dmax]);
  153.         for k = 1:nbtn
  154.             d = depths(k);
  155.             dx = 0; dy = 0;
  156.             for j = 1:d
  157.                 l = d-j+1;
  158.                 if pos(l,k)==1
  159.                     dy = dy + vdiv(j);
  160.                 elseif pos(l,k)==2
  161.                     dx = dx + vdiv(j);
  162.                     dy = dy + vdiv(j);
  163.                 elseif pos(l,k)==3
  164.                 elseif pos(l,k)==0
  165.                     dx = dx + vdiv(j);
  166.                 end
  167.         end
  168.             xpos(k) = Xbase*dx;
  169.             ypos(k) = Ybase*dy;
  170.         end
  171.         
  172.         % newsiz = sizes;
  173.         xmin = xpos+(0.5*large)./(newsiz(2,:));
  174.         if sizes(2,:)>1
  175.             xmax = xpos+((newsiz(2,:)-0.5).*large)./newsiz(2,:);
  176.         else
  177.             xmax = xpos+large;
  178.         end
  179.         ymin = ypos+(0.5*hight)./newsiz(1,:);
  180.         if sizes(1,:)>1
  181.             ymax = ypos+((newsiz(1,:)-0.5).*hight)./newsiz(1,:);
  182.         else
  183.             ymax = ypos+hight;
  184.         end
  185.         NBdraw = 1;
  186.         if nbtn==1 , flg_code = 0; else flg_code = 1; end
  187.         for k = 1:nbtn
  188.             tmp    = zeros(sizes(:,k)');
  189.             tmp(:) = cfs(deb(k):fin(k));
  190.             img = image([xmin(k) xmax(k)],[ymin(k) ymax(k)], ...
  191.                     flipud(wimgcode('cod',flg_code,tmp,nb_colors,codemat_v,[depths(k) size0])),...
  192.                     'Tag',tag_img_cfs,...
  193.                     'Userdata',[depths(k) posis(k) xpos(k) xmax(k) ypos(k) ymax(k)],...
  194.                     'Parent',axe);
  195.             xx1 = xpos(k);
  196.             xx2 = xx1+hight(k);
  197.             yy1 = ypos(k);
  198.             yy2 = yy1+hight(k);
  199.             if dmax<=flg_line
  200.                 lin = line(...
  201.                         'Parent',axe,                   ...
  202.                         'Xdata',[xx1 xx2 xx2 xx1 xx1],  ...
  203.                         'Ydata',[yy1 yy1 yy2 yy2 yy1],  ...
  204.                         'Linewidth',lwidth              ...
  205.                         );
  206.             end
  207.             if NBdraw==4 , NBdraw = 1; else , NBdraw = NBdraw+1; end
  208.         end
  209.         lin = line(...
  210.                     'Parent',axe,       ...
  211.                     'Xdata',[0 1 1 0 0],...
  212.                     'Ydata',[0 0 1 1 0],...
  213.                     'Linewidth',2       ...
  214.                     );
  215.         set(axe,'Tag',tag_axe);
  216.         drawnow
  217. end