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

波变换

开发平台:

Matlab

  1. function wp2dutil(option,win_wptool,in3,in4)
  2. %WP2DUTIL Wavelet packets 2-D utilities.
  3. %   WP2DUTIL(OPTION,WIN_WPTOOL,IN3,IN4)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 08-Jan-2001.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.13 $ $Date: 2002/06/17 12:18:55 $
  8. % Default values.
  9. %----------------
  10. max_lev_anal = 5;
  11. % Memory Blocks of stored values.
  12. %================================
  13. % MB1 (main window).
  14. %-------------------
  15. n_param_anal   = 'WP2D_Par_Anal';
  16. ind_img_name   = 1;
  17. ind_wav_name   = 2;
  18. ind_lev_anal   = 3;
  19. ind_ent_anal   = 4;
  20. ind_ent_par    = 5;
  21. ind_img_size   = 6;
  22. ind_img_t_name = 7;
  23. ind_act_option = 8;
  24. ind_thr_val    = 9;
  25. nb1_stored     = 9;
  26. % MB2 (main window).
  27. %-------------------
  28. n_wp_utils = 'WP_Utils';
  29. ind_tree_lin  = 1;
  30. ind_tree_txt  = 2;
  31. ind_type_txt  = 3;
  32. ind_sel_nodes = 4;
  33. ind_gra_area  = 5;
  34. ind_nb_colors = 6;
  35. nb2_stored    = 6;
  36. % Tag property of objects.
  37. %-------------------------
  38. tag_m_savesyn = 'Save_Syn';
  39. tag_m_savedec = 'Save_Dec';
  40. tag_pus_anal  = 'Pus_Anal';
  41. tag_pus_deno  = 'Pus_Deno';
  42. tag_pus_comp  = 'Pus_Comp';
  43. tag_pus_btree = 'Pus_Btree';
  44. tag_pus_blev  = 'Pus_Blev';
  45. tag_inittree  = 'Pus_InitTree';
  46. tag_wavtree   = 'Pus_WavTree';
  47. tag_curtree   = 'Pop_CurTree';
  48. tag_nodlab    = 'Pop_NodLab';
  49. tag_nodact    = 'Pop_NodAct';
  50. tag_nodsel    = 'Pus_NodSel';
  51. tag_pus_full  = ['Pus_Full.1';'Pus_Full.2';'Pus_Full.3';'Pus_Full.4'];
  52. tag_axe_t_lin = 'Axe_TreeLines';
  53. tag_axe_sig   = 'Axe_Sig';
  54. tag_axe_pack  = 'Axe_Pack';
  55. tag_axe_cfs   = 'Axe_Cfs';
  56. tag_axe_col   = 'Axe_Col';
  57. tag_sli_size  = 'Sli_Size';
  58. tag_sli_pos   = 'Sli_Pos';
  59. % Miscellaneous values.
  60. %----------------------
  61. Col_SigIni   = 'r';
  62. children     = get(win_wptool,'Children');
  63. axe_handles  = findobj(children,'flat','type','axes');
  64. uic_handles  = findobj(children,'flat','type','uicontrol');
  65. pop_handles  = findobj(uic_handles,'style','popupmenu');
  66. pus_handles  = findobj(uic_handles,'style','pushbutton');
  67. sli_handles  = findobj(uic_handles,'style','slider');
  68. txt_handles  = findobj(uic_handles,'Style','text');
  69. m_files      = wfigmngr('getmenus',win_wptool,'file');
  70. m_savesyn    = findobj(m_files,'Tag',tag_m_savesyn);
  71. m_savedec    = findobj(m_files,'Tag',tag_m_savedec);
  72. pus_anal     = findobj(pus_handles,'Tag',tag_pus_anal);
  73. pus_deno     = findobj(pus_handles,'Tag',tag_pus_deno);
  74. pus_comp     = findobj(pus_handles,'Tag',tag_pus_comp);
  75. pus_inittree = findobj(pus_handles,'Tag',tag_inittree);
  76. pus_wavtree  = findobj(pus_handles,'Tag',tag_wavtree);
  77. pus_btree    = findobj(pus_handles,'Tag',tag_pus_btree);
  78. pus_blev     = findobj(pus_handles,'Tag',tag_pus_blev);
  79. pop_curtree  = findobj(pop_handles,'Tag',tag_curtree);
  80. pop_nodlab   = findobj(pop_handles,'Tag',tag_nodlab);
  81. pop_nodact   = findobj(pop_handles,'Tag',tag_nodact);
  82. for k =1:size(tag_pus_full,1)
  83.     pus_full(k) = (findobj(pus_handles,'Tag',tag_pus_full(k,:)))';
  84. end
  85. pus_nodsel   = findobj(pus_handles,'Tag',tag_nodsel);
  86. WP_Axe_Tree  = findobj(axe_handles,'flat','Tag',tag_axe_t_lin);
  87. WP_Axe_Sig   = findobj(axe_handles,'flat','Tag',tag_axe_sig);
  88. WP_Axe_Pack  = findobj(axe_handles,'flat','Tag',tag_axe_pack);
  89. WP_Axe_Cfs   = findobj(axe_handles,'flat','Tag',tag_axe_cfs);
  90. WP_Axe_Col   = findobj(axe_handles,'flat','Tag',tag_axe_col);
  91. switch option
  92.     case 'clean'
  93.         % in3 = type of loading.
  94.         %-----------------------
  95.         % 'load_img' , 'load_dec' , 'demo'
  96.         %----------------------------------
  97.         if nargin<4 , in4 = ''; end
  98.         str_btn = 'Analyze';
  99.         cba_btn = ['wp2dmngr(''anal'',' sprintf('%.0f',win_wptool) ');'];
  100.         set(pus_anal,'String',xlate(str_btn),'Callback',cba_btn);
  101.         % Testing first use.
  102.         %-------------------
  103.         active_option = wmemtool('rmb',win_wptool,n_param_anal, ...
  104.                                                         ind_act_option);
  105.         if isempty(active_option) , first = 1; else, first = 0; end
  106.         % End of Cleaning when first is true.
  107.         %------------------------------------
  108.         if first , return; end
  109.         % Setting enable property of objects.
  110.         %------------------------------------
  111.         set([m_savesyn , m_savedec],'Enable','Off');
  112.         cbanapar('enable',win_wptool,'off');
  113.         utentpar('enable',win_wptool,'off');
  114.         set([pus_anal,     pus_deno,    pus_comp,    ...
  115.              pus_inittree, pus_wavtree,              ...
  116.              pus_btree,    pus_blev,    pop_curtree, ...
  117.              pop_nodlab,   pop_nodact,  pus_nodsel,  ...
  118.              pus_full                                ...
  119.              ],...
  120.              'Enable','off'...
  121.              );
  122.         % Cleaning DynVTool.
  123.         %-------------------
  124.         dynvtool('stop',win_wptool);
  125.         % Cleaning Axes.
  126.         %--------------
  127.         wpfullsi('clean',win_wptool);
  128.         axe_hld = [WP_Axe_Tree,WP_Axe_Cfs, WP_Axe_Pack];
  129.         if ~strcmp(in4,'new_anal')
  130.             axe_hld = [axe_hld , WP_Axe_Sig, WP_Axe_Col];
  131.             cleanaxe(axe_hld);
  132.         else      
  133.             titl    = get(WP_Axe_Cfs,'title');
  134.             strtitl = get(titl,'String');
  135.             cleanaxe(axe_hld);
  136.             axes(WP_Axe_Cfs)
  137.             wtitle(strtitl,'Parent',WP_Axe_Cfs,'Visible','on');
  138.         end
  139.         wmemtool('wmb',win_wptool,n_wp_utils,...
  140.                         ind_tree_lin,[],ind_tree_txt,[],ind_sel_nodes,[]);
  141.         % Cleaning GUI.
  142.         %--------------
  143.         set(pop_nodlab,'Value',1,'Userdata',1);
  144.         set(pop_nodact,'Value',1,'Userdata',1);
  145.         if ~strcmp(in4,'new_anal')
  146.             str_lev_data = int2str([1:max_lev_anal]');
  147.             cbanapar('set',win_wptool,...
  148.                 'nam','',             ...
  149.                 'wav','haar',         ...
  150.                 'lev',{'String',str_lev_data,'Value',1});
  151.             utentpar('clean',win_wptool);
  152.         end
  153.     case 'set_gui'
  154.         % in3 = calling option.
  155.         % in4  optional (new_anal).
  156.         %-----------------------------
  157.         if nargin<4 , in4 = ''; end
  158.         switch in3
  159.             case 'load_img'
  160.                 [Img_Name,Img_Size,Img_True_Name] = ...
  161.                         wmemtool('rmb',win_wptool,n_param_anal,...
  162.                                         ind_img_name,ind_img_size, ...
  163.                                         ind_img_t_name);
  164.                 levm         = wmaxlev(Img_Size,'haar');
  165.                 levmax       = min(levm,max_lev_anal);
  166.                 str_lev_data = int2str([1:levmax]');
  167.                 if isequal(Img_True_Name,'X')
  168.                     imgName = Img_Name;
  169.                 else
  170.                     imgName = Img_True_Name;
  171.                 end
  172.                 cbanapar('set',win_wptool,...
  173.                     'n_s',{imgName,Img_Size}, ...
  174.                     'lev',{'String',str_lev_data,'Value',min(levmax,2)});
  175.             case {'demo','load_dec'}
  176.                 [Img_Name,Img_Size,Wave_Name,Level_Anal,...
  177.                         Ent_Name,Ent_Par,Img_True_Name] =     ...
  178.                         wmemtool('rmb',win_wptool,n_param_anal, ...
  179.                                        ind_img_name,ind_img_size,...
  180.                                        ind_wav_name,ind_lev_anal,...
  181.                                        ind_ent_anal,ind_ent_par, ...
  182.                                        ind_img_t_name);
  183.                 levm         = wmaxlev(Img_Size,'haar');
  184.                 levmax       = min(levm,max_lev_anal);
  185.                 str_lev_data = int2str([1:levmax]');
  186.                 if isequal(Img_True_Name,'X')
  187.                     imgName = Img_Name;
  188.                 else
  189.                     imgName = Img_True_Name;
  190.                 end
  191.                 cbanapar('set',win_wptool,...
  192.                     'n_s',{imgName,Img_Size}, ...
  193.                     'wav',Wave_Name, ...
  194.                     'lev',{'String',str_lev_data,'Value',Level_Anal});
  195.                 utentpar('set',win_wptool,'ent',{Ent_Name,Ent_Par});
  196.             case 'anal'
  197.                 Level_Anal = wmemtool('rmb',win_wptool,n_param_anal,...
  198.                                                         ind_lev_anal);
  199.                 levels  = int2str([1:Level_Anal]');
  200.         end
  201.         switch in3
  202.             case {'load_img','demo','load_dec'}
  203.                 pos_g = wmemtool('rmb',win_wptool,n_wp_utils,ind_gra_area);
  204.                 [ pos_axe_pack,   pos_axe_tree,   pos_axe_cfs,    ...
  205.                   pos_axe_sig,    pos_sli_size,   pos_sli_pos,    ...
  206.                   pos_axe_col] =  wpposaxe(win_wptool,2,pos_g,Img_Size);
  207.                 WP_Slider_Size  = findobj(sli_handles,'Tag',tag_sli_size);
  208.                 WP_Slider_Pos   = findobj(sli_handles,'Tag',tag_sli_pos);
  209.                 set(WP_Axe_Tree,'Position',pos_axe_tree);
  210.                 set(WP_Slider_Size,'Position',pos_sli_size);
  211.                 set(WP_Slider_Pos,'Position',pos_sli_pos);
  212.                 set(WP_Axe_Sig,'Position',pos_axe_sig);
  213.                 set(WP_Axe_Pack,'Position',pos_axe_pack);
  214.                 set(WP_Axe_Cfs,'Position',pos_axe_cfs);
  215.         end
  216.     case 'enable'
  217.         % in3 = calling option.
  218.         %----------------------
  219.         switch in3
  220.             case {'load_img','demo','load_dec'}
  221.                 cbanapar('enable',win_wptool,'on');
  222.                 utentpar('enable',win_wptool,'on');
  223.                 set(pus_anal,'Enable','On');
  224.         end
  225.         switch in3
  226.             case {'demo','load_dec','anal','synt'}
  227.                 cbcolmap('enable',win_wptool,'on');
  228.                 set([pus_deno,       pus_comp,       pus_btree,  ...
  229.                      pus_blev,       pus_inittree,   pus_wavtree,...
  230.                      pop_curtree,    pop_nodlab,     pop_nodact, ...
  231.                      pus_nodsel,     pus_full,                   ...
  232.                      ],      ...
  233.                      'Enable','on'...
  234.                      );
  235.                 set([m_savesyn, m_savedec],'Enable','on');
  236.             case {'comp','deno'}
  237.                 set([m_files , pus_anal , pus_deno , pus_comp],'Enable','off');
  238.             case {'return_comp','return_deno'}
  239.                 set([m_files , pus_anal , pus_deno , pus_comp],'Enable','on');
  240.         end
  241.     otherwise
  242.         errargt(mfilename,'Unknown Option','msg');
  243.         error('*');
  244. end