// Script function: Mask all pixels with intensities below a certain times of the mean value
// Requirement to run the script: Open an image

// 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 EMInputImage, EMMask, EMOutputImage
if ( !GetFrontImage( EMInputImage ) )
Throw( "Please open an image." )

TagGroup GlobalSino, EMItems
GlobalSino = DLGCreateDialog( "Please confirm your channels", EMItems )
TagGroup MyMeanNumber
EMItems.DLGAddElement( DLGCreateRealField( "Window Start (eV) :", MyMeanNumber, 1, 8, 3 ) )  

if ( !Alloc( UIframe ).Init( GlobalSino ).Pose() ) exit (0)
number GlobalSinoMeanNumber = MyMeanNumber.DLGGetValue()

EMMask := ( EMInputImage > GlobalSinoMeanNumber*mean( EMInputImage ) ) ? 1 : 0                
SetName( EMMask, "Binary mask" )
ShowImage( EMMask )

EMOutputImage := EMMask ? EMInputImage : 0
SetName( EMOutputImage, GetName( EMInputImage ) + " Masked Image" )
ShowImage( EMOutputImage ) 
