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

波变换

开发平台:

Matlab

  1. function out1 = dw2dstat(option,in2,in3,in4,in5,in6)
  2. %DW2DSTAT Discrete wavelet 2-D statistics.
  3. %   OUT1 = DW2DSTAT(OPTION,IN2,IN3,IN4,IN5,IN6)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 18-Dec-2000.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.21 $
  8. % Memory Blocks of stored values.
  9. %================================
  10. % MB1.
  11. %-----
  12. n_param_anal   = 'DWAn2d_Par_Anal';
  13. ind_img_name   = 1;
  14. ind_wav_name   = 2;
  15. ind_lev_anal   = 3;
  16. ind_img_t_name = 4;
  17. ind_img_size   = 5;
  18. ind_nbcolors   = 6;
  19. ind_act_option = 7;
  20. ind_simg_type  = 8;
  21. ind_thr_val    = 9;
  22. nb1_stored     = 9;
  23. % MB2.1 & MB2.2
  24. %--------------
  25. n_coefs = 'MemCoefs';
  26. n_sizes = 'MemSizes';
  27. % MB3.
  28. %-----
  29. n_miscella     = 'DWStat2D_Misc';
  30. ind_curr_img   = 1;
  31. ind_curr_color = 2;
  32. nb3_stored     = 2;
  33. % Tag property of objects.
  34. %-------------------------
  35. tag_txt_ad   = 'Appdet_Txt';
  36. tag_pop_ad   = 'Appdet_Val';
  37. tag_pop_dir  = 'Detdir_Val';
  38. tag_sel_cfs  = 'Sel_Cfs';
  39. tag_sel_rec  = 'Sel_Rec';
  40. tag_ori_img  = 'Orig_img';
  41. tag_syn_img  = 'Synt_img';
  42. tag_app_img  = 'App_img';
  43. tag_det_img  = 'Det_img';
  44. tag_txt_bin  = 'Bins_Txt';
  45. tag_edi_bin  = 'Bins_Data';
  46. tag_levels   = 'Levels';
  47. tag_ax_image = 'Ax_Image';
  48. tag_ax_hist  = 'Ax_Hist';
  49. tag_ax_cumhist = 'Ax_Cumhist';
  50. tag_pus_sta  = 'Show_Stat';
  51. if ~isequal(option,'create') , win_stats = in2; end
  52. switch option
  53.     case 'create'
  54.         % Get Globals.
  55.         %--------------
  56.         [Def_Txt_Height,Def_Btn_Height,Def_Btn_Width,Pop_Min_Width, ...
  57.          X_Spacing,Y_Spacing,Def_EdiBkColor,Def_FraBkColor] = ...
  58.             mextglob('get',...
  59.                 'Def_Txt_Height','Def_Btn_Height','Def_Btn_Width', ...
  60.                 'Pop_Min_Width','X_Spacing','Y_Spacing', ...
  61.                 'Def_EdiBkColor','Def_FraBkColor' ...
  62.                 );
  63.         % Calling figure.
  64.         %----------------
  65.         win_dw2dtool = in2;
  66.         str_win_dw2dtool = sprintf('%.0f',win_dw2dtool);
  67.         % Window initialization.
  68.         %----------------------
  69.         win_name = 'Wavelet 2-D  --  Statistics';
  70.         [win_stats,pos_win,win_units,str_numwin,...
  71.                 frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  72.                     wfigmngr('create',win_name,'','ExtFig_HistStat',mfilename,0);
  73.         out1 = win_stats;
  74.         % Begin waiting.
  75.         %---------------
  76.         set(wfindobj('figure'),'Pointer','watch');
  77.         % Getting variables from dw2dtool figure memory block.
  78.         %-----------------------------------------------------
  79.         [Img_Name,Img_Size,NB_ColorsInPal,Wav_Name,Lev_Anal] = ...
  80.         wmemtool('rmb',win_dw2dtool,n_param_anal,...
  81.                        ind_img_name, ...
  82.                        ind_img_size, ...
  83.                        ind_nbcolors, ...
  84.                        ind_wav_name, ...
  85.                        ind_lev_anal  ...
  86.                        );
  87.         [Wav_Fam,Wav_Num] = wavemngr('fam_num',Wav_Name);
  88.         % General parameters initialization.
  89.         %-----------------------------------
  90.         dx = X_Spacing;  dx2 = 2*dx;
  91.         dy = Y_Spacing;  dy2 = 2*dy;
  92.         d_txt = (Def_Btn_Height-Def_Txt_Height);
  93.         gra_width  = Pos_Graphic_Area(3);
  94.         x_frame0   = pos_frame0(1);
  95.         cmd_width  = pos_frame0(3);
  96.         push_width = (cmd_width-4*dx)/2;
  97.         txt_width  = Def_Btn_Width;
  98.         pop_width  = Pop_Min_Width;
  99.         default_bins = 50;
  100.         % Position property of objects.
  101.         %------------------------------
  102.         [chk_heigth,dy_chk] = depOfMachine(Def_Btn_Height);
  103.         xlocINI      = [x_frame0 cmd_width];
  104.         ybottomINI   = pos_win(4)-3.5*Def_Btn_Height-dy2;
  105.         y_low        = ybottomINI-Def_Btn_Height-10*dy;
  106.         wx           = 7*push_width/4;
  107.         px           = x_frame0+(cmd_width-wx)/2;
  108.         pos_ori_img  = [px, y_low, wx, chk_heigth];
  109.         y_low        = pos_ori_img(2)-chk_heigth-dy_chk;
  110.         pos_syn_img = [px, y_low, wx, chk_heigth];
  111.         y_low        = pos_syn_img(2)-chk_heigth-dy_chk;
  112.         pos_app_img  = [px, y_low, wx, chk_heigth];
  113.         y_low        = pos_app_img(2)-chk_heigth-dy_chk;
  114.         pos_det_img  = [px, y_low, wx, chk_heigth];
  115.         wx             = 3*push_width/2;
  116.         px             = x_frame0+(cmd_width-wx)/2;
  117.         y_low          = pos_det_img(2)-3*Def_Btn_Height/2;
  118.         pos_txt_ad = [px, y_low+d_txt/2, wx, Def_Txt_Height];
  119.         y_low          = y_low-Def_Btn_Height;
  120.         pos_pop_ad = [px, y_low, wx, Def_Btn_Height];
  121.         y_low          = y_low-3*Def_Btn_Height/2;
  122.         pos_pop_dir = [px, y_low, wx, Def_Btn_Height];
  123.         wx            = 5*push_width/4;
  124.         px            = x_frame0+(cmd_width-wx)/2;
  125.         y_low         = pos_pop_dir(2)-2*Def_Btn_Height;
  126.         pos_sel_cfs   = [px, y_low, wx, Def_Btn_Height];
  127.         y_low         = pos_sel_cfs(2)-3*Def_Btn_Height/2;
  128.         pos_sel_rec   = [px, y_low, wx, Def_Btn_Height];
  129.         px            = x_frame0+(cmd_width-3*pop_width)/2;
  130.         y_low         = pos_sel_rec(2)-2*Def_Btn_Height;
  131.         pos_txt_bin  = [px, y_low+d_txt/2, 2*pop_width, Def_Txt_Height];
  132.         px            = pos_txt_bin(1)+pos_txt_bin(3)+dx;
  133.         pos_edi_bin = [px, y_low, pop_width, Def_Btn_Height];
  134.         px            = x_frame0+(cmd_width-3*push_width/2)/2;
  135.         y_low         = pos_edi_bin(2)-3*Def_Btn_Height;
  136.         pos_pus_sta = [px, y_low, 3*push_width/2, 2*Def_Btn_Height];
  137.         % String property of objects.
  138.         %----------------------------
  139.         s_i = wmemtool('rmb',win_dw2dtool,n_param_anal,ind_simg_type);
  140.         if      s_i=='ss', str_ss = 'Synthesized image';
  141.         elseif  s_i=='ds', str_ss = 'De_noised image';
  142.         elseif  s_i=='cs', str_ss = 'Compressed image';
  143.         end
  144.         str_syn_img     = str_ss;
  145.         str_ori_img     = 'Original image';
  146.         str_app_img     = 'Approximation';
  147.         str_det_img     = 'Detail';
  148.         str_app_txt     = 'Approximation at';
  149.         str_det_txt     = 'Detail at';
  150.         str_pop_dir  = [ 'Horizontal' ; 'Vertical  ' ; 'Diagonal  '];
  151.         str_sel_cfs     = 'Coefficients';
  152.         str_sel_rec     = 'Reconstructed';
  153.         str_txt_bin    = 'Number of bins';
  154.         str_edi_bin   = sprintf('%.0f',default_bins);
  155.         str_pus_sta   = 'Show statistics';
  156.         str_pop_ad  = [];
  157.         for i = 1:Lev_Anal
  158.             str_pop_ad  = [str_pop_ad ; sprintf('Level %2.0f', i)];
  159.         end
  160.         % Command part construction of the window.
  161.         %-----------------------------------------
  162.         utanapar('create_copy',win_stats, ...
  163.                  {'xloc',xlocINI,'bottom',ybottomINI},...
  164.                  {'n_s',{Img_Name,Img_Size},'wav',Wav_Name,'lev',Lev_Anal} ...
  165.                  );
  166.         commonProp = {'Parent',win_stats,'Unit',win_units};
  167.         comRadProp = {commonProp{:},'Style','Radiobutton','Enable','off'};
  168.         rad_ori_img = uicontrol(comRadProp{:}, ...
  169.                          'Position',pos_ori_img,...
  170.                          'String',str_ori_img,...
  171.                          'Value',1,...
  172.                          'Userdata',1,...
  173.                          'Tag',tag_ori_img...
  174.                          );
  175.         rad_syn_img = uicontrol(comRadProp{:}, ...
  176.                          'Position',pos_syn_img,...
  177.                          'String',str_syn_img,...
  178.                          'Tag',tag_syn_img...
  179.                          );
  180.         rad_app_img = uicontrol(comRadProp{:}, ...
  181.                         'Position',pos_app_img,...
  182.                         'String',str_app_img,...
  183.                         'Tag',tag_app_img...
  184.                         );
  185.        rad_det_img = uicontrol(comRadProp{:}, ...
  186.                         'Position',pos_det_img,...
  187.                         'String',str_det_img,...
  188.                         'Tag',tag_det_img...
  189.                         );
  190.         txt_txt_ad  = uicontrol(commonProp{:},...
  191.                                     'Style','Text',...
  192.                                     'Position',pos_txt_ad,...
  193.                                     'String',str_app_txt,...
  194.                                     'Visible','off',...
  195.                                     'Tag',tag_txt_ad,...
  196.                                     'Backgroundcolor',Def_FraBkColor...
  197.                                     );
  198.         pop_ad      = uicontrol(commonProp{:},...
  199.                                     'Style','Popup',...
  200.                                     'Position',pos_pop_ad,...
  201.                                     'String',str_pop_ad,...
  202.                                     'Visible','off',...
  203.                                     'Userdata',1,...
  204.                                     'Tag',tag_pop_ad...
  205.                                     );
  206.         pop_dir     = uicontrol(commonProp{:},...
  207.                                     'Style','Popup',...
  208.                                     'Position',pos_pop_dir,...
  209.                                     'String',str_pop_dir,...
  210.                                     'Visible','off',...
  211.                                     'Userdata',1,...
  212.                                     'Tag',tag_pop_dir...
  213.                                     );
  214.         rad_sel_cfs = uicontrol(commonProp{:},...
  215.                                 'Style','Radiobutton',...
  216.                                 'Position',pos_sel_cfs,...
  217.                                 'String',str_sel_cfs,...
  218.                                 'Visible','off',...
  219.                                 'Tag',tag_sel_cfs,...
  220.                                 'Userdata',0,...
  221.                                 'Value',0);
  222.         rad_sel_rec = uicontrol(commonProp{:},...
  223.                                 'Style','Radiobutton',...
  224.                                 'Position',pos_sel_rec,...
  225.                                 'String',str_sel_rec,...
  226.                                 'Visible','off',...
  227.                                 'Tag',tag_sel_rec,...
  228.                                 'Userdata',1,...
  229.                                 'Value',1);
  230.         txt_bin     = uicontrol(commonProp{:},...
  231.                                 'Style','text',...
  232.                                 'Position',pos_txt_bin,...
  233.                                 'String',str_txt_bin,...
  234.                                 'Backgroundcolor',Def_FraBkColor,...
  235.                                 'Visible','off',...
  236.                                 'Tag',tag_txt_bin...
  237.                                 );
  238.         edi_bin   = uicontrol(commonProp{:},...
  239.                                     'Style','Edit',...
  240.                                     'Position',pos_edi_bin,...
  241.                                     'String',str_edi_bin,...
  242.                                     'Backgroundcolor',Def_EdiBkColor,...
  243.                                     'Visible','off',...
  244.                                     'Tag',tag_edi_bin...
  245.                                     );
  246.         pus_sta   = uicontrol(commonProp{:},...
  247.                                     'Style','Pushbutton',...
  248.                                     'Position',pos_pus_sta,...
  249.                                     'String',xlate(str_pus_sta),...
  250.                                     'Visible','off',...
  251.                                     'Tag',tag_pus_sta...
  252.                                     );
  253.         coeff_vari_pos = 2;
  254.         pos_txt_bin(2) = pos_det_img(2)-coeff_vari_pos*Def_Btn_Height;
  255.         pos_edi_bin(2)= pos_txt_bin(2);
  256.         pos_pus_sta(2)= pos_edi_bin(2)-3*Def_Btn_Height;
  257.         set(txt_bin,'Position',pos_txt_bin,'Visible','on');
  258.         set(edi_bin,'Position',pos_edi_bin,'Visible','on');
  259.         set(pus_sta,'Position',pos_pus_sta,'Visible','on');
  260.         % Frame Stats. construction.
  261.         %---------------------------
  262.         [infos_hdls,h_frame1] = utstats('create',win_stats,...
  263.                                         'xloc',Pos_Graphic_Area([1,3]), ...
  264.                                         'bottom',dy2);
  265.         % Group handles.
  266.         %---------------
  267.         set1_hdls = [txt_txt_ad;pop_ad;pop_dir;rad_sel_cfs;rad_sel_rec];
  268.         set2_hdls = [txt_bin;edi_bin;pus_sta];
  269.         % Selected box limits.
  270.         %---------------------
  271.         Axe_Ref = findobj(get(win_dw2dtool,'Children'),'flat','Type','axes');
  272.         Axe_Ref = findobj(Axe_Ref,'Tag','Axe_ImgIni');
  273.         [xlim_selbox ylim_selbox]= mngmbtn('getbox',win_dw2dtool); 
  274.         if ~isempty(xlim_selbox)
  275.             xlim_selbox = [min(xlim_selbox) max(xlim_selbox)];
  276.         else
  277.             xlim_selbox = get(Axe_Ref,'XLim');
  278.         end
  279.         if ~isempty(ylim_selbox)
  280.             ylim_selbox = [min(ylim_selbox) max(ylim_selbox)];
  281.         else
  282.             ylim_selbox = get(Axe_Ref,'YLim');
  283.         end
  284.         xlim_selbox = round(xlim_selbox);
  285.         ylim_selbox = round(ylim_selbox);
  286.         xlim1       = xlim_selbox(1);
  287.         xlim2       = xlim_selbox(2);
  288.         ylim1       = ylim_selbox(1);
  289.         ylim2       = ylim_selbox(2);
  290.         if xlim1<1,                xlim1 = 1;           end
  291.         if xlim2>Img_Size(1),      xlim2 = Img_Size(1); end
  292.         if (xlim2<1) | (xlim1>Img_Size(1)), return,     end
  293.         if ylim1<1,                ylim1 = 1;           end
  294.         if ylim2>Img_Size(2),      ylim2 = Img_Size(2); end
  295.         if (ylim2<1) | (ylim1>Img_Size(2)), return,     end
  296.         selbox = [xlim1 xlim2 ylim1 ylim2];
  297.         % Callbacks update.
  298.         %------------------
  299.         str_infos_hdls  = num2mstr(infos_hdls);
  300.         str_group_hdls  = num2mstr([set2_hdls;set1_hdls]);
  301.         str_set2_hdls   = num2mstr(set2_hdls);
  302.         str_rad_ori_img = num2mstr(rad_ori_img);
  303.         str_rad_syn_img = num2mstr(rad_syn_img);
  304.         str_rad_app_img = num2mstr(rad_app_img);
  305.         str_rad_det_img = num2mstr(rad_det_img);
  306.         str_pop_ad      = num2mstr(pop_ad);
  307.         str_pop_dir     = num2mstr(pop_dir);
  308.         str_rad_sel_rec = num2mstr(rad_sel_rec);
  309.         str_rad_sel_cfs = num2mstr(rad_sel_cfs);
  310.         str_edi_bin = num2mstr(edi_bin);
  311.         str_selbox  = num2mstr(selbox);
  312.         cba_ori_img = [mfilename '(''select'',' ...
  313.                             str_numwin ','      ...
  314.                             str_rad_ori_img ',' ...
  315.                             str_infos_hdls ','  ...
  316.                             str_group_hdls ','  ...
  317.                             str_set2_hdls       ...
  318.                             ');'];
  319.         cba_syn_img = [mfilename '(''select'',' ...
  320.                             str_numwin ','      ...
  321.                             str_rad_syn_img ',' ...
  322.                             str_infos_hdls ','  ...
  323.                             str_group_hdls ','  ...
  324.                             str_set2_hdls       ...
  325.                             ');'];
  326.         cba_app_img = [mfilename '(''select'',' ...
  327.                             str_numwin ','      ...
  328.                             str_rad_app_img ',' ...
  329.                             str_infos_hdls ','  ...
  330.                             str_group_hdls ','  ...
  331.                             str_group_hdls      ...
  332.                             ');'];
  333.         cba_det_img = [mfilename '(''select'',' ...
  334.                             str_numwin ','      ...
  335.                             str_rad_det_img ',' ...
  336.                             str_infos_hdls ','  ...
  337.                             str_group_hdls ','  ...
  338.                             str_group_hdls      ...
  339.                             ');'];
  340.         cba_pop_ad = [mfilename '(''upd'','    ...
  341.                             str_numwin ',''lvl'',' ...
  342.                             str_infos_hdls ',' ...
  343.                             str_pop_ad         ...
  344.                             ');'];
  345.         cba_pop_dir = [mfilename '(''upd'','   ...
  346.                             str_numwin ',''lvl'',' ...
  347.                             str_infos_hdls ',' ...
  348.                             str_pop_dir        ...
  349.                             ');'];
  350.         cba_sel_rec = [mfilename '(''upd'','   ...
  351.                             str_numwin ',''cfs'',' ...
  352.                             str_infos_hdls ',' ...
  353.                             str_rad_sel_rec    ...
  354.                             ');'];
  355.         cba_sel_cfs = [mfilename '(''upd'','   ...
  356.                             str_numwin ',''cfs'',' ...
  357.                             str_infos_hdls ',' ...
  358.                             str_rad_sel_cfs    ...
  359.                             ');'];
  360.         cba_edi_bin = [mfilename '(''update_bins'',' ...
  361.                             str_numwin ','  ...
  362.                             str_edi_bin ',' ...
  363.                             str_infos_hdls  ...
  364.                             ');'];
  365.         cba_pus_sta = [mfilename '(''draw'',' ...
  366.                             str_numwin ','    ...
  367.                             str_win_dw2dtool ',' ...
  368.                             str_infos_hdls ',' ...
  369.                             str_selbox ...
  370.                             ');'];
  371.         set(rad_ori_img,'Callback',cba_ori_img);
  372.         set(rad_syn_img,'Callback',cba_syn_img);
  373.         set(rad_app_img,'Callback',cba_app_img);
  374.         set(rad_det_img,'Callback',cba_det_img);
  375.         set(pop_ad,'Callback',cba_pop_ad);
  376.         set(pop_dir,'Callback',cba_pop_dir);
  377.         set(rad_sel_rec,'Callback',cba_sel_rec);
  378.         set(rad_sel_cfs,'Callback',cba_sel_cfs);
  379.         set(edi_bin,'Callback',cba_edi_bin);
  380.         set(pus_sta,'Callback',cba_pus_sta);
  381.         % Axes construction.
  382.         %-------------------
  383.         xspace          = gra_width/10;
  384.         yspace          = pos_frame0(4)/10;
  385.         axe_height      = (pos_frame0(4)-Def_Btn_Height-h_frame1-4*dy)/2-yspace;
  386.         axe_width       = gra_width-2*xspace;
  387.         half_width      = axe_width/2-xspace/2;
  388.         cx              = xspace+axe_width/2;
  389.         cy              = h_frame1+2*dy2+axe_height+4*yspace/3+axe_height/2;
  390.         [w_used,h_used] = wpropimg(Img_Size,axe_width,axe_height,'pixels');
  391.         pos_ax_image    = [cx-w_used/2,cy-h_used/2,w_used,h_used];
  392.         pos_ax_hist     = [xspace h_frame1+2*dy2+yspace/3 ...
  393.                                  half_width axe_height];
  394.         pos_ax_cumhist  = [2*xspace+half_width h_frame1+2*dy2+yspace/3 ...
  395.                                  half_width axe_height];
  396.         commonProp = {...
  397.              'Parent',win_stats,...
  398.              'Unit',win_units,...
  399.              'Visible','Off',...
  400.              'box','on',...
  401.              'NextPlot','Replace',...
  402.              'Drawmode','fast' ...
  403.              };
  404.         locProp = {commonProp{:}, ...
  405.                      'Position',pos_ax_image,'Tag',tag_ax_image};
  406.         axe_image = axes(locProp{:});
  407.         locProp = {commonProp{:}, ...
  408.                      'Position',pos_ax_hist,'Tag',tag_ax_hist};
  409.         axe_hist  = axes(locProp{:});
  410.         locProp = {commonProp{:}, ...
  411.                      'Position',pos_ax_cumhist,'Tag',tag_ax_cumhist};
  412.         axe_cumhist  = axes(locProp{:});
  413.         drawnow
  414.         % Displaying the window title.
  415.         %-----------------------------
  416.         str_nb_val   = [' (' sprintf('%.0f',Img_Size(1)) ' x ' sprintf('%.0f',Img_Size(2)) ')'];
  417.         str_wintitle = [Img_Name,str_nb_val,' analyzed at level ',...
  418.                         sprintf('%.0f',Lev_Anal),' with ',Wav_Name];
  419.         str_wintitle = [str_wintitle '  --->  X = ' ,...
  420.                         sprintf('%.0f',selbox(1)) ' : ' ...
  421.                         sprintf('%.0f',selbox(2)) '    Y = ' ...
  422.                         sprintf('%.0f',selbox(3)) ' : ' ...
  423.                         sprintf('%.0f',selbox(4))];
  424.         wfigtitl('string',win_stats,str_wintitle,'off');
  425.         % Setting units to normalized.
  426.         %-----------------------------
  427.         wfigmngr('normalize',win_stats);
  428. % Initialization with signal statistics (31/08/2000).
  429. %----------------------------------------------------
  430.         dw2dstat('draw',win_stats,win_dw2dtool,infos_hdls,selbox);
  431. % End waiting.
  432.         %-------------
  433.         set(wfindobj('figure'),'Pointer','arrow');
  434.         set([rad_ori_img rad_syn_img rad_app_img rad_det_img],'Enable','on');
  435.     case 'select'
  436.         %***********************************************%
  437.         %** OPTION = 'select' - SIGNAL TYPE SELECTION **%
  438.         %***********************************************%
  439.         sel_rad_btn = in3;
  440.         infos_hdls  = in4;
  441.         group_hdls  = in5;
  442.         curr_hdls   = in6;
  443.         % Get Globals.
  444.         %--------------
  445.         Def_Btn_Height = mextglob('get','Def_Btn_Height');
  446.         % Set to the current selection.
  447.         %------------------------------
  448.         rad_handles = findobj(win_stats,'Style','radiobutton');
  449.         rad_ori_img = findobj(rad_handles,'Tag',tag_ori_img);
  450.         rad_syn_img = findobj(rad_handles,'Tag',tag_syn_img);
  451.         rad_app_img = findobj(rad_handles,'Tag',tag_app_img);
  452.         rad_det_img = findobj(rad_handles,'Tag',tag_det_img);
  453.         rad_opt     = [rad_ori_img rad_syn_img rad_app_img rad_det_img];
  454.         old_rad = findobj(rad_opt,'Userdata',1);
  455.         set(rad_opt,'Value',0,'Userdata',[]);
  456.         set(sel_rad_btn,'Value',1,'Userdata',1)
  457.         if old_rad==sel_rad_btn , return; end
  458.         % Reset all.
  459.         %-----------
  460.         set(infos_hdls,'Visible','off');
  461.         set(group_hdls,'Visible','off');
  462.         axe_handles = findobj(get(win_stats,'Children'),'flat','Type','axes');
  463.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  464.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  465.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  466.         set(findobj([axe_image axe_hist axe_cumhist]),'visible','off');
  467.         drawnow
  468.         % Redraw the command part depending on the current selection.
  469.         %------------------------------------------------------------
  470.         pos_det_img = get(rad_det_img,'Position');
  471.         pos_txt_bin = get(curr_hdls(1),'Position');
  472.         pos_edi_bin = get(curr_hdls(2),'Position');
  473.         pos_pus_sta = get(curr_hdls(3),'Position');
  474.         coeff_vari_pos = 10;
  475.         [nul,ypixl] = wfigutil('prop_size',win_stats,0,1);
  476.         deltay      = Def_Btn_Height*ypixl;
  477.         if sel_rad_btn==rad_ori_img | sel_rad_btn==rad_syn_img
  478.             coeff_vari_pos = 2;
  479.         end
  480.         pos_txt_bin(2) = pos_det_img(2)-coeff_vari_pos*deltay;
  481.         pos_edi_bin(2)= pos_txt_bin(2);
  482.         pos_pus_sta(2)= pos_edi_bin(2)-3*deltay;
  483.         set(curr_hdls(1),'Position',pos_txt_bin);
  484.         set(curr_hdls(2),'Position',pos_edi_bin);
  485.         set(curr_hdls(3),'Position',pos_pus_sta);
  486.         set(curr_hdls,'Visible','On');
  487.         if sel_rad_btn==rad_app_img
  488.               set(curr_hdls(4),'String',xlate('Approximation at'))
  489.               set(curr_hdls(6),'Visible','off')
  490.         elseif sel_rad_btn==rad_det_img
  491.               set(curr_hdls(4),'String',xlate('Detail at'))
  492.               set(curr_hdls(6),'Visible','on')
  493.         end
  494.     case 'upd'
  495.         %***************************************%
  496.         %** OPTION = 'upd' - UPDATE :         **%
  497.         %**     COEFFICIENTS TYPE SELECTION   **%
  498.         %**     LEVEL NUMBER SELECTION        **%
  499.         %**     LEVEL DIRECTION SELECTION     **%
  500.         %***************************************%
  501.         opt        = in3;
  502.         infos_hdls = in4;
  503.         % Set to the current selection.
  504.         %------------------------------
  505.         switch opt
  506.             case 'cfs'
  507.                 sel_rad_btn = in5;
  508.                 rad_handles = findobj(win_stats,'Style','radiobutton');
  509.                 rad_sel_rec = findobj(rad_handles,'Tag',tag_sel_rec);
  510.                 rad_sel_cfs = findobj(rad_handles,'Tag',tag_sel_cfs);
  511.                 rad_opt     = [rad_sel_rec rad_sel_cfs];
  512.                 old_rad     = findobj(rad_opt,'Userdata',1);
  513.                 set(rad_opt,'Value',0,'Userdata',0);
  514.                 set(sel_rad_btn,'Value',1,'Userdata',1)
  515.                 if old_rad==sel_rad_btn , return; end
  516.             case 'lvl'
  517.                 pop_level = in5;
  518.                 val_pop = get(pop_level,'value');
  519.                 usr_pop = get(pop_level,'userdata');
  520.                 if usr_pop==val_pop , return; end
  521.                 set(pop_level,'userdata',val_pop);
  522.             case 'dir'
  523.                 pop_dir = in5;
  524.                 val_pop = get(pop_dir,'value');
  525.                 usr_pop = get(pop_dir,'userdata');
  526.                 if usr_pop==val_pop , return; end
  527.                 set(pop_dir,'userdata',val_pop);
  528.         end
  529.         % Reset all.
  530.         %-----------
  531.         set(infos_hdls,'Visible','off');
  532.         axe_handles = findobj(get(win_stats,'Children'),'flat','Type','axes');
  533.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  534.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  535.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  536.         set(findobj([axe_image axe_hist axe_cumhist]),'visible','off');
  537.         drawnow
  538.     case 'lvl'
  539.         %*********************************************%
  540.         %** OPTION = 'lvl' - LEVEL NUMBER SELECTION **%
  541.         %*********************************************%
  542.         pop_level  = in3;
  543.         infos_hdls = in4;
  544.         % Set to the current selection.
  545.         %------------------------------
  546.         val_pop = get(pop_level,'value');
  547.         usr_pop = get(pop_level,'userdata');
  548.         if usr_pop==val_pop , return; end
  549.         set(pop_level,'userdata',val_pop);
  550.         % Reset all.
  551.         %-----------
  552.         set(infos_hdls,'Visible','off');
  553.         axe_handles = findobj(get(win_stats,'Children'),'flat','Type','axes');
  554.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  555.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  556.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  557.         set(findobj([axe_image axe_hist axe_cumhist]),'visible','off');
  558.         drawnow
  559.     case 'draw'
  560.         %**********************************************%
  561.         %** OPTION = 'draw' - DRAW AXES              **%
  562.         %**********************************************%
  563.         win_dw2dtool = in3;
  564.         infos_hdls   = in4;
  565.         selbox       = in5;
  566.         % Handles of tagged objects.
  567.         %---------------------------
  568.         children    = get(win_stats,'Children');
  569.         uic_handles = findobj(children,'flat','type','uicontrol');
  570.         axe_handles = findobj(children,'flat','type','axes');
  571.         rad_handles = findobj(uic_handles,'Style','radiobutton');
  572.         edi_handles = findobj(uic_handles,'Style','edit');
  573.         txt_handles = findobj(uic_handles,'Style','text');
  574.         pop_handles = findobj(uic_handles,'Style','popupmenu');
  575.         pus_sta = findobj(uic_handles,'Style','pushbutton','Tag',tag_pus_sta);
  576.         rad_sel_cfs = findobj(rad_handles,'Tag',tag_sel_cfs);
  577.         rad_ori_img = findobj(rad_handles,'Tag',tag_ori_img);
  578.         rad_syn_img = findobj(rad_handles,'Tag',tag_syn_img);
  579.         rad_app_img = findobj(rad_handles,'Tag',tag_app_img);
  580.         rad_det_img = findobj(rad_handles,'Tag',tag_det_img);
  581.         edi_bin = findobj(edi_handles,'Tag',tag_edi_bin);
  582.         pop_ad  = findobj(pop_handles,'Tag',tag_pop_ad);
  583.         pop_dir = findobj(pop_handles,'Tag',tag_pop_dir);
  584.         % Handles of tagged objects continuing.
  585.         %-------------------------------------
  586.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  587.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  588.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  589.         % Main parameters selection before drawing.
  590.         %------------------------------------------
  591.         sel_cfs  = (get(rad_sel_cfs,'Value')~=0);
  592.         orig_img = (get(rad_ori_img,'Value')~=0);
  593.         synt_img = (get(rad_syn_img,'Value')~=0);
  594.         app_img  = (get(rad_app_img,'Value')~=0);
  595.         det_img  = (get(rad_det_img,'Value')~=0);
  596.         % Check the bins number.
  597.         %-----------------------
  598.         default_bins = 50;
  599.         old_params   = get(pus_sta,'Userdata');
  600.         if ~isempty(old_params)
  601.             default_bins = old_params(1);
  602.         end
  603.         nb_bins = wstr2num(get(edi_bin,'String'));
  604.         if isempty(nb_bins) | (nb_bins<2)
  605.             nb_bins = default_bins;   
  606.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  607.         end
  608.         level     = get(pop_ad,'value');
  609.         direction = get(pop_dir,'value');
  610.         new_params = [nb_bins sel_cfs orig_img synt_img ...
  611.                       app_img det_img level direction   ...
  612.                       ];
  613.         if ~isempty(old_params) & (new_params==old_params)
  614.             vis = get(axe_hist,'Visible');
  615.             if vis(1:2)=='on', return, end
  616.         end
  617.         % Updating parameters.
  618.         %--------------------- 
  619.         set(pus_sta,'Userdata',new_params);
  620.         % Show the status line.
  621.         %----------------------
  622.         wfigtitl('vis',win_stats,'on');
  623.         % Cleaning the graphical part.
  624.         %-----------------------------
  625.         set(infos_hdls,'Visible','off');
  626.         % Waiting message.
  627.         %-----------------
  628.         wwaiting('msg',win_stats,'Wait ... computing');
  629.         % Cleaning the graphical part continuing.
  630.         %----------------------------------------
  631.         set(findobj([axe_image axe_hist axe_cumhist]),'visible','off');
  632.         drawnow
  633.         % Deseable new selection.
  634.         %-------------------------
  635.         pop_handles = cbanapar('no_pop',win_stats,pop_handles);
  636.         set([rad_handles;edi_bin],'Enable','off');
  637.         % Getting memory blocks.
  638.         %-----------------------
  639.         [Img_Name,NB_ColorsInPal,Wav_Name,Lev_Anal] = ...
  640.                  wmemtool('rmb',win_dw2dtool,n_param_anal,...
  641.                                 ind_img_name, ...
  642.                                 ind_nbcolors, ...
  643.                                 ind_wav_name, ...
  644.                                 ind_lev_anal  ...
  645.                                 );
  646.         coefs = wmemtool('rmb',win_dw2dtool,n_coefs,1);
  647.         sizes = wmemtool('rmb',win_dw2dtool,n_sizes,1);
  648. % Image Coding Value.
  649. %-------------------
  650. codemat_v = wimgcode('get',win_dw2dtool);
  651.         % Current image construction.
  652.         %----------------------------
  653.         if orig_img
  654.             curr_img   = get(dw2drwcd('r_orig',win_dw2dtool),'Cdata');
  655.             flg_code   = 0;
  656.             curr_color = wtbutils('colors','sig');
  657.             str_title  = 'Original image';
  658.         elseif synt_img
  659.             curr_img   = get(dw2drwcd('r_synt',win_dw2dtool),'Cdata');
  660.             flg_code   = 0;
  661.             curr_color = wtbutils('colors','ssig');
  662.             s_i = wmemtool('rmb',win_dw2dtool,n_param_anal,ind_simg_type);
  663.             if     s_i=='ss', str_ss = 'Synthesized image';
  664.             elseif s_i=='ds', str_ss = 'De_noised image';
  665.             elseif s_i=='cs', str_ss = 'Compressed image';
  666.             end
  667.             str_title = str_ss;
  668.         elseif app_img
  669.             if sel_cfs
  670.                 curr_img = appcoef2(coefs,sizes,Wav_Name,level);
  671.                 flg_code = 1;
  672.                 str_title= sprintf('Coefficients of approximation at level ');
  673.             else
  674.                 curr_img = wrcoef2('a',coefs,sizes,Wav_Name,level);
  675.                 flg_code = 0;
  676.                 str_title= sprintf('Reconstructed approximation at level ');
  677.             end
  678.             col_app    = wtbutils('colors','app',Lev_Anal);
  679.             curr_color = col_app(level,:);
  680.             str_title  = [str_title, sprintf('%.0f',level)];
  681.         elseif det_img
  682.             switch direction
  683.               case 1 , dir = 'horizontal ';
  684.               case 2 , dir = 'vertical ';
  685.               case 3 , dir = 'diagonal ';
  686.             end
  687.             if sel_cfs
  688.                 curr_img = detcoef2(dir(1),coefs,sizes,level);
  689.                 flg_code = 1;
  690.                 str_title= sprintf('Coefficients of detail at level ');
  691.             else
  692.                 curr_img = wrcoef2(dir(1),coefs,sizes,Wav_Name,level);
  693.                 flg_code = 1;
  694.                 str_title= sprintf('Reconstructed detail at level ');
  695.             end
  696.             col_det    = wtbutils('colors','det',Lev_Anal);
  697.             curr_color = col_det(level,:);
  698.             str_title  = [str_title dir,sprintf('%.0f',level)];
  699.         end
  700.         if sel_cfs & ~orig_img & ~synt_img
  701.             selbox  = ceil(selbox./2^level);
  702.         end
  703.         if selbox(2)-selbox(1)<2 | selbox(4)-selbox(3)<2
  704.             wwarndlg([' Not enough coefficients ' ...
  705.                     'remaining at level ' ...
  706.                     sprintf('%.0f',level)],...
  707.                     'Wavelet 2-D -- Statistics','block');
  708.             set([pop_handles;rad_handles;edi_bin],'Enable','on');
  709.             wwaiting('off',win_stats);
  710.             return;
  711.         end
  712.         % Displaying the image.
  713.         %-----------------------
  714.         set(win_stats,'Colormap',get(win_dw2dtool,'Colormap'));
  715.         curr_img = curr_img(selbox(3):selbox(4),selbox(1):selbox(2));
  716.         axes(axe_image);
  717.         pos_ax_image    = get(axe_image,'Position');
  718.         pos3            = pos_ax_image(3);
  719.         pos_ax_image(3) = min((pos_ax_image(4)/(selbox(4)-selbox(3)+1))...
  720.                         *(selbox(2)-selbox(1)+1),pos3);
  721.         pos_ax_image(1) = pos_ax_image(1)+(pos3-pos_ax_image(3))/2;      
  722.         set(axe_image,'Position',pos_ax_image);
  723.         tag = get(axe_image,'Tag');
  724.         image([selbox(1) selbox(2)],[selbox(3) selbox(4)],...
  725.                 wimgcode('cod',flg_code,curr_img,NB_ColorsInPal,codemat_v),...
  726.                 'Parent',axe_image);
  727.         wtitle(str_title,'Parent',axe_image);
  728.         %%% BUG enable %%%
  729.         pause(0.1);
  730.         set(axe_image,'Visible','on','Tag',tag);
  731.         drawnow;
  732.         % Check the bins number.
  733.         %-----------------------
  734.         nb_bins = wstr2num(get(edi_bin,'String'));
  735.         if isempty(nb_bins) 
  736.             nb_bins = default_bins;   
  737.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  738.         elseif nb_bins<2
  739.             nb_bins = default_bins;
  740.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  741.         end
  742.         % Displaying histogram.
  743.         %----------------------
  744.         his       = wgethist(curr_img(:),nb_bins);
  745.         [xx,imod] = max(his(2,:));
  746.         mode_val  = (his(1,imod)+his(1,imod+1))/2;
  747.         his(2,:)  = his(2,:)/length(curr_img(:));
  748.         axes(axe_hist);
  749.         wplothis(axe_hist,his,curr_color);
  750.         wtitle('Histogram','Parent',axe_hist);
  751.         % Displaying cumulated histogram.
  752.         %--------------------------------
  753.         for i=6:4:length(his(2,:));
  754.             his(2,i)   = his(2,i)+his(2,i-4);
  755.             his(2,i+1) = his(2,i);
  756.         end
  757.         axes(axe_cumhist);
  758.         wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  759.         wtitle('Cumulative histogram','Parent',axe_cumhist);
  760.         drawnow;
  761.         % Displaying statistics.
  762.         %-----------------------
  763.         errtol    = 1.0E-12;
  764.         mean_val  = mean(mean(curr_img));
  765.         if abs(mean_val)<errtol , mean_val = 0; end
  766.         max_val   = max(max(curr_img));
  767.         if abs(max_val)<errtol , max_val = 0; end
  768.         min_val   = min(min(curr_img));
  769.         if abs(min_val)<errtol , min_val = 0; end
  770.         range_val = max_val-min_val;
  771.         if abs(range_val)<errtol , range_val = 0; end
  772.         std_val   = std(curr_img(:));
  773.         if abs(std_val)<errtol , std_val = 0; end
  774.         med_val   = median(curr_img(:));
  775.         if abs(med_val)<errtol , med_val = 0; end
  776.         utstats('display',win_stats, ...
  777.             [mean_val; med_val ; mode_val;  ...
  778.              max_val ; min_val ; range_val; ...
  779.              std_val ; median(abs(curr_img(:)-med_val)); ...
  780.              mean(abs(curr_img(:)-mean_val))]);
  781.         % Memory blocks update.
  782.         %----------------------
  783.         wmemtool('ini',win_stats,n_miscella,nb3_stored);
  784.         wmemtool('wmb',win_stats,n_miscella,  ...
  785.                        ind_curr_img,curr_img(:), ...
  786.                        ind_curr_color,curr_color ...
  787.                        );
  788.         % End waiting.
  789.         %-------------
  790.         wwaiting('off',win_stats);
  791.         % Setting infos visible.
  792.         %-----------------------
  793.         set(infos_hdls,'Visible','on');
  794.         % Enable new selection.
  795.         %----------------------
  796.         set([pop_handles;rad_handles;edi_bin],'Enable','on');
  797.     case 'update_bins'
  798.         %**************************************************************%
  799.         %** OPTION = 'update_bins' - UPDATE HISTOGRAMS WITH NEW BINS **%
  800.         %**************************************************************%
  801.         edi_bin    = in3;
  802.         infos_hdls = in4;
  803.         % Handles of tagged objects.
  804.         %---------------------------
  805.         children = get(win_stats,'Children');
  806.         pus_sta  = findobj(children,'Style','pushbutton','Tag',tag_pus_sta);
  807.         axe_handles = findobj(children,'flat','Type','axes');
  808.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  809.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  810.         % Return if no current display.
  811.         %------------------------------
  812.         vis = get(axe_hist,'Visible');
  813.         if vis(1:2)=='of', return, end
  814.         % Check the bins number.
  815.         %-----------------------
  816.         default_bins = 50;
  817.         old_params   = get(pus_sta,'Userdata');
  818.         if ~isempty(old_params)
  819.             default_bins = old_params(1);
  820.         end
  821.         nb_bins = wstr2num(get(edi_bin,'String'));
  822.         if isempty(nb_bins) | (nb_bins<2)
  823.             nb_bins = default_bins;   
  824.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  825.         end
  826.         if default_bins==nb_bins , return; end
  827.         % Waiting message.
  828.         %-----------------
  829.         set(infos_hdls,'Visible','off');
  830.         wwaiting('msg',win_stats,'Wait ... computing');
  831.         % Getting memory blocks.
  832.         %-----------------------
  833.         [curr_img,curr_color] = wmemtool('rmb',win_stats,n_miscella,...
  834.                                                ind_curr_img,...
  835.                                                ind_curr_color);
  836.         % Updating histograms.
  837.         %---------------------
  838.         if ~isempty(curr_img)
  839.             old_params(1) = nb_bins;
  840.             set(pus_sta,'Userdata',old_params);
  841.             his      = wgethist(curr_img,nb_bins);
  842.             his(2,:) = his(2,:)/length(curr_img);
  843.             axes(axe_hist);
  844.             wplothis(axe_hist,his,curr_color);
  845.             wtitle('Histogram','Parent',axe_hist);
  846.             for i=6:4:length(his(2,:));
  847.                 his(2,i)   = his(2,i)+his(2,i-4);
  848.                 his(2,i+1) = his(2,i);
  849.             end
  850.             axes(axe_cumhist);
  851.             wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  852.             wtitle('Cumulative histogram','Parent',axe_cumhist);
  853.         end
  854.         % End waiting.
  855.         %-------------
  856.         wwaiting('off',win_stats);
  857.         set(infos_hdls,'Visible','on');
  858.     case 'demo'
  859.         %****************************************%
  860.         %** OPTION = 'demo' -  DEMOS or TESTS  **%
  861.         %****************************************%
  862.         pus_sta = findobj(win_stats,'Style','pushbutton','Tag',tag_pus_sta);
  863.         eval(get(pus_sta,'Callback'));
  864.     case 'close'
  865.     otherwise
  866.         errargt(mfilename,'Unknown Option','msg');
  867.         error('*');
  868. end
  869. %-------------------------------------------------
  870. function varargout = depOfMachine(varargin)
  871. Def_Btn_Height = varargin{1};
  872. scrSize = get(0,'ScreenSize');
  873. if scrSize(4)<700
  874.     chk_heigth = Def_Btn_Height;
  875.     dy_chk     = Def_Btn_Height/2;
  876. else
  877.     chk_heigth = 3*Def_Btn_Height/2;
  878.     dy_chk     = Def_Btn_Height/2;
  879. end
  880. varargout = {chk_heigth,dy_chk};
  881. %-------------------------------------------------