// Script function: Live histogram.
// Requirement: Open an image and draw a rectangle ROI
 
// Unless named starting with GlobalSino, EM, My, Self, the function commands are defined
//by Gatan DM, please see at link: http://www.globalsino.com/EM/page2597.html
 
 
number MyHistogramColumn,MyBinning,MyROIPixels,EMTop,EMLeft,EMBottom,EMRight
 
ImageDisplay GlobalSinoImage = GetFrontImage().ImageGetImageDisplay(0)
 
ROI EMROI = GlobalSinoImage.ImageDisplayGetROI(0)
EMROI.ROISetLabel("ROI for Histogram")
 
ROIGetRectangle(EMROI,EMTop,EMLeft,EMBottom,EMRight);
MyROIPixels = (EMBottom-EMTop)*(EMRight-EMLeft)
 
TagGroup GlobalSinoDialog, EMItems
 
GlobalSinoDialog = DLGCreateDialog( "My Binning", EMItems )
TagGroup MyOptions = DLGCreateRadioList( 1 ) // "1" here says the default selection is the one with the same number below.
MyOptions.DLGAddRadioItem( "Binning 1", 1 )
MyOptions.DLGAddRadioItem( "Binning 2", 2 ) // "10" is the default selection pointed above.
MyOptions.DLGAddRadioItem( "Binning 4", 4)
MyOptions.DLGAddRadioItem( "Binning 16", 16)
MyOptions.DLGAddRadioItem( "Binning 64", 64)
MyOptions.DLGAddRadioItem( "Binning 128", 128)
EMItems.DLGAddElement( DLGCreateLabel( "Please select a number:" ) )      
 
EMItems.DLGAddElement( MyOptions )      
 
if ( !Alloc( UIframe ).Init( GlobalSinoDialog ).Pose() ) exit (0)
MyBinning = MyOptions.DLGGetValue()
 
MyHistogramColumn = round(MyROIPixels/MyBinning)
 
NewLiveHistogram(GlobalSinoImage,GlobalSinoImage.ImageDisplayGetROI(0), MyHistogramColumn)