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

波变换

开发平台:

Matlab

  1. function varargout = dw2dcomp(option,varargin)
  2. %DW2DCOMP Discrete wavelet 2-D compression.
  3. %   VARARGOUT = DW2DCOMP(OPTION,VARARGIN)
  4.               
  5. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  6. %   Last Revision: 12-Mar-2003.
  7. %   Copyright 1995-2004 The MathWorks, Inc.
  8. %   $Revision: 1.19.4.2 $ $Date: 2004/03/15 22:40:18 $
  9. % Memory Blocks of stored values.
  10. %================================
  11. % MB1.
  12. %-----
  13. n_param_anal   = 'DWAn2d_Par_Anal';
  14. ind_img_name   = 1;
  15. ind_wav_name   = 2;
  16. ind_lev_anal   = 3;
  17. ind_img_t_name = 4;
  18. ind_img_size   = 5;
  19. ind_nbcolors   = 6;
  20. ind_act_option = 7;
  21. ind_simg_type  = 8;
  22. ind_thr_val    = 9;
  23. nb1_stored     = 9;
  24. % MB2.1 and MB2.2.
  25. %-----------------
  26. n_coefs = 'MemCoefs';
  27. n_sizes = 'MemSizes';
  28. % MB1 (local).
  29. %-------------
  30. n_misc_loc = ['MB1_' mfilename];
  31. ind_sav_menus  = 1;
  32. ind_status     = 2;
  33. ind_win_caller = 3;
  34. ind_axe_datas  = 4;
  35. ind_hdl_datas  = 5;
  36. ind_pop_mod    = 6;
  37. nbLOC_1_stored = 6;
  38. % MB2 (local).
  39. %-------------
  40. n_thrDATA = 'thrDATA';
  41. ind_value = 1;
  42. nbLOC_2_stored = 1;
  43. if ~isequal(option,'create') , win_compress = varargin{1}; end                
  44. switch option
  45.     case 'create'
  46.         % Get Globals.
  47.         %-------------
  48.         [Def_Btn_Height,Y_Spacing,Def_FraBkColor] = ...
  49.             mextglob('get','Def_Btn_Height','Y_Spacing','Def_FraBkColor');
  50.         % Calling figure.
  51.         %----------------
  52.         win_caller = varargin{1};
  53.         str_win_caller = sprintf('%.0f',win_caller);
  54.         % Window initialization.
  55.         %----------------------
  56.         win_name = 'Wavelet 2-D  --  Compression';
  57.         [win_compress,pos_win,win_units,str_win_compress,...
  58.             frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  59.                  wfigmngr('create',win_name,'',...
  60.                      'ExtFig_CompDeno',strvcat(mfilename,'cond'));
  61.         set(win_compress,'userdata',win_caller);
  62.         varargout{1} = win_compress;
  63. % Add Help for Tool.
  64. %------------------
  65. wfighelp('addHelpTool',win_compress,'Image Compression','DW2D_COMP_GUI');
  66. % Add Help Item.
  67. %----------------
  68. wfighelp('addHelpItem',win_compress,'Compression Procedure','COMP_PROCEDURE');
  69. wfighelp('addHelpItem',win_compress,'Available Methods','COMP_DENO_METHODS');
  70. wfighelp('addHelpItem',win_compress,'Compressing Images','COMP_IMAGES');
  71. % Menu construction for current figure.
  72.         %--------------------------------------
  73. m_save  = wfigmngr('getmenus',win_compress,'save');
  74.         sav_menus(1) = uimenu(m_save,...
  75.                                 'Label','Compressed &Image ',...
  76.                                 'Position',1,                   ...
  77.                                 'Enable','Off',                 ...
  78.                                 'Callback',                     ...
  79.                                 [mfilename '(''save_synt'','    ...
  80.                                         str_win_compress ');']  ...
  81.                                 );
  82.         sav_menus(2) = uimenu(m_save,...
  83.                                 'Label','&Coefficients ',   ...
  84.                                 'Position',2,                   ...
  85.                                 'Enable','Off',                 ...
  86.                                 'Callback',                     ...
  87.                                 [mfilename '(''save_cfs'','     ...
  88.                                         str_win_compress ');']  ...
  89.                                 );
  90.         sav_menus(3) = uimenu(m_save,...
  91.                                 'Label','&Decomposition ',  ...
  92.                                 'Position',3,                   ...
  93.                                 'Enable','Off',                 ...
  94.                                 'Callback',                     ...
  95.                                 [mfilename '(''save_dec'','     ...
  96.                                          str_win_compress ');'] ...
  97.                                 );
  98.         % Begin waiting.
  99.         %---------------
  100.         wwaiting('msg',win_compress,'Wait ... initialization');
  101.         % Getting  Analysis parameters.
  102.         %------------------------------
  103.         [Img_Name,Img_Size,Wav_Name,Lev_Anal] = ...
  104.         wmemtool('rmb',win_caller,n_param_anal, ...
  105.                                 ind_img_name,   ...
  106.                                 ind_img_size,   ...
  107.                                 ind_wav_name,   ...
  108.                                 ind_lev_anal    ...
  109.                                 );
  110.         [Wav_Fam,Wav_Num] = wavemngr('fam_num',Wav_Name);
  111.         isBior = wavemngr('isbior',Wav_Fam);
  112.         % General parameters initialization.
  113.         %-----------------------------------
  114.         dy = Y_Spacing;
  115.         str_dir_det = strvcat('Horizontal','Diagonal','Vertical');
  116.         str_pop_mod = strvcat('Global thresholding','By Level thresholding');
  117.         % Command & Graphic parts (common & global thresholding).
  118.         %========================================================
  119.         comFigProp = {'Parent',win_compress,'Unit',win_units};
  120.         % Data, Wavelet and Level parameters.
  121.         %------------------------------------
  122.         xlocINI = pos_frame0([1 3]);
  123.         ytopINI = pos_win(4)-dy;
  124.         toolPos = utanapar('create_copy',win_compress, ...
  125.                     {'xloc',xlocINI,'top',ytopINI},...
  126.                     {'n_s',{Img_Name,Img_Size},'wav',Wav_Name,'lev',Lev_Anal} ...
  127.                     );
  128.         % Popup for mode.
  129.         %----------------
  130.         w_uic = (3*pos_frame0(3))/4;
  131.         x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  132.         h_uic = Def_Btn_Height;
  133.         y_uic = toolPos(2)-4*dy-h_uic;
  134.         pos_pop_mod = [x_uic, y_uic, w_uic, h_uic];            
  135.         pop_mod = uicontrol(comFigProp{:},...
  136.                             'Style','Popup',...
  137.                             'Position',pos_pop_mod,...
  138.                             'Userdata',1,...
  139.                             'String',str_pop_mod...
  140.                             );
  141.         cba_pop_mod = [mfilename '(''change_mode'',' ...
  142.                           str_win_compress ',' num2mstr(pop_mod) ');'];
  143.         set(pop_mod,'Callback',cba_pop_mod);
  144.         % Global Compression tools.
  145.         %-------------------------
  146.         ytopTHR = pos_pop_mod(2)-4*dy;
  147.         utthrgbl('create',win_compress,'toolOPT','dw2dcomp', ...
  148.                  'xloc',xlocINI,'top',ytopTHR, ...
  149.                  'isbior',isBior,   ...
  150.                  'caller',mfilename ...
  151.                  );
  152.         % Adding colormap GUI.
  153.         %---------------------
  154.         briflag = (Lev_Anal<6); 
  155.         if Lev_Anal<6
  156.             pop_pal_caller = cbcolmap('get',win_caller,'pop_pal');
  157.             prop_pal = get(pop_pal_caller,{'String','Value','Userdata'});
  158.             utcolmap('create',win_compress, ...
  159.                      'xloc',xlocINI, ...
  160.                      'bkcolor',Def_FraBkColor, ...
  161.                      'briflag',briflag, ...
  162.                      'enable','on');
  163.             pop_pal_loc = cbcolmap('get',win_compress,'pop_pal');
  164.             set(pop_pal_loc,'String',prop_pal{1},'Value',prop_pal{2}, ...
  165.                             'Userdata',prop_pal{3});
  166.             set(win_compress,'Colormap',get(win_caller,'Colormap'));
  167.         end
  168.         % Displaying the window title.
  169.         %-----------------------------
  170.         strX = sprintf('%.0f',Img_Size(2));
  171.         strY = sprintf('%.0f',Img_Size(1));
  172.         str_nb_val   = [' (' strX ' x ' strY ')'];
  173.         str_wintitle = [Img_Name,str_nb_val,' analyzed at level ',...
  174.                         sprintf('%.0f',Lev_Anal),' with ',Wav_Name];
  175.         wfigtitl('string',win_compress,str_wintitle,'on');
  176.         drawnow
  177.         % General graphical parameters initialization.
  178.         %--------------------------------------------
  179.         bdx_l   = 0.10*pos_win(3);
  180.         bdx_r   = 0.06*pos_win(3);
  181.         bdx     = 0.08*pos_win(3);
  182.         ecx     = 0.04*pos_win(3);
  183.         bdy     = 0.07*pos_win(4);
  184.         ecy     = 0.03*pos_win(4);
  185.         y_graph = 2*Def_Btn_Height+dy;
  186.         h_graph = pos_frame0(4)-y_graph-Def_Btn_Height;
  187.         w_graph = pos_frame0(1);
  188.         % Common axes properties.
  189.         %------------------------
  190.         comAxeProp = {...
  191.           comFigProp{:},    ...
  192.           'Units',win_units,...
  193.           'Drawmode','fast',...
  194.           'Box','On',       ...
  195.           'Visible','off'   ...
  196.           };
  197.         % Building axes for original image.
  198.         %----------------------------------
  199.         x_axe  = bdx;
  200.         w_axe  = (w_graph-ecx-3*bdx/2)/2;
  201.         h_axe  = 0.95*w_axe;
  202.         y_axe  = y_graph+h_graph-w_axe-bdy;
  203.         cx_ori = x_axe+w_axe/2;
  204.         cy_ori = y_axe+h_axe/2;
  205.         cx_cmp = cx_ori+w_axe+ecx;
  206.         cy_cmp = cy_ori;
  207.         [w_used,h_used] = wpropimg(Img_Size,w_axe,h_axe,'pixels');
  208.         pos_axe      = [cx_ori-w_used/2 cy_ori-h_used/2 w_used h_used];
  209.         axe_datas(1) = axes(comAxeProp{:},'Position',pos_axe);
  210.         axe_orig     = axe_datas(1);
  211.         % Displaying original image.
  212.         %---------------------------
  213.         Img_Anal  = get(dw2drwcd('r_orig',win_caller),'Cdata');
  214.         hdl_datas = [NaN;NaN];
  215.         set(win_compress,'Colormap',get(win_caller,'Colormap'));
  216.         hdl_datas(1) = image([1 Img_Size(1)],[1,Img_Size(2)],Img_Anal, ...
  217.                             'Parent',axe_orig);
  218.         wtitle('Original image','Parent',axe_orig);
  219.         % Building axes for compressed image.
  220.         %------------------------------------
  221.         pos_axe = [cx_cmp-w_used/2 cy_cmp-h_used/2 w_used h_used];
  222.         xylim   = get(axe_orig,{'Xlim','Ylim'});
  223.         axe_datas(2) = axes(comAxeProp{:},...
  224.                             'Position',pos_axe,'Xlim',xylim{1},'Ylim',xylim{2});
  225.         axe_comp = axe_datas(2);
  226.         % Initializing global threshold.
  227.         %-------------------------------
  228.         [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  229.             dw2dcomp('compute_GBL_THR',win_compress,win_caller);
  230.         utthrgbl('set',win_compress,'thrBOUNDS',[0,valTHR,maxTHR]);
  231.         % Displaying perfos & legend.
  232.         %----------------------------
  233.         y_graph = 2*Def_Btn_Height+dy;
  234.         h_graph = pos_frame0(4)-y_graph-Def_Btn_Height;
  235.         w_graph = pos_frame0(1);
  236.         w_axe  = (w_graph-ecx-3*bdx/2)/2;
  237.         h_axe  = (h_graph-3*bdy)/2;
  238.         x_axe = bdx;
  239.         y_axe = y_graph+bdy;
  240.         pos_axe_perfo = [x_axe y_axe w_axe h_axe];
  241.         x_axe = bdx+w_axe+ecx;
  242.         y_axe = y_graph+w_axe/3+bdy;
  243.         h_axe = w_axe/3;
  244.         pos_axe_legend = [x_axe y_axe w_axe h_axe];
  245.         utthrgbl('displayPerf',win_compress, ...
  246.                   pos_axe_perfo,pos_axe_legend,thresVALUES,n0SCR,rl2SCR,valTHR);
  247.         [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  248.         utthrgbl('set',win_compress,'perfo',[perfl2,perf0]);
  249.         drawnow
  250.         % Command & Graphic parts (by Level thresholding).
  251.         %=================================================
  252.         % Compression tool.
  253.         %-------------------
  254.         utthrw2d('create',win_compress, ...
  255.                  'xloc',xlocINI,'top',ytopTHR,...
  256.                  'ydir',-1, ...
  257.                  'visible','off', ...
  258.                  'enable','on', ...
  259.                  'levmax',Lev_Anal, ...
  260.                  'levmaxMAX',Lev_Anal, ...
  261.                  'isbior',isBior,  ...
  262.                  'toolOPT','comp' ...
  263.                  );
  264.         % Building axes for histograms.
  265.         %------------------------------
  266.         x_axe    = bdx;
  267.         y_axe    = y_graph+bdy;
  268.         h_axe    = (h_graph-w_axe-3*bdy-(Lev_Anal-1)*ecy)/Lev_Anal;
  269.         w_axe    = (w_graph-2*ecx-3*bdx/2)/3;
  270.         pos_axe  = [x_axe y_axe w_axe h_axe];
  271.         axe_hist = zeros(3,Lev_Anal);
  272.         for k = 1:Lev_Anal
  273.             pos_axe(1) = bdx_l;
  274.             pos_axe(2) = y_graph+bdy+(k-1)*(h_axe+ecy);
  275.             for direct=1:3
  276.                 axe_hist(direct,k) = axes(comAxeProp{:},'Position',pos_axe);
  277.                 pos_axe(1) = pos_axe(1)+pos_axe(3)+ecx;
  278.             end
  279.         end
  280.         utthrw2d('set',win_compress,'axes',axe_hist);
  281.         drawnow
  282.         % Initializing by level threshold.
  283.         %---------------------------------
  284.         maxTHR = zeros(3,Lev_Anal);
  285.         [valTHR,perfl2,perf0] = ...
  286.             dw2dcomp('compute_LVL_THR',win_compress,win_caller);
  287.         coefs = wmemtool('rmb',win_caller,n_coefs,1);
  288.         sizes = wmemtool('rmb',win_caller,n_sizes,1);
  289.         for d=1:3
  290.             for i=Lev_Anal:-1:1
  291.                 dir = lower(str_dir_det(d,1));
  292.                 c   = detcoef2(dir,coefs,sizes,i);
  293.                 tmp = max(abs(c(:)));
  294.                 if tmp<eps , maxTHR(d,i) = 1; else , maxTHR(d,i) = 1.1*tmp; end
  295.             end
  296.         end
  297.         valTHR = min(maxTHR,valTHR);
  298.         % Displaying details coefficients histograms.
  299.         %--------------------------------------------
  300.         dirDef   = 1;
  301.         fontsize = wmachdep('fontsize','normal');
  302.         col_det  = wtbutils('colors','det',Lev_Anal);
  303.         nb_bins  = 50;
  304.         axeXColor = get(win_compress,'DefaultAxesXColor');        
  305.         for level = 1:Lev_Anal
  306.             for direct=1:3
  307.                 axeAct  = axe_hist(direct,level);
  308.                 axes(axeAct);
  309.                 dir        = lower(str_dir_det(direct,1));
  310.                 curr_img   = detcoef2(dir,coefs,sizes,level);
  311.                 curr_color = col_det(level,:);
  312.                 his        = wgethist(curr_img(:),nb_bins);
  313.                 his(2,:)   = his(2,:)/length(curr_img(:));
  314.                 hdl_hist   = wplothis(axeAct,his,curr_color);
  315.                 if direct==dirDef
  316.                     txt_hist(direct) = ...
  317.                     txtinaxe('create',['L_' sprintf('%.0f',level)],...
  318.                              axeAct,'left','on',...
  319.                              'bold',fontsize);
  320.                     set(txt_hist(direct),'color',axeXColor);
  321.                 end
  322.                 if level==1
  323.                     wxlabel([deblank(str_dir_det(direct,:)) ' Details'],...
  324.                             'color',axeXColor,...
  325.                             'Parent',axeAct);
  326.                 end
  327.                 thr_val = valTHR(direct,level);
  328.                 thr_max = maxTHR(direct,level);
  329.                 ylim    = get(axeAct,'Ylim');
  330.                 utthrw2d('plot_dec',win_compress,dirDef, ...
  331.                           {thr_max,thr_val,ylim,direct,level,axeAct})
  332.                 xmax = 1.1*max([thr_max, max(abs(his(1,:)))]);
  333.                 set(axeAct,'Xlim',[-xmax xmax]);
  334.                 set(findall(axeAct),'Visible','off');
  335.             end
  336.         end
  337.         % Initialization of Compression structure.
  338.         %----------------------------------------
  339.         utthrw2d('set',win_compress,'valthr',valTHR,'maxthr',maxTHR);
  340. % Add Context Sensitive Help (CSHelp).
  341. %-------------------------------------
  342. wfighelp('add_ContextMenu',win_compress,pop_mod,'DW2D_COMP_GUI');
  343. %-------------------------------------
  344.         % Memory blocks update.
  345.         %----------------------
  346.         utthrgbl('set',win_compress,'handleORI',hdl_datas(1));
  347.         utthrw2d('set',win_compress,'handleORI',hdl_datas(1));
  348.         wmemtool('ini',win_compress,n_misc_loc,nbLOC_1_stored);
  349.         wmemtool('wmb',win_compress,n_misc_loc,  ...
  350.                        ind_sav_menus,sav_menus,  ...
  351.                        ind_status,0,             ...
  352.                        ind_win_caller,win_caller,...
  353.                        ind_axe_datas,axe_datas,  ...
  354.                        ind_hdl_datas,hdl_datas,  ...
  355.                        ind_pop_mod,pop_mod       ...
  356.                        );
  357.         wmemtool('ini',win_compress,n_thrDATA,nbLOC_2_stored);
  358.         % Axes attachment.
  359.         %-----------------
  360.         axe_cmd = [axe_orig axe_comp];
  361.         axe_act = [];
  362.         dynvtool('init',win_compress,[],axe_cmd,axe_act,[1 1],'','','','int');
  363.         % Setting units to normalized.
  364.         %-----------------------------
  365.         wfigmngr('normalize',win_compress);
  366.         % End waiting.
  367.         %-------------
  368.         wwaiting('off',win_compress);
  369.        %%% PROVISOIRE BUG %%%%%%
  370.        % refresh(win_compress)
  371.        %%%%%%%%%%%%%%%%%%%%%%%%%
  372.     case 'compress'
  373.         % Waiting message.
  374.         %-----------------
  375.         wwaiting('msg',win_compress,'Wait ... computing');
  376.         % Clear & Get Handles.
  377.         %----------------------
  378.         dw2dcomp('clear_GRAPHICS',win_compress);
  379.         [win_caller,pop_mod]  = wmemtool('rmb',win_compress,n_misc_loc, ...
  380.                                                ind_win_caller,ind_pop_mod);
  381.         [axe_datas,hdl_datas] = wmemtool('rmb',win_compress,n_misc_loc, ...
  382.                                                ind_axe_datas,ind_hdl_datas);
  383.         axe_orig = axe_datas(1);
  384.         axe_comp = axe_datas(2);
  385.         % Getting  Analysis parameters.
  386.         %------------------------------
  387.         [Img_Size,Wav_Name,Lev_Anal] = ...
  388.          wmemtool('rmb',win_caller,n_param_anal, ...
  389.                         ind_img_size, ...
  390.                         ind_wav_name, ...
  391.                         ind_lev_anal  ...
  392.                         );
  393.         coefs   = wmemtool('rmb',win_caller,n_coefs,1);
  394.         sizes   = wmemtool('rmb',win_caller,n_sizes,1);
  395.         Wav_Fam = wavemngr('fam_num',Wav_Name);
  396.         isBior  = wavemngr('isbior',Wav_Fam);
  397.         % Compression.
  398.         %-------------
  399.         mode_val = get(pop_mod,'value');
  400.         switch mode_val
  401.           case 1
  402.             valTHR = utthrgbl('get',win_compress,'valthr');
  403.             thrParams = {'gbl',coefs,sizes,Wav_Name,Lev_Anal,valTHR,'h',1};
  404.           case 2
  405.             valTHR = utthrw2d('get',win_compress,'valthr');
  406.             thrParams = {'lvd',coefs,sizes,Wav_Name,Lev_Anal,valTHR,'h'};
  407.         end
  408.         [xc,cxc,lxc] = wdencmp(thrParams{:});
  409.         clear thrParams
  410.         switch mode_val
  411.           case 1 , [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  412.           case 2 , perf0 = 100*(length(find(cxc==0))/length(cxc));
  413.         end
  414.         if isBior
  415.             img_orig = hdl_datas(1);
  416.             Img_Anal = get(img_orig,'Cdata');
  417.             n_ori    = norm(Img_Anal);
  418.             perfl2   = 100; if n_ori>eps , perfl2 = 100*(norm(xc)/n_ori)^2; end
  419.         elseif mode_val==2
  420.             n_ori  = norm(coefs);
  421.             perfl2 = 100;
  422.             if n_ori>eps , perfl2 = 100*(norm(cxc)/n_ori)^2; end        
  423.         end 
  424.         if isBior , topTitle = 'Energy ratio ';
  425.         else      , topTitle = 'Retained energy ';
  426.         end
  427.         % Displaying compressed image.
  428.         %------------------------------
  429.         hdl_comp = hdl_datas(2);
  430.         if ishandle(hdl_comp)
  431.             set(hdl_comp,'Cdata',xc,'Visible','on');
  432.         else
  433.             hdl_comp = image([1 Img_Size(1)],[1,Img_Size(2)],xc,...
  434.                               'Parent',axe_comp);
  435.             hdl_datas(2) = hdl_comp;
  436.             utthrgbl('set',win_compress,'handleTHR',hdl_comp);
  437.             utthrw2d('set',win_compress,'handleTHR',hdl_comp);
  438.             wmemtool('wmb',win_compress,n_misc_loc,ind_hdl_datas,hdl_datas);
  439.         end
  440.         xylim = get(axe_orig,{'Xlim','Ylim'});
  441.         set(axe_comp,'Xlim',xylim{1},'Ylim',xylim{2},'Visible','on');
  442.         % Set a text as a super title.
  443.         %-----------------------------
  444.         wtitle('Compressed image','Parent',axe_comp)
  445.         txt_comp = [topTitle num2str(perfl2,'%5.2f') ...
  446.                           ' % -- Zeros ' num2str(perf0,'%5.2f') ' %'];
  447.         wtxttitl(axe_comp,txt_comp);
  448.         if mode_val==2
  449.             utthrw2d('set',win_compress,'perfos',{perfl2,perf0});
  450.         end 
  451.         % Memory blocks & HG update.
  452.         %---------------------------
  453.         switch mode_val
  454.           case 1
  455.             valTHR = utthrgbl('get',win_compress,'valthr');
  456.           case 2
  457.             valTHR = utthrw2d('get',win_compress,'valthr');
  458.         end
  459.         wmemtool('wmb',win_compress,n_thrDATA,ind_value,{xc,cxc,lxc,valTHR});
  460.         dw2dcomp('enable_menus',win_compress,'on');
  461.         % End waiting.
  462.         %-------------
  463.         wwaiting('off',win_compress);
  464.     case 'change_mode'
  465.         pop_mod = varargin{2}(1);
  466.         mod_val = get(pop_mod,'value');
  467.         old_mod = get(pop_mod,'userdata');
  468.         if isequal(mod_val,old_mod) , return; end
  469.         set(pop_mod,'userdata',mod_val);
  470.         dw2dcomp('clear_GRAPHICS',win_compress);
  471.         switch mod_val
  472.           case 1 , visGBL = 'on';  visLVL = 'off'; visMAP = 'on';
  473.           case 2
  474.             visGBL = 'off'; visLVL = 'on';  visMAP = 'on';
  475.             win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  476.             Lev_Anal = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  477.             if Lev_Anal>3 , visMAP = 'off'; else , visMAP = 'on'; end
  478.           
  479.         end
  480.         cbcolmap('visible',win_compress,visMAP);
  481.         utthrgbl('visible',win_compress,visGBL);
  482.         utthrw2d('visible',win_compress,visLVL);
  483.     case 'compute_GBL_THR'
  484.         win_caller = varargin{2};
  485.         [numMeth,meth,sliVal] = utthrgbl('get_GBL_par',win_compress);
  486.         coefs = wmemtool('rmb',win_caller,n_coefs,1);
  487.         sizes = wmemtool('rmb',win_caller,n_sizes,1);
  488.         thrFLAGS = 'dw2dcompGBL';
  489.         switch numMeth
  490.           case {1,3}
  491.             [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  492.                 wthrmngr(thrFLAGS,meth,coefs,sizes);
  493.             if nargout==1 , varargout = {valTHR};
  494.             else          , varargout = {valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR};
  495.             end
  496.           case 2
  497.             img = get(dw2drwcd('r_orig',win_caller),'Cdata');
  498.             valTHR = wthrmngr(thrFLAGS,meth,img);
  499.             maxTHR = max(coefs(:));
  500.             valTHR = min(valTHR,maxTHR);
  501.             varargout = {valTHR};
  502.         end
  503.     case 'update_GBL_meth'
  504.         dw2dcomp('clear_GRAPHICS',win_compress);
  505.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  506.         valTHR = dw2dcomp('compute_GBL_THR',win_compress,win_caller);
  507.         utthrgbl('update_GBL_meth',win_compress,valTHR);
  508.     case 'show_LVL_perfos'
  509.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  510.         coefs = wmemtool('rmb',win_caller,n_coefs,1);
  511.         sizes = wmemtool('rmb',win_caller,n_sizes,1);
  512.         lev_anal = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  513.         [numMeth,meth,scal,sorh] = utthrw2d('get_LVL_par',win_compress);
  514.         valTHR = utthrw2d('get',win_compress,'valTHR');
  515.         [perfl2,perf0] = wscrupd(coefs,sizes,lev_anal,valTHR,sorh);      
  516.         utthrw2d('set',win_compress,'perfos',{perfl2,perf0}); 
  517.     case 'compute_LVL_THR'
  518.         win_caller = varargin{2};
  519.         [numMeth,meth,alfa,sorh] = utthrw2d('get_LVL_par',win_compress);
  520.         coefs = wmemtool('rmb',win_caller,n_coefs,1);
  521.         sizes = wmemtool('rmb',win_caller,n_sizes,1);
  522.         level = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  523.         thrFLAGS = 'dw2dcompLVL';
  524.         switch numMeth
  525.           case {1,2,3,4,6} , valTHR = wthrmngr(thrFLAGS,meth,coefs,sizes,alfa);
  526.           case 5          
  527.             img = get(dw2drwcd('r_orig',win_caller),'Cdata');
  528.             valTHR = wthrmngr(thrFLAGS,meth,img,level);
  529.         end
  530.         [perfl2,perf0] = wscrupd(coefs,sizes,level,valTHR,sorh);
  531.         utthrw2d('set',win_compress,'perfos',{perfl2,perf0}); 
  532.         varargout = {valTHR,perfl2,perf0};
  533.     case 'update_LVL_meth'
  534.         dw2dcomp('clear_GRAPHICS',win_compress);
  535.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  536.         [valTHR,perfl2,perf0] = ...
  537.             dw2dcomp('compute_LVL_THR',win_compress,win_caller);
  538.         utthrw2d('update_LVL_meth',win_compress,valTHR);
  539.     case 'clear_GRAPHICS'
  540.         status = wmemtool('rmb',win_compress,n_misc_loc,ind_status);
  541.         if status == 0 , return; end
  542.  
  543.         % Diseable Toggles and Menus.
  544.         %----------------------------
  545.         dw2dcomp('enable_menus',win_compress,'off');
  546.         % Get Handles.
  547.         %-------------
  548.         axe_datas = wmemtool('rmb',win_compress,n_misc_loc,ind_axe_datas);
  549.         axe_comp = axe_datas(2);
  550.         % Setting compressed axes invisible.
  551.         %-----------------------------------
  552.         set(findobj(axe_comp),'visible','off');
  553.         drawnow
  554.     case 'enable_menus'
  555.         enaVal = varargin{2};
  556.         sav_menus = wmemtool('rmb',win_compress,n_misc_loc,ind_sav_menus);
  557.         set(sav_menus,'Enable',enaVal);
  558.         utthrgbl('enable_tog_res',win_compress,enaVal);
  559.         utthrw2d('enable_tog_res',win_compress,enaVal);
  560.         if strncmpi(enaVal,'on',2) , status = 1; else , status = 0; end
  561.         wmemtool('wmb',win_compress,n_misc_loc,ind_status,status);
  562.     case 'save_synt'
  563.         % Testing file.
  564.         %--------------
  565.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  566.                                      '*.mat','Save Compressed Image');
  567.         if ~ok, return; end
  568.         % Begin waiting.
  569.         %--------------
  570.         wwaiting('msg',win_compress,'Wait ... saving');
  571.         % Getting Analysis values.
  572.         %-------------------------
  573.         win_caller  = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  574.         wname = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  575.         map = cbcolmap('get',win_caller,'self_pal');
  576.         if isempty(map)
  577.             nb_colors = wmemtool('rmb',win_caller,n_param_anal,ind_nbcolors);
  578.             map = pink(nb_colors);
  579.         end
  580.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  581.         X = round(thrDATA{1});
  582.         valTHR = thrDATA{4};
  583.         % Saving file.
  584.         %--------------
  585.         [name,ext] = strtok(filename,'.');
  586.         if isempty(ext) | isequal(ext,'.')
  587.             ext = '.mat'; filename = [name ext];
  588.         end
  589.         saveStr = {'X','map','valTHR','wname'};
  590.         wwaiting('off',win_compress);
  591.         try
  592.           save([pathname filename],saveStr{:});
  593.         catch
  594.           errargt(mfilename,'Save FAILED !','msg');
  595.         end
  596.     case 'save_cfs'
  597.         % Testing file.
  598.         %--------------
  599.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  600.                                      '*.mat','Save Coefficients (2D)');
  601.         if ~ok, return; end
  602.         % Begin waiting.
  603.         %--------------
  604.         wwaiting('msg',win_compress,'Wait ... saving coefficients');
  605.         % Getting Analysis values.
  606.         %-------------------------
  607.         win_caller  = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  608.         wname = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  609.         map = cbcolmap('get',win_caller,'self_pal');
  610.         if isempty(map)
  611.             nb_colors = wmemtool('rmb',win_caller,n_param_anal,ind_nbcolors);
  612.             map = pink(nb_colors);
  613.         end
  614.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  615.         coefs = thrDATA{2};
  616.         sizes = thrDATA{3};
  617.         valTHR = thrDATA{4};
  618.         % Saving file.
  619.         %--------------
  620.         [name,ext] = strtok(filename,'.');
  621.         if isempty(ext) | isequal(ext,'.')
  622.             ext = '.mat'; filename = [name ext];
  623.         end
  624.         saveStr = {'coefs','sizes','map','valTHR','wname'};
  625.         wwaiting('off',win_compress);
  626.         try
  627.           save([pathname filename],saveStr{:});
  628.         catch
  629.           errargt(mfilename,'Save FAILED !','msg');
  630.         end
  631.     case 'save_dec'
  632.         % Testing file.
  633.         %--------------
  634.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  635.                                      '*.wa2','Save Wavelet Analysis (2D)');
  636.         if ~ok, return; end
  637.         % Begin waiting.
  638.         %--------------
  639.         wwaiting('msg',win_compress,'Wait ... saving decomposition');
  640.         % Getting Analysis values.
  641.         %-------------------------
  642.         win_caller  = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  643.         [wave_name,data_name,nb_colors] =    ...
  644.                 wmemtool('rmb',win_caller,n_param_anal, ...
  645.                                ind_wav_name, ...
  646.                                ind_img_name, ...
  647.                                ind_nbcolors  ...
  648.                                );
  649.         map = cbcolmap('get',win_caller,'self_pal');
  650.         if isempty(map) , map = pink(nb_colors); end
  651.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  652.         coefs = thrDATA{2};
  653.         sizes = thrDATA{3};
  654.         valTHR = thrDATA{4};
  655.         % Saving file.
  656.         %--------------
  657.         [name,ext] = strtok(filename,'.');
  658.         if isempty(ext) | isequal(ext,'.')
  659.             ext = '.wa2'; filename = [name ext];
  660.         end
  661.         saveStr = {'coefs','sizes','wave_name','map','valTHR','data_name'};
  662.         wwaiting('off',win_compress);
  663.         try
  664.           save([pathname filename],saveStr{:});
  665.         catch
  666.           errargt(mfilename,'Save FAILED !','msg');
  667.         end
  668.     case 'close'
  669.         [status,win_caller] = wmemtool('rmb',win_compress,n_misc_loc, ...
  670.                                              ind_status,ind_win_caller);
  671.         if status==1
  672.             % Test for Updating.
  673.             %--------------------
  674.             status = wwaitans(win_compress,...
  675.                               'Update the synthesized image ?',2,'cancel');
  676.         end
  677.         switch status
  678.             case 1
  679.               wwaiting('msg',win_compress,'Wait ... computing');
  680.               thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  681.               valTHR  = thrDATA{4};
  682.               wmemtool('wmb',win_caller,n_param_anal,ind_thr_val,valTHR);
  683.               hdl_datas = wmemtool('rmb',win_compress,n_misc_loc,ind_hdl_datas);
  684.               img_comp  = hdl_datas(2);
  685.               dw2dmngr('return_comp',win_caller,status,img_comp);
  686.               wwaiting('off',win_compress);
  687.             case 0 , dw2dmngr('return_comp',win_caller,status);
  688.         end
  689.         if nargout>0 , varargout{1} = status; end
  690.     otherwise
  691.         errargt(mfilename,'Unknown Option','msg');
  692.         error('*');
  693. end