@@ -656,184 +656,19 @@ function Stats_Callback(hObject, eventdata, handles)
656656% HISTOGRAM FIG
657657function Histogram_Callback(hObject , eventdata , handles )
658658% unselect button to prevent activation with spacebar
659- set(hObject , ' Enable' , ' off' );
660- drawnow ;
661- set(hObject , ' Enable' , ' on' );
662- % Plot figure
663- f= figure(' Position' , [100 100 700 400 ], ' Resize' , ' Off' ,' Name' ,' Histogram' );
664-
665- Map = handles .tool .getImage ;
666- MatlabVer = version ;
667- if str2double(MatlabVer(1 ))<8 || (str2double(MatlabVer(1 ))==8 && str2double(MatlabVer(3 ))<4)
668- Maskall = uint8(handles .tool .getMask );
669- else
670- Maskall = handles .tool .getMask(1 );
671- h_plot = subplot(1 ,2 ,2 ); % Use subplot to give space for GUI elements
672- h_plot.OuterPosition = [0.3 0 0.7 1.0 ];
673- end
674-
675- % loop over mask
676- values = unique(Maskall(Maskall > 0))' ;
677- if isempty(values ), values = 0 ; end
678- for ic = 1 : length(values )
679- Selected = values(ic );
680- Mask = Maskall == Selected ;
659+ set(hObject , ' Enable' , ' off' );
660+ drawnow ;
661+ set(hObject , ' Enable' , ' on' );
681662
682- ii = find(Mask );
683- nVox = length(ii );
684- data = reshape(Map(ii ),1 ,nVox );
685-
686- % Matlab < R2014b
687- MatlabVer = version ;
688- if str2double(MatlabVer(1 ))<8 || (str2double(MatlabVer(1 ))==8 && str2double(MatlabVer(3 ))<4)
689- defaultNumBins = max(5 ,round(length(data )/100 ));
690- hist(data , defaultNumBins );
691- % Label axes
692- SourceFields = cellstr(get(handles .SourcePop ,' String' ));
693- Source = SourceFields{get(handles .SourcePop ,' Value' )};
694- xlabel(Source );
695- ylabel(' Counts' );
696- return ;
697- end
663+ Map = handles .tool .getImage ;
664+ Maskall = handles .tool .getMask(1 );
698665
699- % Matlab >= R2014b
700- hold on
701- h_hist(ic )=histogram(data );
702- BinWidth(ic ) = h_hist .BinWidth ;
703-
704- hold off
666+ SourceFields = cellstr(get(handles .SourcePop ,' String' ));
667+ label = SourceFields{get(handles .SourcePop ,' Value' )};
705668 Color = handles .tool .getMaskColor ;
706- set(h_hist(ic ),' FaceColor' ,Color(Selected + 1 ,: ),' FaceAlpha' ,0.3 )
707- end
708-
709- % set BinWidth
710- BinWidth = median(BinWidth );
711- for ic = 1 : length(h_hist )
712- h_hist(ic ).BinWidth = BinWidth ;
713- end
714-
715- % Label axes
716- SourceFields = cellstr(get(handles .SourcePop ,' String' ));
717- Source = SourceFields{get(handles .SourcePop ,' Value' )};
718- xlabel(Source );
719- h_ylabel = ylabel(' Counts' );
720-
721- % No. of bins GUI objects
722- h_text_bin = uicontrol(f ,' Style' ,' text' ,...
723- ' String' , ' Width of bins:' ,...
724- ' FontSize' , 14 ,...
725- ' Position' ,[5 20 + 300 140 34 ]);
726- h_edit_bin = uicontrol(f ,' Style' ,' edit' ,...
727- ' String' , BinWidth ,...
728- ' FontSize' , 14 ,...
729- ' Position' ,[135 25 + 300 70 34 ]);
730- h_slider_bin = uicontrol(f ,' Style' ,' slider' ,...
731- ' Min' ,BinWidth / 10 ,' Max' ,BinWidth * 10 ,' Value' ,BinWidth ,...
732- ' SliderStep' ,[1 /(100 - 1 ) 1 /(100 - 1 )],...
733- ' Position' ,[205 26 + 300 10 30 ],...
734- ' Callback' ,{@sl_call ,{h_hist h_edit_bin }});
735- h_edit_bin.Callback = {@ed_call ,{h_hist h_slider_bin }};
736-
737- % Min-Max GUI objects
738- h_text_min = uicontrol(f ,' Style' ,' text' ,...
739- ' String' , ' Min' ,...
740- ' FontSize' , 14 ,...
741- ' Position' ,[0 20 + 200 140 34 ]);
742- BinLimits = cat(1 ,h_hist .BinLimits );
743- h_edit_min = uicontrol(f ,' Style' ,' edit' ,...
744- ' String' , min(BinLimits(: ,1 )),...
745- ' FontSize' , 14 ,...
746- ' Position' , [35 20 + 180 70 34 ]);
747- h_text_max = uicontrol(f ,' Style' ,' text' ,...
748- ' String' , ' Max' ,...
749- ' FontSize' , 14 ,...
750- ' Position' ,[130 20 + 200 40 34 ]);
751- h_edit_max = uicontrol(f ,' Style' ,' edit' ,...
752- ' String' , max(BinLimits(: ,2 )),...
753- ' FontSize' , 14 ,...
754- ' Position' , [116 20 + 180 70 34 ]);
755- h_button_minmax = uicontrol(f ,' Style' ,' pushbutton' ,...
756- ' String' , ' Recalculate' ,...
757- ' FontSize' , 14 ,...
758- ' Position' , [65 20 + 140 100 34 ],...
759- ' Callback' ,{@minmax_call ,{h_hist h_edit_min h_edit_max data }});
760-
761- % Normalization GUI objects
762- h_text_min = uicontrol(f ,' Style' ,' text' ,...
763- ' String' , ' Normalization mode' ,...
764- ' FontSize' , 14 ,...
765- ' Position' ,[30 20 + 40 180 34 ]);
766- h_popup_norm = uicontrol(f ,' Style' ,' popupmenu' ,...
767- ' String' , {' Count' ,...
768- ' Cumulative count' ,...
769- ' Probability' ,...
770- ' PDF' ,...
771- ' CDF' },...
772- ' FontSize' , 14 ,...
773- ' Position' , [30 20 + 20 180 34 ],...
774- ' Callback' ,{@norm_call ,{h_hist h_ylabel }});
775-
776-
777- % Histogram GUI callbacks
778- function [] = sl_call(varargin )
779- % Callback for the histogram slider.
780- [h_slider_bin ,h_cell ] = varargin{[1 ,3 ]};
781- h_hist = h_cell{1 };
782- h_edit_bin = h_cell{2 };
783- for ic = 1 : length(h_hist )
784- h_hist(ic ).BinWidth = h_slider_bin .Value ;
785- end
786- h_edit_bin.String = h_slider_bin .Value ;
787-
788- function [] = ed_call(varargin )
789- % Callback for the histogram edit box.
790- [h_edit_bin ,h_cell ] = varargin{[1 ,3 ]};
791- h_hist = h_cell{1 };
792- h_slider_bin = h_cell{2 };
793-
794- for ic= 1 : length(h_hist )
795- h_hist(ic ).BinWidth = max(eps ,str2double(h_edit_bin .String ));
796- end
797- h_slider_bin.Value = round(str2double(h_edit_bin .String ));
798-
799- function [] = minmax_call(varargin )
800- % Callback for the histogram bin bounds recalculate box.
801- h_cell = varargin{3 };
802- h_hist = h_cell{1 };
803- h_min = h_cell{2 };
804- h_max = h_cell{3 };
805-
806- % Mask data out of range of min-max
807- minVal = str2double(h_min .String );
808- maxVal = max(minVal ,str2double(h_max .String ));
809-
810- for ic = 1 : length(h_hist )
811- h_hist(ic ).BinLimits = [minVal maxVal ];
812- end
813669
814- function [] = norm_call(varargin )
815- % Callback for the histogram edit box.
816- [h_popup_norm ,h_cell ] = varargin{[1 ,3 ]};
817- h_hist = h_cell{1 };
818- h_ylabel = h_cell{2 };
819-
820- menu_status = h_popup_norm.String{h_popup_norm .Value };
821-
822- for ic= 1 : length(h_hist )
823- switch menu_status
824- case ' Count'
825- h_hist(ic ).Normalization = ' count' ;
826- case ' Cumulative count'
827- h_hist(ic ).Normalization = ' cumcount' ;
828- case ' Probability'
829- h_hist(ic ).Normalization = ' probability' ;
830- case ' PDF'
831- h_hist(ic ).Normalization = ' pdf' ;
832- case ' CDF'
833- h_hist(ic ).Normalization = ' cdf' ;
834- end
835- end
836- h_ylabel.String = menu_status ;
670+ HistogramGUI(Map , Maskall , Color , label )
671+
837672
838673% PLOT DATA FIT
839674function ViewDataFit_Callback(hObject , eventdata , handles )
0 commit comments