// Script function: Sum the counts of a ROI area in a given image
// Requirement: Open an image and then draw a ROI on it
 
// 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
 
image GlobalSinoImage
if ( !GetFrontImage( GlobalSinoImage ) )
Throw( "Please open an image and draw a rectangle ROI" )
 
GlobalSinoImage:=getfrontimage()
 
ImageDisplay EMImage=GlobalSinoImage.ImageGetImageDisplay(0)
 
if( 1 !=  EMImage.ImageDisplayCountROIs())
Throw( "Please draw a rectangle ROI" )
 
number EMxScale, EMyScale
GetScale(GlobalSinoImage, EMxScale, EMyScale)
ImageDisplay EMImageDisplay=GlobalSinoImage.ImageGetImageDisplay(0)
ROI EMROI=EMImageDisplay.ImageDisplayGetROI(0)
 
image EMROIImage=GlobalSinoImage[]
ShowImage(EMROIImage)
 
ImageCopyCalibrationFrom(EMROIImage, GlobalSinoImage)
 
string EMImageName
GetName(GlobalSinoImage, EMImageName)
ImageDisplay EMROIDisplay=EMROIImage.ImageGetImageDisplay(0)
EMROIDisplay.ApplyDataBar()
string GlobalSinoImageName="ROI from " + EMImageName
SetName(EMROIImage, GlobalSinoImageName)
 
 
number EMImageSum
EMImageSum= sum(EMROIImage)
 
result ("Sum of the ROI is: " + EMImageSum + "\n")
 
EMROIImage.SetName("Summed area " + EMROIImage.GetName())
ShowImage(EMROIImage)