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

波变换

开发平台:

Matlab

  1. function wpplotcf(t,colorMode,axe,nb_colors)
  2. %WPPLOTCF Plot wavelet packets colored coefficients.
  3. %
  4. %   WPPLOTCF(T) OR
  5. %   WPPLOTCF(T,COLORMODE) OR
  6. %   WPPLOTCF(T,COLORMODE,AXE) OR
  7. %   WPPLOTCF(T,COLORMODE,AXE,NB_COLORS)
  8. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  9. %   Last Revision: 22-May-2003.
  10. %   Copyright 1995-2004 The MathWorks, Inc.
  11. %   $Revision: 1.5.4.2 $  $Date: 2004/03/15 22:39:21 $
  12. % Tag for image of Coefficients.
  13. %--------------------------------
  14. tag_img_cfs = 'Img_WPCfs';
  15. DefNBColor = 128;
  16. if nargin<2
  17.     colorMode = 1; axe = gca; nb_colors = DefNBColor;
  18. elseif nargin<3
  19.     axe = gca; nb_colors = DefNBColor;
  20. elseif nargin<4
  21.     nb_colors = DefNBColor;
  22. end
  23. order = treeord(t);
  24. dmax  = treedpth(t);
  25. nodes = leaves(t);
  26. sizes = fmdtree('tn_read',t,'sizes');
  27. nbtn  = length(nodes);
  28. [depths,posis] = ind2depo(order,nodes);
  29. cfs   = read(t,'data');
  30. switch order
  31.     case 2 , flg_line = 6;
  32.     case 4 , flg_line = 5;
  33. end
  34. if     dmax==flg_line   , lwidth = 0.5;
  35. elseif dmax==flg_line-1 , lwidth = 1;
  36. else                    , lwidth = 2;
  37. end
  38. switch order
  39.     case 2
  40.         switch colorMode
  41.             case {1,2,3,4} , ord = wpfrqord(nodes);
  42.             case {5,6,7,8} , ord = [1:length(nodes)];
  43.         end
  44.         switch colorMode
  45.             case {1,2,5,6} , abs_val = 1;
  46.             case {3,4,7,8} , abs_val = 0;
  47.         end
  48.         switch colorMode
  49.             case {1,3,5,7} , cfs = wcodemat(cfs,nb_colors,'row',abs_val);
  50.         end
  51.         sizes = max(sizes,[],2);
  52.         deb = [1];
  53.         fin = [];       
  54.         for k = 1:nbtn
  55.             fin(k)   = deb(k)+sizes(k)-1;
  56.             deb(k+1) = fin(k)+1;
  57.         end
  58.         nbrows = (2.^(dmax-depths));
  59.         NBrowtot = sum(nbrows);
  60.         NBcoltot = max(read(t,'sizes',0));
  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.         size0 = read(t,'sizes',0);
  133.         tmp   = size0(ones(dmax+1,1),:);
  134.         for k = 2:dmax+1
  135.             tmp(k,:) = floor((tmp(k-1,:)+1)/2);
  136.         end
  137.         newsiz = tmp(depths+1,:);
  138.         deb = [1];
  139.         fin = [];
  140.         for k = 1:nbtn
  141.             fin(k) = deb(k)+prod(sizes(k,:))-1;
  142.             deb(k+1) = fin(k)+1;
  143.         end
  144.         large = (Xbase./(2.^depths))';
  145.         xpos  = zeros(1,nbtn);
  146.         ypos  = zeros(1,nbtn);
  147.         tab   = zeros(nbtn,dmax+1);
  148.         tab(:,1) = nodes;
  149.         for j = 1:dmax
  150.             tab(:,j+1) = floor((tab(:,j)-1)/order);
  151.         end
  152.         pos  = rem(tab,order)';
  153.         vdiv = 1./(2.^[1:dmax]);
  154.         for k = 1:nbtn
  155.             d = depths(k);
  156.             dx = 0; dy = 0;
  157.             for j = 1:d
  158.                 l = d-j+1;
  159.                 if pos(l,k)==1
  160.                         dy = dy + vdiv(j);
  161.                 elseif pos(l,k)==2
  162.                         dx = dx + vdiv(j);
  163.                         dy = dy + vdiv(j);
  164.                 elseif pos(l,k)==3;
  165.                 elseif pos(l,k)==0
  166.                         dx = dx + vdiv(j);
  167.                 end
  168.             end
  169.             xpos(k) = Xbase*dx;
  170.             ypos(k) = Ybase*dy;
  171.         end
  172.         wimg = newsiz(:,2)';
  173.         himg = newsiz(:,1)';
  174.         xmin = xpos+(0.5*large)./wimg;
  175.         if sizes(:,2)>1
  176.             xmax = xpos+((wimg-0.5).*large)./wimg;
  177.         else
  178.             xmax = xpos+large;
  179.         end
  180.         ymin = ypos+(0.5*hight)./himg;
  181.         if sizes(:,1)>1
  182.             ymax = ypos+((himg-0.5).*hight)./himg;
  183.         else
  184.             ymax = ypos+hight;
  185.         end
  186.         NBdraw = 1;
  187.         if nbtn==1 , flg_code = 0; else flg_code = 1; end
  188.         for k = 1:nbtn
  189.             tmp    = zeros(sizes(k,:));
  190.             tmp(:) = cfs(deb(k):fin(k));
  191.             img = image([xmin(k) xmax(k)],[ymin(k) ymax(k)], ...
  192.                     flipud(wimgcode('cod',flg_code,tmp,nb_colors,codemat_v,[depths(k) size0])),...
  193.                     'Tag',tag_img_cfs,...
  194.                     'Userdata',[depths(k) posis(k) xpos(k) xmax(k) ypos(k) ymax(k)],...
  195.                     'Parent',axe);
  196.             xx1 = xpos(k);
  197.             xx2 = xx1+hight(k);
  198.             yy1 = ypos(k);
  199.             yy2 = yy1+hight(k);
  200.             if dmax<=flg_line
  201.                     lin = line(...
  202.                             'Parent',axe,                   ...
  203.                             'Xdata',[xx1 xx2 xx2 xx1 xx1],  ...
  204.                             'Ydata',[yy1 yy1 yy2 yy2 yy1],  ...
  205.                             'Linewidth',lwidth              ...
  206.                             );
  207.             end
  208.             if NBdraw==4
  209.                 % drawnow;
  210.                 NBdraw = 1;
  211.             else
  212.                 NBdraw = NBdraw+1;
  213.             end
  214.         end
  215.         line(...
  216.              'Parent',axe,        ...
  217.              'Xdata',[0 1 1 0 0], ...
  218.              'Ydata',[0 0 1 1 0], ...
  219.              'Linewidth',2        ...
  220.              );
  221.         set(axe,'Tag',tag_axe);
  222.         drawnow
  223. end