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

波变换

开发平台:

Matlab

  1. function varargout = sw2dtool(option,varargin)
  2. %SW2DTOOL Stationary Wavelet Transform 2-D tool.
  3. %   VARARGOUT = SW2DTOOL(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 02-Mar-1998.
  5. %   Last Revision: 05-Feb-2004.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.9.4.2 $  $Date: 2004/03/15 22:41:46 $
  8. % Test inputs.
  9. %-------------
  10. if nargin==0 , option = 'create'; end
  11. [option,winAttrb] = utguidiv('ini',option,varargin{:});
  12. % Default values.
  13. %----------------
  14. max_lev_anal = 5;
  15. def_lev_anal = 2;
  16. def_nbcolors = 255;
  17. str_dir_det  = strvcat('Horizontal','Diagonal','Vertical');
  18. % Memory Blocks of stored values.
  19. %================================
  20. % MB1.
  21. %-----
  22. n_membloc1    = 'MB_1';
  23. ind_status    = 1;
  24. ind_sav_menu  = 2;
  25. ind_filename  = 3;
  26. ind_pathname  = 4;
  27. ind_img_name  = 5;
  28. ind_img_t_nam = 6;
  29. ind_NB_lev    = 7;
  30. ind_wave      = 8;
  31. nb1_stored    = 8;
  32. % MB2.
  33. %-----
  34. n_membloc2   = 'MB_2';
  35. ind_pus_dec  = 1;
  36. ind_axe_hdl  = 2;
  37. ind_txt_hdl  = 3;
  38. ind_gra_area = 4;
  39. nb2_stored   = 4;
  40. % MB3.
  41. %-----
  42. n_membloc3 = 'MB_3';
  43. ind_coefs  = 1;
  44. nb3_stored = 1;
  45. if ~isequal(option,'create') , win_tool = varargin{1}; end
  46. switch option
  47.     case 'create'
  48.         % Get Globals.
  49.         %-------------
  50.         [Def_Btn_Height,Y_Spacing] = ...
  51.             mextglob('get','Def_Btn_Height','Y_Spacing');
  52.         % Window initialization.
  53.         %-----------------------
  54.         win_title = 'Stationary Wavelet Transform De-noising 2-D';
  55.         [win_tool,pos_win,win_units,str_numwin,...
  56.            frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  57.              wfigmngr('create',win_title,winAttrb,'ExtFig_Tool_3',mfilename,1,1,0);
  58.         if nargout>0 , varargout{1} = win_tool; end
  59. % Add Help for Tool.
  60. %------------------
  61. wfighelp('addHelpTool',win_tool, ...
  62. 'Two-Dimensional Analysis for De-&noising','SW2D_GUI');
  63. % Add Help Item.
  64. %----------------
  65. wfighelp('addHelpItem',win_tool,'Stationary Wavelet Transform','SWT');
  66. wfighelp('addHelpItem',win_tool,'Available Methods','COMP_DENO_METHODS');
  67. wfighelp('addHelpItem',win_tool,'Loading and Saving','SW2D_LOADSAVE');
  68.         % Menu construction for current figure.
  69.         %--------------------------------------
  70.         m_files = wfigmngr('getmenus',win_tool,'file');
  71.         cba_menu = [mfilename '(''load'','  str_numwin ');'];
  72.         uimenu(m_files,...
  73.                       'Label','&Load Image ', ...
  74.                       'Position',1,           ...
  75.                       'Callback', cba_menu    ...
  76.                        );
  77.         cba_menu = [mfilename '(''save'','  str_numwin ');'];
  78.         m_save = uimenu(m_files,...
  79.                         'Label','&Save De-Noised Image ',...
  80.                         'Position',2,        ...
  81.                         'Enable','Off',      ...
  82.                         'Callback', cba_menu ...
  83.                         );
  84.         demoSET = {...
  85.           'Noisy Woman'   , 'noiswom'  , 'haar', 3 , '{''penallo'',46.12}'  ; ...
  86.           'Noisy Woman'   , 'noiswom'  , 'haar', 5 , '{''penallo'',48.62}'  ; ...
  87.           'Noisy Woman'   , 'noiswom'  , 'db3' , 4 , '{''penallo'',NaN}'  ; ...
  88.           'Noisy Barbara' , 'nbarb1'   , 'db1' , 4 , '{}'  ; ...
  89.           'Noisy Sinsin'  , 'noissi2d' , 'db1' , 2 , '{}'   ...
  90.           };
  91.         m_demo = uimenu(m_files,'Label','&Example Analysis','Position',3);
  92.         beg_call_str = [mfilename '(''demo'',' str_numwin ','''];
  93.         nbDEM = size(demoSET,1);
  94.         for k=1:nbDEM
  95.             nam = demoSET{k,1};
  96.             fil = demoSET{k,2};
  97.             wav = demoSET{k,3};
  98.             lev = int2str(demoSET{k,4});
  99.             par = demoSET{k,5};       
  100.             libel = ['with ' wav ' at level ' lev  '  --->  ' nam];
  101.             action = [beg_call_str fil ''',''' wav ''',' lev ',' par ');'];
  102.             uimenu(m_demo,'Label',libel,'Callback',action);
  103.         end
  104.         % Begin waiting.
  105.         %---------------
  106.         wwaiting('msg',win_tool,'Wait ... initialization');
  107.         % General parameters initialization.
  108.         %-----------------------------------
  109.         dy = Y_Spacing;
  110.         str_pus_dec = 'Decompose Image';
  111.         % Command part of the window.
  112.         %============================
  113.         comFigProp = {'Parent',win_tool,'Unit',win_units};
  114.         % Data, Wavelet and Level parameters.
  115.         %------------------------------------
  116.         xlocINI = pos_frame0([1 3]);
  117.         ytopINI = pos_win(4)-dy;
  118.         toolPos = utanapar('create',win_tool, ...
  119.                     'xloc',xlocINI,'top',ytopINI,...
  120.                     'enable','off',        ...
  121.                     'wtype','dwt',         ...
  122.                     'deflev',def_lev_anal, ...
  123.                     'maxlev',max_lev_anal  ...
  124.                     );
  125.         % Decompose pushbutton.
  126.         %----------------------
  127.         h_uic = 3*Def_Btn_Height/2;
  128.         y_uic = toolPos(2)-h_uic-2*dy;
  129.         w_uic = (3*pos_frame0(3))/4;
  130.         x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  131.         pos_pus_dec = [x_uic, y_uic, w_uic, h_uic];
  132.         pus_dec = uicontrol(...
  133.                             'Parent',win_tool,      ...
  134.                             'Style','Pushbutton',   ...
  135.                             'Unit',win_units,       ...
  136.                             'Position',pos_pus_dec, ...
  137.                             'String',xlate(str_pus_dec),   ...
  138.                             'Enable','off',         ...
  139.                             'Interruptible','On'    ...
  140.                             );
  141.         % De-noising tool.
  142.         %-----------------
  143.         ytopTHR = pos_pus_dec(2)-4*dy;
  144.         toolPos = utthrw2d('create',win_tool, ...
  145.                     'xloc',xlocINI,'top',ytopTHR,...
  146.                     'ydir',-1, ...
  147.                     'levmax',def_lev_anal,    ...
  148.                     'levmaxMAX',max_lev_anal, ...
  149.                     'status','Off',  ...
  150.                     'toolOPT','deno' ...
  151.                     );
  152.         % Adding colormap GUI.
  153.         %---------------------
  154.         briflag = (max_lev_anal<6); 
  155.         utcolmap('create',win_tool, ...
  156.                  'xloc',xlocINI, ...
  157.                  'briflag',briflag, ...
  158.                  'enable','off');
  159.         % Callbacks update.
  160.         %------------------
  161.         hdl_den = utthrw2d('handles',win_tool);
  162.         utanapar('set_cba_num',win_tool,[m_files;hdl_den(:)]);
  163.         pop_lev = utanapar('handles',win_tool,'lev');
  164.         end_cba = [str_numwin ',' num2mstr([pop_lev]) ');'];
  165.         cba_pop_lev = [mfilename '(''update_level'',' end_cba];
  166.         cba_pus_dec = [mfilename '(''decompose'','  end_cba];
  167.         set(pop_lev,'Callback',cba_pop_lev);
  168.         set(pus_dec,'Callback',cba_pus_dec);
  169.         % General graphical parameters initialization.
  170.         %--------------------------------------------
  171.         fontsize    = wmachdep('fontsize','normal',9,max_lev_anal);
  172.         txtfontsize = 14;
  173.         % Axes construction parameters.
  174.         %------------------------------
  175.         NB_lev    = max_lev_anal;
  176.         bdx       = 0.08*pos_win(3);
  177.         ecy_up    = 0.06*pos_win(4);
  178.         ecy_mid_1 = 0.08*pos_win(4);
  179.         ecy_mid_2 = ecy_up;
  180.         ecy_down  = ecy_up;
  181.         ecy_det   = (0.04*pos_win(4))/1.4;
  182.         w_gra_rem = Pos_Graphic_Area(3);
  183.         h_gra_rem = Pos_Graphic_Area(4);
  184.         w_left    = (w_gra_rem-3*bdx)/2;
  185.         w_right   = w_left;
  186.         w_medium  = w_left;
  187.         w_detail  = (w_gra_rem-4*bdx)/3+bdx/2;
  188.         x_left    = bdx;
  189.         x_right   = x_left+w_left+5*bdx/4;
  190.         x_medium  = (w_gra_rem-w_medium)/2;
  191.         h_min     = h_gra_rem/4;
  192.         h_max     = h_gra_rem/3;
  193.         h_image   = (h_min*(NB_lev-1)+h_max*(max_lev_anal-NB_lev))/(max_lev_anal-1);
  194.         h_histo   = h_gra_rem/8;
  195.         h_gra_rem = h_gra_rem-h_histo-h_image-ecy_up-ecy_mid_1-ecy_mid_2;
  196.         h_detail  = (h_gra_rem-ecy_down-(NB_lev-1)*ecy_det)/NB_lev;
  197.         y_low_ini = pos_win(4);
  198.         % Building data axes.
  199.         %--------------------
  200.         commonProp   = {...
  201.            'Parent',win_tool,...
  202.            'Visible','off',  ...
  203.            'Units',win_units,...
  204.            'Drawmode','fast',...
  205.            'Box','On'...
  206.            };
  207.         y_low_ini   = y_low_ini-h_image-ecy_up;
  208.         pos_left    = [x_left y_low_ini w_left h_image];
  209.         axe_left_1  = axes(commonProp{:},'Position',pos_left);
  210.         pos_right   = [x_right y_low_ini w_right h_image];
  211.         axe_right_1 = axes(commonProp{:},'Position',pos_right);
  212.         y_low_ini   = y_low_ini-h_histo-ecy_mid_1;
  213.         pos_medium  = [x_medium y_low_ini w_medium h_histo];
  214.         axe_medium  = axes(commonProp{:},'Position',pos_medium);
  215.         y_low_ini   = y_low_ini-ecy_mid_2+ecy_det;
  216.         % Building histograms axes.
  217.         %==========================
  218.         axe_hist = zeros(3,NB_lev);
  219.         commonProp = {commonProp{:},'XTicklabelMode','manual','XTickLabel',[]};
  220.         % Building axes on the left part.
  221.         %-------------------------------    
  222.         txt_left = zeros(NB_lev,1);
  223.         x_left   = bdx;
  224.         y_left   = y_low_ini;
  225.         pos_left = [x_left y_left w_detail h_detail];
  226.         for j = 1:NB_lev
  227.             k = NB_lev-j+1;
  228.             pos_left(2) = pos_left(2)-pos_left(4)-ecy_det;
  229.             axe_hist(1,k) = axes(commonProp{:}, ...
  230.                                 'Position',pos_left,'NextPlot','add');
  231.             str_txt     = ['L' wnsubstr(k)];
  232.             txt_left(k) = txtinaxe('create',str_txt, ...
  233.                              axe_hist(1,k),'l','off','bold',txtfontsize);
  234.         end
  235.         % Building details axes on the middle part.
  236.         %----------------------------------------
  237.         x_mid   = x_left+w_detail+bdx/2;
  238.         y_mid   = y_low_ini;
  239.         pos_mid = [x_mid y_mid w_detail h_detail];
  240.         for k = 1:NB_lev
  241.             j = NB_lev-j+1;
  242.             pos_mid(2)    = pos_mid(2)-pos_mid(4)-ecy_det;
  243.             axe_hist(2,k) = axes(commonProp{:},'Position',pos_mid);
  244.         end
  245.         
  246.         % Building details axes on the right part.
  247.         %-----------------------------------------
  248.         x_right   = x_mid+w_detail+bdx/2;
  249.         y_right   = y_low_ini;
  250.         pos_right = [x_right y_right w_detail h_detail];
  251.         for j = 1:NB_lev
  252.             k = NB_lev-j+1;
  253.             pos_right(2)  = pos_right(2)-pos_right(4)-ecy_det;
  254.             axe_hist(3,k) = axes(commonProp{:},'Position',pos_right);
  255.         end
  256.         %  Normalization.
  257.         %----------------
  258.         Pos_Graphic_Area = wfigmngr('normalize',win_tool,Pos_Graphic_Area);
  259.         drawnow
  260.         % Memory blocks update.
  261.         %----------------------
  262.         axes_hdl = {axe_left_1,axe_right_1,axe_medium,axe_hist};
  263.         utthrw2d('set',win_tool,'axes',axe_hist);
  264.         wmemtool('ini',win_tool,n_membloc1,nb1_stored);
  265.         wmemtool('ini',win_tool,n_membloc2,nb2_stored);
  266.         wmemtool('wmb',win_tool,n_membloc1, ...
  267.                        ind_status,0,        ...
  268.                        ind_sav_menu,m_save  ...
  269.                        );
  270.         wmemtool('wmb',win_tool,n_membloc2, ...
  271.                        ind_pus_dec,pus_dec, ...
  272.                        ind_axe_hdl,axes_hdl,...
  273.                        ind_gra_area,Pos_Graphic_Area, ...
  274.                        ind_txt_hdl,txt_left ...
  275.                        );
  276.         % End waiting.
  277.         %---------------
  278.         wwaiting('off',win_tool);
  279.     case {'load','demo'}
  280.         % Loading file.
  281.         %--------------
  282.         switch option
  283.             case 'load'
  284.                 imgFileType = ['*.mat;*.bmp;*.hdf;*.jpg;' ...
  285.                         '*.jpeg;*.pcx;*.tif;*.tiff;*.gif'];
  286.                 [imgInfos,img_ori,map,ok] = utguidiv('load_img',win_tool, ...
  287.                     imgFileType,'Load Image',def_nbcolors);
  288.                 
  289.             case 'demo'
  290.                 img_Name = deblank(varargin{2});
  291.                 wav_Name = deblank(varargin{3});
  292.                 lev_Anal = varargin{4};
  293.                 if length(varargin)>4 & ~isempty(varargin{5})
  294.                     par_Demo = varargin{5};
  295.                 else
  296.                     par_Demo = '';
  297.                 end
  298.                 filename = [img_Name '.mat'];
  299.                 pathname = utguidiv('WTB_DemoPath',filename);
  300.                 [imgInfos,img_ori,map,ok] = utguidiv('load_dem2D',win_tool, ...
  301.                     pathname,filename,def_nbcolors);
  302.         end
  303.         if ~ok, return; end
  304.         % Begin waiting.
  305.         %---------------
  306.         wwaiting('msg',win_tool,'Wait ... cleaning');
  307.         % Storing values. 
  308.         %-----------------
  309.         wmemtool('wmb',win_tool,n_membloc1, ...
  310.                        ind_status,0,        ...
  311.                        ind_filename,imgInfos.filename,  ...
  312.                        ind_pathname,imgInfos.pathname,  ...
  313.                        ind_img_name,imgInfos.name,      ...
  314.                        ind_img_t_nam,imgInfos.true_name ...
  315.                        );
  316.         % Cleaning and setting GUI. 
  317.         %--------------------------
  318.         cbanapar('enable',win_tool,'Off');
  319.         dynvtool('stop',win_tool);
  320.         ax_hdl  = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  321.         ax_hdl  = [ax_hdl{1:3},ax_hdl{4}(:)'];
  322.         obj2del = [findobj(ax_hdl,'type','line');  ...
  323.                    findobj(ax_hdl,'type','patch'); ...
  324.                    findobj(ax_hdl,'type','image')];
  325.         delete(obj2del)
  326.         utthrw2d('clean_thr',win_tool);
  327.         % Setting analysis  & GUI values.
  328.         %--------------------------------
  329.         levm   = wmaxlev(imgInfos.size,'haar');
  330.         levmax = min(levm,max_lev_anal);
  331.         if isequal(imgInfos.true_name,'X')
  332.             img_Name = imgInfos.name;
  333.         else
  334.             img_Name = imgInfos.true_name;
  335.         end
  336.         if isequal(option,'demo')
  337.             anaPar = {'wav',wav_Name};
  338.         else
  339.             lev_Anal = def_lev_anal;
  340.             anaPar = {};
  341.         end
  342.         strlev = int2str([1:levmax]');
  343.         anaPar = {anaPar{:},'n_s',{img_Name,imgInfos.size}, ...
  344.                   'lev',{'String',strlev,'Value',lev_Anal}};
  345.         cbanapar('set',win_tool,anaPar{:});
  346.         NB_ColorsInPal = size(map,1);
  347.         if imgInfos.self_map , arg = map; else , arg = []; end
  348.         cbcolmap('set',win_tool,'pal',{'pink',NB_ColorsInPal,'self',arg});
  349.         utthrw2d('set',win_tool,'position',{1,lev_Anal})
  350.         % Enabling HDLG.
  351.         %---------------
  352.         sw2dtool('enable',win_tool,'ini','on');
  353.         % Setting axes. 
  354.         %--------------
  355.         sw2dtool('set_axes',win_tool);
  356.         % Initial drawing
  357.         %----------------
  358.         axe_hdl = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  359.         axe_ori = axe_hdl{1};
  360.         hdl_ori = image([1 imgInfos.size(1)],[1 imgInfos.size(2)],img_ori, ...
  361.                         'Parent',axe_ori);
  362.         wtitle('Original Image (I)','Parent',axe_ori)
  363.         utthrw2d('set',win_tool,'handleORI',hdl_ori);
  364.         % Analyze and De-noise.
  365.         %----------------------
  366.         if isequal(option,'demo')
  367.             sw2dtool('decompose',win_tool);
  368.             if ~isempty(par_Demo)
  369.                 den_Meth = par_Demo{1};
  370.                 if length(par_Demo)>1
  371.                     thr_Val  = par_Demo{2};
  372.                 else
  373.                     thr_Val  = NaN;
  374.                 end
  375.                 if isequal(den_Meth,'penallo')
  376.                     utthrw2d('demo',win_tool,'swt2',den_Meth,thr_Val);
  377.                 end
  378.             end
  379.             sw2dtool('denoise',win_tool);
  380.         end
  381.         cbanapar('enable',win_tool,'On');
  382.         % End waiting.
  383.         %-------------
  384.         wwaiting('off',win_tool);
  385.     case 'save'
  386.         % Testing file.
  387.         %--------------
  388.         [filename,pathname,ok] = utguidiv('test_save',win_tool, ...
  389.                                      '*.mat','Save De-Noised Image');
  390.         if ~ok, return; end
  391.         % Begin waiting.
  392.         %--------------
  393.         wwaiting('msg',win_tool,'Wait ... saving');
  394.         % Getting colormap.
  395.         %------------------
  396.         map = cbcolmap('get',win_tool,'self_pal');
  397.         if isempty(map) , map = pink(def_nbcolors); end
  398.         % Get de-noised signal.
  399.         %----------------------
  400.         hdl_den = utthrw2d('get',win_tool,'handleTHR');
  401.         X = get(hdl_den,'Cdata');
  402.         % Saving file.
  403.         %--------------
  404.         [wname,Lev_Anal] = wmemtool('rmb',win_tool,n_membloc1, ...
  405.                                           ind_wave,ind_NB_lev);        
  406.         valTHR = utthrw2d('get',win_tool,'allvalthr');
  407.         valTHR = valTHR(:,1:Lev_Anal);
  408.         [name,ext] = strtok(filename,'.');
  409.         if isempty(ext) | isequal(ext,'.')
  410.             ext = '.mat'; filename = [name ext];
  411.         end
  412.         saveStr = {'X','map','wname','valTHR'};
  413.         wwaiting('off',win_tool);        
  414.         try
  415.           save([pathname filename],saveStr{:});
  416.         catch
  417.           errargt(mfilename,'Save FAILED !','msg');
  418.         end
  419.    
  420.         % End waiting.
  421.         %-------------
  422.         wwaiting('off',win_tool);
  423.     case 'decompose'
  424.         % Compute decomposition and plot.
  425.         %--------------------------------
  426.         wwaiting('msg',win_tool,'Wait ... computing');
  427.         % Get handles analysis parameters.
  428.         %---------------------------------
  429.         [wname,Lev_Anal] = cbanapar('get',win_tool,'wav','lev');
  430.         hdl_ori = utthrw2d('get',win_tool,'handleORI');
  431.         img_ori = get(hdl_ori,'Cdata');
  432.         siz_ori = size(img_ori);
  433.         pow = 2^Lev_Anal;
  434.         if any(rem(siz_ori,pow))
  435.             siz_sug = ceil(siz_ori/pow)*pow;
  436.             wwaiting('off',win_tool);
  437.             oriStr = ['(' int2str(siz_ori(1)) ',' int2str(siz_ori(2)) ')'];
  438.             sugStr = ['(' int2str(siz_sug(1)) ',' int2str(siz_sug(2)) ')'];
  439.             msg = strvcat(...
  440.             ['The level of decomposition ' int2str(Lev_Anal)],...
  441.             ['and the size of the image ' oriStr],...
  442.             'are not compatible.',...
  443.             ['Suggested size: ' sugStr],...
  444.             '(see Image Extension Tool)', ...
  445.             ' ', ...
  446.             ['2^Level has to divide the size of the image.'] ...
  447.             );
  448.             errargt(mfilename,msg,'msg');
  449.             return
  450.         end        
  451.         % Clean HDLG.
  452.         %---------------
  453.         utthrw2d('clean_thr',win_tool);
  454.         % Get Handles.
  455.         %--------------------------------------------------------
  456.         % ax_hdl = {axe_left_1 axe_right_1 axe_medium  axe_hist}
  457.         %--------------------------------------------------------
  458.         ax_hdl = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  459.         % Clean axes.
  460.         %------------
  461.         axe_hist = ax_hdl{4};
  462.         axes2clean = [ax_hdl{2};ax_hdl{3};axe_hist(:)];
  463.         obj2del = [findobj(axes2clean,'type','line');   ...
  464.                    findobj(axes2clean,'type','image');  ...
  465.                    findobj(axes2clean,'type','patch')   ...
  466.                    ];
  467.         delete(obj2del)
  468.         set(axe_hist(:),'Nextplot','add')
  469.         % Setting prog status.
  470.         %----------------------
  471.         wmemtool('wmb',win_tool,n_membloc1, ...
  472.                        ind_status,1,ind_NB_lev,Lev_Anal,ind_wave,wname);
  473.         % Clean reset axes limits.
  474.         %-------------------------
  475.         set([ax_hdl{1:2}],'Xlim',[1 siz_ori(2)],'Ylim',[1 siz_ori(1)])
  476.         % Compute Decomposition.
  477.         %------------------------
  478.         wDEC = swt2(img_ori,Lev_Anal,wname);
  479.         wmemtool('wmb',win_tool,n_membloc3,ind_coefs,wDEC);
  480.         % Initializing by level threshold.
  481.         %---------------------------------
  482.         maxTHR = zeros(3,Lev_Anal);
  483.         valTHR = sw2dtool('compute_LVL_THR',win_tool);
  484.         permDir = [1 3 2];
  485.         index   = zeros(3,Lev_Anal);
  486.         for k = 1:Lev_Anal
  487.           for d=1:3 , index(d,k) = (permDir(d)-1)*Lev_Anal+k; end
  488.         end
  489.         for k=1:Lev_Anal
  490.             for d=1:3
  491.                 ind = index(d,k);
  492.                 curr_img = wDEC(:,:,ind);
  493.                 curr_img = curr_img(:);
  494.                 tmp = max(abs(curr_img));
  495.                 if tmp<eps , maxTHR(d,k) = 1; else , maxTHR(d,k) = 1.1*tmp; end
  496.             end
  497.         end
  498.         valTHR = min(maxTHR,valTHR);
  499.         % Displaying details coefficients histograms.
  500.         %--------------------------------------------
  501.         dirDef   = 1;
  502.         fontsize = wmachdep('fontsize','normal');
  503.         col_det  = wtbutils('colors','det',Lev_Anal);
  504.         nb_bins  = 50;
  505.         axeXColor = get(win_tool,'DefaultAxesXColor');        
  506.         for level = 1:Lev_Anal
  507.             for direct=1:3
  508.                 ind = index(direct,level);
  509.                 curr_img = wDEC(:,:,ind);
  510.                 curr_img = curr_img(:);
  511.                 axeAct   = axe_hist(direct,level);
  512.                 axes(axeAct);
  513.                 curr_color = col_det(level,:);
  514.                 his        = wgethist(curr_img,nb_bins);
  515.                 his(2,:)   = his(2,:)/length(curr_img);
  516.                 hdl_hist   = wplothis(axeAct,his,curr_color);
  517.                 if level>1
  518.                     wxlabel('','Parent',axeAct);
  519.                 else
  520.                     wxlabel([deblank(str_dir_det(direct,:)) ' Details'],...
  521.                             'color',axeXColor,'Parent',axeAct);
  522.                 end
  523.                 thr_val = valTHR(direct,level);
  524.                 thr_max = maxTHR(direct,level);
  525.                 ylim    = get(axeAct,'Ylim');
  526.                 utthrw2d('plot_dec',win_tool,dirDef, ...
  527.                           {thr_max,thr_val,ylim,direct,level,axeAct})
  528.                 xmax = 1.1*max([thr_max, max(abs(his(1,:)))]);
  529.                 set(axeAct,'Xlim',[-xmax xmax]);
  530.                 set(findall(axeAct),'Visible','on');
  531.             end
  532.         end
  533.         drawnow
  534.         % Initialization of denoising structure.
  535.         %----------------------------------------
  536.         utthrw2d('set',win_tool,'valthr',valTHR,'maxthr',maxTHR);
  537.         % Dynvtool Attachement.
  538.         %---------------------
  539.         axe_cmd = [ax_hdl{1:2}];
  540.         dynvtool('init',win_tool,[],axe_cmd,[],[1 1],'','','','int')
  541.         % Enabling HDLG.
  542.         %---------------
  543.         sw2dtool('enable',win_tool,'dec','on');
  544.         % End waiting.
  545.         %-------------
  546.         wwaiting('off',win_tool);
  547.     case 'denoise'
  548.         % Compute decomposition and plot.
  549.         %--------------------------------
  550.         wwaiting('msg',win_tool,'Wait ... computing');
  551.         % Diseable De-noising Tool.
  552.         %---------------------------
  553.         utthrw2d('enable',win_tool,'off');
  554.         % Get decomposition.
  555.         %-------------------
  556.         [wname,Lev_Anal] = wmemtool('rmb',win_tool,n_membloc1, ...
  557.                                           ind_wave,ind_NB_lev);        
  558.         wDEC = wmemtool('rmb',win_tool,n_membloc3,ind_coefs);
  559.         valTHR = utthrw2d('get',win_tool,'allvalthr');
  560.         valTHR = valTHR(:,1:Lev_Anal);
  561.         permDir = [1 3 2];
  562.         for level = 1:Lev_Anal
  563.             for kk=1:3
  564.                ind = (permDir(kk)-1)*Lev_Anal+level;
  565.                thr = valTHR(kk,level);
  566.                wDEC(:,:,ind) = wthresh(wDEC(:,:,ind),'s',thr);
  567.             end
  568.         end
  569.         % Plotting de-noised Image.
  570.         %---------------------------
  571.         img_den = iswt2(wDEC,wname);
  572.         axe_hdl = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  573.         axe_ori = axe_hdl{1};
  574.         axe_den = axe_hdl{2};
  575.         axe_dif = axe_hdl{3};
  576.         hdl_den = image(img_den,'Parent',axe_den);
  577.         xylim   = get(axe_ori,{'Xlim','Ylim'});
  578.         set(axe_den,'Xlim',xylim{1},'Ylim',xylim{2},'Visible','on');
  579.         wtitle('De-Noised image (DI)','Parent',axe_den);
  580.         hdl_ori  = utthrw2d('get',win_tool,'handleORI');
  581.         img_dif  = get(hdl_ori,'Cdata')-img_den;
  582.         img_dif  = img_dif(:);
  583.         nb_bins  = 80;
  584.         color    = wtbutils('colors','sw2d','histRES');
  585.         his      = wgethist(img_dif,nb_bins);
  586.         his(2,:) = his(2,:)/length(img_dif);
  587.         hdl_hist = wplothis(axe_dif,his,color);
  588.         wtitle('Histogram of residuals: (I) - (DI)','Parent',axe_dif);
  589.         % Memory blocks update.
  590.         %----------------------
  591.         utthrw2d('set',win_tool,'handleTHR',hdl_den);
  592.         wmemtool('wmb',win_tool,n_membloc1,ind_status,1);
  593.         % Dynvtool Attachement.
  594.         %---------------------
  595.         dynvtool('ini_his',win_tool,0);
  596.         dynvtool('put',win_tool)
  597.         % Enabling HDLG.
  598.         %---------------
  599.         utthrw2d('enable',win_tool,'on');
  600.         sw2dtool('enable',win_tool,'den','on');
  601.         % End waiting.
  602.         %---------------
  603.         wwaiting('off',win_tool);
  604.     case 'update_level'
  605.         pop_lev = varargin{2}(1);
  606.         lev_New  = get(pop_lev,'value');
  607.         [status,lev_Anal] = wmemtool('rmb',win_tool,n_membloc1,...
  608.             ind_status,ind_NB_lev);
  609.         utthrw2d('set',win_tool,'position',{1,lev_New});
  610.         sw2dtool('set_axes',win_tool);
  611.         vis_InAxes = 'off';
  612.         if isequal(lev_New,lev_Anal)
  613.             switch status
  614.                 case -1 , 
  615.                     sw2dtool('enable',win_tool,'ini');
  616.                 case  0 ,
  617.                     sw2dtool('enable',win_tool,'dec');
  618.                 case  1 ,
  619.                     vis_InAxes = 'on';
  620.                     sw2dtool('enable',win_tool,'dec','on');
  621.                     sw2dtool('enable',win_tool,'den','on');
  622.             end
  623.         else
  624.             sw2dtool('enable',win_tool,'ini');
  625.         end
  626.         
  627.         % Get Handles.
  628.         %--------------------------------------------------------
  629.         % ax_hdl = {axe_left_1 axe_right_1 axe_medium  axe_hist}
  630.         %--------------------------------------------------------
  631.         ax_hdl  = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  632.         axe_Off = [ax_hdl{2};ax_hdl{3}];
  633.         obj_Off = [findobj(axe_Off,'type','line');  ...
  634.                    findobj(axe_Off,'type','patch'); ...
  635.                    findobj(axe_Off,'type','image')];
  636.         set(obj_Off,'Visible',vis_InAxes);
  637.                 
  638.     case 'compute_LVL_THR'
  639.         [numMeth,meth,alfa,sorh] = utthrw2d('get_LVL_par',win_tool);
  640.         wDEC = wmemtool('rmb',win_tool,n_membloc3,ind_coefs);
  641.         varargout{1} = wthrmngr('sw2ddenoLVL',meth,wDEC,alfa);
  642.     case 'update_LVL_meth'
  643.         sw2dtool('clear_GRAPHICS',win_tool);
  644.         valTHR = sw2dtool('compute_LVL_THR',win_tool);
  645.         utthrw2d('update_LVL_meth',win_tool,valTHR);
  646.     case 'clear_GRAPHICS'
  647.         status = wmemtool('rmb',win_tool,n_membloc1,ind_status);
  648.         if status<1 , return; end
  649.         % Diseable Toggle and Menus.
  650.         %---------------------------
  651.         sw2dtool('enable',win_tool,'den','off');
  652.         % Get Handles.
  653.         %-------------
  654.         axe_hdl = wmemtool('rmb',win_tool,n_membloc2,ind_axe_hdl);
  655.         axe_Off = [axe_hdl{2};axe_hdl{3}];
  656.         obj_Off = [findobj(axe_Off,'type','line');  ...
  657.                    findobj(axe_Off,'type','patch'); ...
  658.                    findobj(axe_Off,'type','image')];
  659.         set(obj_Off,'Visible','off');
  660.     case 'enable'
  661.         type  = varargin{2};
  662.         m_sav = wmemtool('rmb',win_tool,n_membloc1,ind_sav_menu);
  663.         switch type 
  664.           case 'ini'
  665.             set(m_sav,'Enable','off');
  666.             pus_dec = wmemtool('rmb',win_tool,n_membloc2,ind_pus_dec);
  667.             col_hdl = utcolmap('handles',win_tool,'act','true');
  668.             utthrw2d('status',win_tool,'off');
  669.             set([pus_dec;col_hdl],'Enable','on');
  670.           case 'dec'
  671.             nb_lev = wmemtool('rmb',win_tool,n_membloc1,ind_NB_lev);
  672.             set(m_sav,'Enable','off');
  673.             utthrw2d('status',win_tool,'on');
  674.             utthrw2d('enable',win_tool,'on',[1:nb_lev]);
  675.             wmemtool('wmb',win_tool,n_membloc1,ind_status,0);
  676.           case 'den'
  677.             enaVal = varargin{3};
  678.             set(m_sav,'Enable',enaVal);
  679.             utthrw2d('enable_tog_res',win_tool,enaVal);
  680.             if strncmpi(enaVal,'on',2) , status = 1; else , status = 0; end
  681.             wmemtool('wmb',win_tool,n_membloc1,ind_status,status);
  682.         end
  683.     case 'set_axes'
  684.         %*************************************************************%
  685.         %** OPTION = 'set_axes' - Set axes positions and visibility **%
  686.         %*************************************************************%
  687.         pos_win = get(win_tool,'Position');
  688.         [ax_hdl,Pos_Graphic_Area] = wmemtool('rmb',win_tool,n_membloc2,...
  689.                                                    ind_axe_hdl,ind_gra_area);
  690.         [wname,NB_lev] = cbanapar('get',win_tool,'wav','lev');
  691.         % Hide axes
  692.         %-----------
  693.         ax_2_clean  = [ax_hdl{1:3},ax_hdl{4}(:)'];
  694.         obj_in_axes = findobj(ax_2_clean);
  695.         set(obj_in_axes,'Visible','off');
  696.         % Plots.
  697.         %--------------------------------------------------------
  698.         % ax_hdl = {axe_left_1 axe_right_1 axe_medium  axe_hist} 
  699.         %--------------------------------------------------------
  700.         NBaxes  = length(ax_2_clean);
  701.         ax_l_1  = ax_hdl{1};
  702.         ax_r_1  = ax_hdl{2};
  703.         ax_med  = ax_hdl{3};
  704.         ax_hist = ax_hdl{4};
  705.         % General graphical parameters initialization.
  706.         %---------------------------------------------
  707.         ecy_up    = 0.06*pos_win(4);
  708.         ecy_mid_1 = 0.08*pos_win(4);
  709.         ecy_mid_2 = ecy_up;
  710.         ecy_down  = ecy_up;
  711.         ecy_det   = (0.04*pos_win(4))/1.4;
  712.         h_gra_rem = Pos_Graphic_Area(4);
  713.         h_min     = h_gra_rem/4;
  714.         h_max     = h_gra_rem/3;
  715.         h_image   = (h_min*(NB_lev-1)+h_max*(max_lev_anal-NB_lev))/(max_lev_anal-1);
  716.         h_histo   = h_gra_rem/8;
  717.         h_gra_rem = h_gra_rem-h_histo-h_image-ecy_up-ecy_mid_1-ecy_mid_2;
  718.         h_detail  = (h_gra_rem-ecy_down-(NB_lev-1)*ecy_det)/NB_lev;
  719.         y_low_ini = 1;
  720.         % Building data axes.
  721.         %--------------------
  722.         y_low_ini = y_low_ini-h_image-ecy_up;
  723.         pos_axes  = get(ax_l_1,'Position');
  724.         pos_axes([2 4]) = [y_low_ini h_image];
  725.         set(ax_l_1,'Position',pos_axes);
  726.         axe_vis   = [ax_l_1];
  727.         pos_axes = get(ax_r_1,'Position');
  728.         pos_axes([2 4]) = [y_low_ini h_image];
  729.         set(ax_r_1,'Position',pos_axes)
  730.         axe_vis  = [axe_vis ax_r_1];
  731.         y_low_ini = y_low_ini-h_histo-ecy_mid_1;
  732.         pos_axes  = get(ax_med,'Position');
  733.         pos_axes([2 4]) = [y_low_ini h_histo];
  734.         set(ax_med,'Position',pos_axes)
  735.         axe_vis   = [axe_vis ax_med];
  736.         y_low_ini = y_low_ini-ecy_mid_2+ecy_det;
  737.         % Position for histograms axes.
  738.         %------------------------------   
  739.         axeXColor = get(win_tool,'DefaultAxesXColor');        
  740.         pos_y    = [y_low_ini , h_detail];
  741.         for level = NB_lev:-1:1
  742.             pos_y(1) = pos_y(1)-h_detail-ecy_det;
  743.             for direct=1:3
  744.                 ax_act   = ax_hist(direct,level);
  745.                 pos_axes = get(ax_act,'Position');           
  746.                 pos_axes([2 4]) = pos_y;
  747.                 set(ax_act,'Position',pos_axes);
  748.                 axe_vis = [axe_vis ax_act];
  749.                 if level>1
  750.                     wxlabel('','Parent',ax_act);
  751.                 else
  752.                     wxlabel([deblank(str_dir_det(direct,:)) ' Details'],...
  753.                             'color',axeXColor,...
  754.                             'Parent',ax_act);
  755.                 end
  756.             end           
  757.         end
  758.         % Setting axes visibility & title.
  759.         %---------------------------------
  760.         obj_in_axes_vis = findobj(axe_vis);
  761.         set(obj_in_axes_vis,'Visible','on');
  762.         wtitle('Original Image (I)','Parent',ax_l_1);
  763.         wtitle('Histogram of residuals: (I) - (DI)','Parent',ax_med);
  764.         wtitle('De-Noised Image (DI)','Parent',ax_r_1);
  765.                     
  766.     case 'close'
  767.     otherwise
  768.         errargt(mfilename,'Unknown Option','msg');
  769.         error('*');
  770. end