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

波变换

开发平台:

Matlab

  1. function varargout = wp2dstat(option,varargin)
  2. %WP2DSTAT Wavelet packets 2-D statistics.
  3. %   VARARGOUT = WP2DSTAT(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 21-May-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.17.4.2 $
  8. % Memory Blocks of stored values.
  9. %================================
  10. % MB1.
  11. %-----
  12. n_param_anal   = 'WP2D_Par_Anal';
  13. ind_img_name   = 1;
  14. ind_wav_name   = 2;
  15. ind_lev_anal   = 3;
  16. ind_ent_anal   = 4;
  17. ind_ent_par    = 5;
  18. ind_img_size   = 6;
  19. ind_img_t_name = 7;
  20. ind_act_option = 8;
  21. ind_thr_val    = 9;
  22. nb1_stored     = 9;
  23. % MB2.
  24. %-----
  25. n_wp_utils = 'WP_Utils';
  26. ind_tree_lin  = 1;
  27. ind_tree_txt  = 2;
  28. ind_type_txt  = 3;
  29. ind_sel_nodes = 4;
  30. ind_gra_area  = 5;
  31. ind_nb_colors = 6;
  32. nb2_stored    = 6;
  33. % MB3.
  34. %-----
  35. n_structures = 'Structures';
  36. ind_tree_st  = 1;
  37. ind_data_st  = 2;
  38. nb3_stored   = 2;
  39. % MB1 (Local Bloc).
  40. %------------------
  41. n_misc_loc = 'WPStat2D_Misc';
  42. ind_curr_img   = 1;
  43. ind_curr_color = 2;
  44. nbLOC_1_stored = 2;
  45. % Tag property of objects.
  46. %-------------------------
  47. tag_sel_cfs    = 'Sel_Cfs';
  48. tag_sel_rec    = 'Sel_Rec';
  49. tag_txt_bin    = 'Bins_Txt';
  50. tag_edi_bin    = 'Bins_Data';
  51. tag_ax_image   = 'Ax_Image';
  52. tag_ax_hist    = 'Ax_Hist';
  53. tag_ax_cumhist = 'Ax_Cumhist';
  54. tag_pus_sta    = 'Show_Stat';
  55. if ~isequal(option,'create') , win_stats = varargin{1}; end
  56. switch option
  57.     case 'create'
  58.         % Get Globals.
  59.         %-------------
  60.         [Def_Txt_Height,Def_Btn_Height,Pop_Min_Width, ...
  61.          X_Spacing,Y_Spacing,Def_EdiBkColor,Def_FraBkColor] =  ...
  62.             mextglob('get',...
  63.                 'Def_Txt_Height','Def_Btn_Height','Pop_Min_Width', ...
  64.                 'X_Spacing','Y_Spacing', 'Def_EdiBkColor','Def_FraBkColor');
  65.         % Calling figure and node.
  66.         %-------------------------
  67.         win_caller     = varargin{1};
  68.         node           = varargin{2};
  69.         str_win_caller = sprintf('%.0f',win_caller);
  70.         str_node       = sprintf('%.0f',node);
  71.         % Window initialization.
  72.         %----------------------
  73.         win_name = 'Wavelet Packet 2-D  --  Statistics';
  74.         [win_stats,pos_win,win_units,str_numwin,...
  75.                 frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  76.                     wfigmngr('create',win_name,'','ExtFig_HistStat',mfilename,0);
  77.         if nargout>0 , varargout{1} = win_stats; end
  78.         % Begin waiting.
  79.         %---------------
  80.         set(wfindobj('figure'),'Pointer','watch');
  81.         % Getting variables from wp2dtool figure memory block.
  82.         %-----------------------------------------------------
  83.         WP_Tree = wmemtool('rmb',win_caller,n_structures,ind_tree_st);
  84.         depth   = treedpth(WP_Tree);
  85.         [Img_Name,Img_Size,Wave_Name,Ent_Nam,Ent_Par] =           ...
  86.                         wmemtool('rmb',win_caller,n_param_anal,   ...
  87.                                        ind_img_name,ind_img_size, ...
  88.                                        ind_wav_name,ind_ent_anal, ...
  89.                                        ind_ent_par);
  90.         Wav_Fam = wavemngr('fam_num',Wave_Name);
  91.         % General parameters initialization.
  92.         %-----------------------------------
  93.         dx = X_Spacing;
  94.         dy = Y_Spacing;  dy2 = 2*dy;
  95.         d_txt = Def_Btn_Height-Def_Txt_Height;
  96.         gra_width = Pos_Graphic_Area(3);
  97.         push_width = (pos_frame0(3)-4*dx)/2;
  98.         pop_width  = Pop_Min_Width;
  99.         default_bins = 50;
  100.         % Position property of objects.
  101.         %------------------------------
  102.         xlocINI     = pos_frame0([1 3]);
  103.         ybottomINI  = pos_win(4)-3.5*Def_Btn_Height-dy2;
  104.         ybottomENT  = ybottomINI-(Def_Btn_Height+dy2)-dy;
  105.         y_low       = ybottomENT-4*Def_Btn_Height;
  106.         px          = pos_frame0(1)+(pos_frame0(3)-5*push_width/4)/2;
  107.         pos_sel_cfs = [px, y_low, 5*push_width/4, 3*Def_Btn_Height/2];
  108.         y_low       = y_low-3*Def_Btn_Height;
  109.         pos_sel_rec = [px, y_low, 5*push_width/4, 3*Def_Btn_Height/2];
  110.         px          = pos_frame0(1)+(pos_frame0(3)-3*pop_width)/2;
  111.         y_low       = y_low-3*Def_Btn_Height;
  112.         pos_txt_bin = [px, y_low+d_txt/2, 2*pop_width, Def_Txt_Height];
  113.         px          = pos_txt_bin(1)+pos_txt_bin(3)+dx;
  114.         pos_edi_bin = [px, y_low, pop_width, Def_Btn_Height];
  115.         px          = pos_frame0(1)+(pos_frame0(3)-3*push_width/2)/2;
  116.         y_low       = pos_edi_bin(2)-3*Def_Btn_Height;
  117.         pos_pus_sta = [px, y_low, 3*push_width/2, 2*Def_Btn_Height];
  118.         % String property of objects.
  119.         %----------------------------
  120.         str_sel_cfs = 'Coefficients';
  121.         str_sel_rec = 'Reconstructed';
  122.         str_txt_bin = 'Number of bins';
  123.         str_edi_bin = sprintf('%.0f',default_bins);
  124.         str_pus_sta = 'Show statistics';
  125.         % Command part construction of the window.
  126.         %-----------------------------------------
  127.         utanapar('create_copy',win_stats, ...
  128.                  {'xloc',xlocINI,'bottom',ybottomINI},...
  129.                  {'n_s',{Img_Name,Img_Size},'wav',Wave_Name,'lev',depth} ...
  130.                  );
  131.         utentpar('create_copy',win_stats, ...
  132.                  {'xloc',xlocINI,'bottom',ybottomENT,...
  133.                   'ent',{Ent_Nam,Ent_Par}} ...
  134.                  );
  135.         rad_cfs = uicontrol('Parent',win_stats,...
  136.                             'Style','Radiobutton',...
  137.                             'Unit',win_units,...
  138.                             'Position',pos_sel_cfs,...
  139.                             'String',str_sel_cfs,...
  140.                             'Tag',tag_sel_cfs,...
  141.                             'Userdata',0,...
  142.                             'Value',0);
  143.         rad_rec = uicontrol('Parent',win_stats,...
  144.                             'Style','Radiobutton',...
  145.                             'Unit',win_units,...
  146.                             'Position',pos_sel_rec,...
  147.                             'String',str_sel_rec,...
  148.                             'Tag',tag_sel_rec,...
  149.                             'Userdata',1,...
  150.                             'Value',1);
  151.         txt_bin = uicontrol('Parent',win_stats,...
  152.                             'Style','text',...
  153.                             'Unit',win_units,...
  154.                             'Position',pos_txt_bin,...
  155.                             'String',str_txt_bin,...
  156.                             'Backgroundcolor',Def_FraBkColor,...
  157.                             'Tag',tag_txt_bin...
  158.                             );
  159.         edi_bin = uicontrol('Parent',win_stats,...
  160.                             'Style','Edit',...
  161.                             'Units',win_units,...
  162.                             'Position',pos_edi_bin,...
  163.                             'String',str_edi_bin,...
  164.                             'Backgroundcolor',Def_EdiBkColor,...
  165.                             'Tag',tag_edi_bin...
  166.                             );
  167.         pus_sta = uicontrol('Parent',win_stats,...
  168.                             'Style','Pushbutton',...
  169.                             'Unit',win_units,...
  170.                             'Position',pos_pus_sta,...
  171.                             'String',xlate(str_pus_sta),...
  172.                             'Userdata',[],...
  173.                             'Tag',tag_pus_sta...
  174.                             );
  175.         % Frame Stats. construction.
  176.         %---------------------------
  177.         [infos_hdls,h_frame1] = utstats('create',win_stats,...
  178.                                         'xloc',Pos_Graphic_Area([1,3]), ...
  179.                                         'bottom',dy2);
  180.         % Callbacks update.
  181.         %------------------
  182.         str_infos_hdls  = num2mstr(infos_hdls);
  183.         str_rad_rec = num2mstr(rad_rec);
  184.         str_rad_cfs = num2mstr(rad_cfs);
  185.         str_edi_bin = num2mstr(edi_bin);
  186.         cba_sel_rec = [mfilename '(''select'',' ...
  187.                             str_numwin ',' ...
  188.                             str_rad_rec ',' ...
  189.                             str_infos_hdls ...
  190.                             ');'];
  191.         cba_sel_cfs = [mfilename '(''select'',' ...
  192.                             str_numwin ',' ...
  193.                             str_rad_cfs ',' ...
  194.                             str_infos_hdls ...
  195.                             ');'];
  196.         cba_edi_bin = [mfilename '(''update_bins'',' ...
  197.                               str_numwin ',' ...
  198.                               str_edi_bin ',' ...
  199.                               str_infos_hdls ...
  200.                               ');'];
  201.         cba_pus_sta = [mfilename '(''draw'',' ...
  202.                               str_numwin ',' ...
  203.                               str_win_caller ',' ...
  204.                               str_infos_hdls ',' ...
  205.                               str_node ...
  206.                               ');'];
  207.         set(rad_rec,'Callback',cba_sel_rec);
  208.         set(rad_cfs,'Callback',cba_sel_cfs);
  209.         set(edi_bin,'Callback',cba_edi_bin);
  210.         set(pus_sta,'Callback',cba_pus_sta);
  211.         % Axes construction.
  212.         %-------------------
  213.         xspace     = gra_width/10;
  214.         yspace     = pos_frame0(4)/10;
  215.         axe_height = (pos_frame0(4)-Def_Btn_Height-h_frame1-4*dy)/2-yspace;
  216.         axe_width  = gra_width-2*xspace;
  217.         half_width = axe_width/2-xspace/2;
  218.         cx         = xspace-axe_height/2+axe_width/2;
  219.         cx         = gra_width/2;
  220.         cy         = h_frame1+2*dy2+axe_height+4*yspace/3+axe_height/2;
  221.         [w_used,h_used] = wpropimg(Img_Size,axe_width,axe_height,'pixels');
  222.         pos_ax_image    = [cx-w_used/2,cy-h_used/2,w_used,h_used];
  223.         pos_ax_hist     = [xspace h_frame1+2*dy2+yspace/3 ...
  224.                                  half_width axe_height];
  225.         pos_ax_cumhist  = [2*xspace+half_width h_frame1+2*dy2+yspace/3 ...
  226.                                  half_width axe_height];
  227.         commonProp = {...
  228.            'Parent',win_stats,...
  229.            'Units',win_units,...
  230.            'Visible','Off',...
  231.            'box','on',...
  232.            'NextPlot','Replace',...
  233.            'Drawmode','fast'...
  234.            };
  235.         axe_image   = axes(commonProp{:},...
  236.                               'Position',pos_ax_image,'Tag',tag_ax_image);
  237.         axe_hist    = axes(commonProp{:},...
  238.                               'Position',pos_ax_hist,'Tag',tag_ax_hist);
  239.         axe_cumhist = axes(commonProp{:},...
  240.                               'Position',pos_ax_cumhist,'Tag',tag_ax_cumhist);
  241.         drawnow
  242.         % Displaying the window title.
  243.         %-----------------------------
  244.         str_par = utentpar('get',win_stats,'txt');
  245.         if ~isempty(str_par)
  246.             str_par = [' (' lower(str_par) ' = ',num2str(Ent_Par),')'];
  247.         end
  248.         str_nb_val   = [' (' sprintf('%.0f',Img_Size(1)) ' x ' sprintf('%.0f',Img_Size(2)) ')'];
  249.         str_wintitle = [Img_Name,str_nb_val,' analyzed at level ',...
  250.                         sprintf('%.0f',depth),' with ',Wave_Name,...
  251.                         ' and ''',Ent_Nam,''' entropy',str_par];
  252.         wfigtitl('string',win_stats,str_wintitle,'off');
  253.         % Setting units to normalized.
  254.         %-----------------------------
  255.         wfigmngr('normalize',win_stats);
  256.         % Computing statistics for the node.
  257.         %-----------------------------------
  258. wp2dstat('draw',win_stats,win_caller,infos_hdls,node);
  259.         % End waiting.
  260.         %-------------
  261.         set(wfindobj('figure'),'Pointer','arrow');
  262.     case 'select'
  263.         %***********************************************%
  264.         %** OPTION = 'select' - SIGNAL TYPE SELECTION **%
  265.         %***********************************************%
  266.         sel_rad_btn = varargin{2};
  267.         infos_hdls  = varargin{3};
  268.         % Set to the current selection.
  269.         %------------------------------
  270.         children    = get(win_stats,'Children');
  271.         rad_handles = findobj(children,'Style','radiobutton');
  272.         old_rad     = findobj(rad_handles,'Userdata',1);
  273.         set(rad_handles,'Value',0,'Userdata',0);
  274.         set(sel_rad_btn,'Value',1,'Userdata',1)
  275.         if old_rad==sel_rad_btn , return; end
  276.         % Reset all.
  277.         %-----------
  278.         set(infos_hdls,'Visible','off');
  279.         axe_handles = findobj(children,'flat','type','axes');
  280.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  281.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  282.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  283.         set(findobj([axe_image,axe_hist,axe_cumhist]),'visible','off');
  284.         drawnow
  285.     case 'draw'
  286.         %*********************************%
  287.         %** OPTION = 'draw' - DRAW AXES **%
  288.         %*********************************%
  289.         win_caller = varargin{2};
  290.         infos_hdls = varargin{3};
  291.         node       = varargin{4};
  292.         % Handles of tagged objects.
  293.         %---------------------------
  294.         children    = get(win_stats,'Children');
  295.         axe_handles = findobj(children,'flat','Type','axes');
  296.         uic_handles = findobj(children,'flat','Type','uicontrol');
  297.         pus_sta     = findobj(uic_handles,'Style','pushbutton','Tag',tag_pus_sta);
  298.         axe_image   = findobj(axe_handles,'flat','Tag',tag_ax_image);
  299.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  300.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  301.         rad_handles = findobj(uic_handles,'Style','radiobutton');
  302.         edi_handles = findobj(uic_handles,'Style','edit');
  303.         rad_cfs     = findobj(rad_handles,'Tag',tag_sel_cfs);
  304.         edi_bin     = findobj(edi_handles,'Tag',tag_edi_bin);
  305.         % Main parameters selection before drawing.
  306.         %------------------------------------------
  307.         sel_cfs = (get(rad_cfs,'Value')~=0);
  308.         % Check the bins number.
  309.         %-----------------------
  310.         default_bins = 50;
  311.         old_params   = get(pus_sta,'Userdata');
  312.         if ~isempty(old_params) , default_bins = old_params(1); end
  313.         nb_bins = wstr2num(get(edi_bin,'String'));
  314.         if isempty(nb_bins) | (nb_bins<2)
  315.             nb_bins = default_bins;   
  316.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  317.         end
  318.         new_params = [nb_bins sel_cfs node];
  319.         if ~isempty(old_params) & (new_params==old_params)
  320.             vis = get(axe_hist,'Visible');
  321.             if vis(1:2)=='on', return, end
  322.         end
  323.         % Deseable new selection.
  324.         %-------------------------
  325.         set([edi_bin;rad_handles],'Enable','off');
  326.         % Updating parameters.
  327.         %--------------------- 
  328.         set(pus_sta,'Userdata',new_params);
  329.         % Show the status line.
  330.         %----------------------
  331.         wfigtitl('vis',win_stats,'on');
  332.         % Cleaning the graphical part.
  333.         %-----------------------------
  334.         set(infos_hdls,'Visible','off');
  335.         % Waiting message.
  336.         %-----------------
  337.         wwaiting('msg',win_stats,'Wait ... computing');
  338.         % Cleaning the graphical part continuing.
  339.         %----------------------------------------
  340.         set(findobj([axe_image,axe_hist,axe_cumhist]),'visible','off');
  341.         drawnow
  342.         % Parameters initialization.
  343.         %---------------------------
  344.         NB_ColorsInPal = wmemtool('rmb',win_caller,n_wp_utils,ind_nb_colors);
  345.         if node>-1
  346.             % Getting memory blocks.
  347.             %-----------------------
  348.             [WP_Tree,WP_Data] = wmemtool('rmb',win_caller,n_structures,...
  349.                                                ind_tree_st,ind_data_st);
  350.             order = treeord(WP_Tree);
  351.             depth = treedpth(WP_Tree);            
  352.             % Current image construction.
  353.             %----------------------------
  354.             if sel_cfs
  355.                 if isa(WP_Tree,'wptree')
  356.                     curr_img = wpcoef(WP_Tree,node);
  357.                 else
  358.                     curr_img = wpcoef(WP_Tree,WP_Data,node);
  359.                 end
  360.                 str_title= 'Coefficients of ';
  361.             else
  362.                 if isa(WP_Tree,'wptree')
  363.                     curr_img = wprcoef(WP_Tree,node);
  364.                 else
  365.                     curr_img = wprcoef(WP_Tree,WP_Data,node);
  366.                 end
  367.                 str_title= 'Reconstructed ';
  368.             end
  369.             size_img = size(curr_img);
  370.             if size_img(1)<3 | size_img(2)<3
  371.                 wwarndlg(['          Not enough coefficients ' ...
  372.                         'remaining at level ' ...
  373.                         sprintf('%.0f',level)],...
  374.                         'Wavelet Packet 2-D -- Statistics','modal');
  375.                 wwaiting('off',win_stats);
  376.                 return;
  377.             end
  378.             Tree_Type_TxtV  = wmemtool('rmb',win_caller,n_wp_utils,...
  379.                                              ind_type_txt);
  380.             [level,pos]     = ind2depo(order,node);
  381.             if strcmp(Tree_Type_TxtV,'i')
  382.                 ind     = depo2ind(order,node);
  383.                 str_pck = ['Packet ('  sprintf('%.0f',ind) ')'];
  384.             else
  385.                 str_pck = ['Packet (' sprintf('%.0f',level) ','  ...
  386.                                       sprintf('%.0f',pos), ')'];
  387.             end
  388.             if pos==0
  389.                 if level==0
  390.                     curr_color = wtbutils('colors','sig');
  391.                     str_title  = [str_title str_pck ...
  392.                                   ' ===> Original image'];
  393.                     flg_code   = 0;
  394.                 else
  395.                     col_app    = wtbutils('colors','app',depth);
  396.                     curr_color = col_app(level,:);
  397.                     str_title  = [str_title str_pck ...
  398.                                   ' ===> Approximation at level '...
  399.                                        sprintf('%.0f',level)];
  400.                 end
  401.                 if sel_cfs
  402.                     flg_code = 1;
  403.                 else
  404.                     flg_code = 0;
  405.                 end
  406.             else
  407.                 col_det    = wtbutils('colors','det',depth);
  408.                 curr_color = col_det(level,:);
  409.                 str_title  = [str_title str_pck];
  410.                 flg_code   = 1;
  411.             end
  412.         else
  413.             curr_img = get(wpssnode('r_synt',win_caller),'Userdata');
  414.             curr_color = wtbutils('colors','wp2d','hist');
  415.             if node==-1
  416.                 str_title = ['Compressed Image'];
  417.             elseif node==-2
  418.                 str_title = ['De-noised Image'];
  419.             end
  420.             flg_code  = 0;
  421.         end
  422.         % Displaying the image.
  423.         %=====================
  424. % Image Coding Value.
  425. %-------------------
  426. codemat_v = wimgcode('get',win_caller);
  427.         set(win_stats,'Colormap',get(win_caller,'Colormap'));
  428.         axes(axe_image);
  429.         image(wimgcode('cod',flg_code,curr_img,NB_ColorsInPal,codemat_v),...
  430.                 'Parent',axe_image);
  431.         set(axe_image,'Tag',tag_ax_image);
  432.         wtitle(str_title,'Parent',axe_image);
  433.         drawnow;
  434.         % Check the bins number.
  435.         %-----------------------
  436.         nb_bins = wstr2num(get(edi_bin,'String'));
  437.         if isempty(nb_bins) | (nb_bins<2)
  438.             nb_bins = default_bins;
  439.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  440.         end
  441.         % Displaying histogram.
  442.         %----------------------
  443.         his       = wgethist(curr_img(:),nb_bins);
  444.         [xx,imod] = max(his(2,:));
  445.         mode_val  = (his(1,imod)+his(1,imod+1))/2;
  446.         his(2,:)  = his(2,:)/length(curr_img(:));
  447.         axes(axe_hist);
  448.         wplothis(axe_hist,his,curr_color);
  449.         wtitle('Histogram','Parent',axe_hist);
  450.         % Displaying cumulated histogram.
  451.         %--------------------------------
  452.         for i=6:4:length(his(2,:));
  453.             his(2,i)   = his(2,i)+his(2,i-4);
  454.             his(2,i+1) = his(2,i);
  455.         end
  456.         axes(axe_cumhist);
  457.         wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  458.         wtitle('Cumulative histogram','Parent',axe_cumhist);
  459.         drawnow;
  460.         % Displaying statistics.
  461.         %-----------------------
  462.         mean_val  = mean(mean(curr_img));
  463.         max_val   = max(max(curr_img));
  464.         min_val   = min(min(curr_img));
  465.         range_val = max_val-min_val;
  466.         std_val   = std(curr_img(:));
  467.         med_val   = median(curr_img(:));
  468.         utstats('display',win_stats, ...
  469.             [mean_val; med_val ; mode_val;  ...
  470.              max_val ; min_val ; range_val; ...
  471.              std_val ; median(abs(curr_img(:)-med_val)); ...
  472.              mean(mean(abs(curr_img-mean_val)))]);
  473.         % Memory blocks update.
  474.         %----------------------
  475.         wmemtool('ini',win_stats,n_misc_loc,nbLOC_1_stored);
  476.         wmemtool('wmb',win_stats,n_misc_loc, ...
  477.                        ind_curr_img,curr_img(:), ...
  478.                        ind_curr_color,curr_color ...
  479.                        );
  480.         % End waiting.
  481.         %-------------
  482.         wwaiting('off',win_stats);
  483.         % Setting infos visible.
  484.         %-----------------------
  485.         set(infos_hdls,'Visible','on');
  486.         % Enable new selection.
  487.         %-------------------------
  488.         set([edi_bin;rad_handles],'Enable','on');
  489.     case 'update_bins'
  490.         %**************************************************************%
  491.         %** OPTION = 'update_bins' - UPDATE HISTOGRAMS WITH NEW BINS **%
  492.         %**************************************************************%
  493.         edi_bin = varargin{2};
  494.         infos_hdls    = varargin{3};
  495.         % Handles of tagged objects.
  496.         %---------------------------
  497.         children    = get(win_stats,'Children');
  498.         axe_handles = findobj(children,'flat','type','axes');
  499.         uic_handles = findobj(children,'flat','type','uicontrol')  ;
  500.         pus_sta = findobj(uic_handles,...
  501.                                         'Style','pushbutton',...
  502.                                         'Tag',tag_pus_sta...
  503.                                         );
  504.         axe_hist    = findobj(axe_handles,'flat','Tag',tag_ax_hist);
  505.         axe_cumhist = findobj(axe_handles,'flat','Tag',tag_ax_cumhist);
  506.         % Return if no current display.
  507.         %------------------------------
  508.         vis     = get(axe_hist,'Visible');
  509.         if vis(1:2)=='of', return, end
  510.         % Check the bins number.
  511.         %-----------------------
  512.         default_bins = 50;
  513.         old_params   = get(pus_sta,'Userdata');
  514.         if ~isempty(old_params)
  515.             default_bins = old_params(1);
  516.         end
  517.         nb_bins = wstr2num(get(edi_bin,'String'));
  518.         if isempty(nb_bins) | (nb_bins<2)
  519.             nb_bins = default_bins;
  520.             set(edi_bin,'String',sprintf('%.0f',default_bins))
  521.         end
  522.         if default_bins==nb_bins , return; end
  523.         % Waiting message.
  524.         %-----------------
  525.         set(infos_hdls,'Visible','off');
  526.         wwaiting('msg',win_stats,'Wait ... computing');
  527.         % Getting memory blocks.
  528.         %-----------------------
  529.         [curr_img,curr_color] = wmemtool('rmb',win_stats,n_misc_loc,...
  530.                                                ind_curr_img,...
  531.                                                ind_curr_color);
  532.         % Updating histograms.
  533.         %---------------------
  534.         if ~isempty(curr_img)
  535.             old_params(1) = nb_bins;
  536.             set(pus_sta,'Userdata',old_params);
  537.             his      = wgethist(curr_img,nb_bins);
  538.             his(2,:) = his(2,:)/length(curr_img);
  539.             axes(axe_hist);
  540.             wplothis(axe_hist,his,curr_color);
  541.             wtitle('Histogram','Parent',axe_hist);
  542.             for i=6:4:length(his(2,:));
  543.                 his(2,i)   = his(2,i)+his(2,i-4);
  544.                 his(2,i+1) = his(2,i);
  545.             end
  546.             axes(axe_cumhist);
  547.             wplothis(axe_cumhist,[his(1,:);his(2,:)],curr_color);
  548.             wtitle('Cumulative histogram','Parent',axe_cumhist);
  549.         end
  550.         % End waiting.
  551.         %-------------
  552.         wwaiting('off',win_stats);
  553.         set(infos_hdls,'Visible','on');
  554.     case 'demo'
  555.         %****************************************%
  556.         %** OPTION = 'demo' -  DEMOS or TESTS  **%
  557.         %****************************************%
  558.         pus_sta = findobj(win_stats,'Style','pushbutton','Tag',tag_pus_sta);
  559.         eval(get(pus_sta,'Callback'));
  560.     case 'close'
  561.     otherwise
  562.         errargt(mfilename,'Unknown Option','msg');
  563.         error('*');
  564. end