// Script function: Mask all pixels within a circular area around a specific point ROI.
// Requirement: Open an image and create a point 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


void GlobalSinoPrint( ROI GlobalSinoROI, number MyCalculation )
{
 if ( !GlobalSinoROI.ROIIsValid() )
     Throw( "Please create a point ROI!" )     
         number MyROIx, MyROIy
         GlobalSinoROI.ROIGetPoint(MyROIx, MyROIy)
         Result( "\n") 
         Result( "\t(" + MyROIx + ";" + MyROIy + ")" ) 
         Result( "\n") 
       
image GlobalSinoInput, GlobalSinoMask, GlobalSinoOutput

TagGroup GlobalSino, EMItems
GlobalSino = DLGCreateDialog( "Please confirm your radius", EMItems )
TagGroup MyNumber1
EMItems.DLGAddElement( DLGCreateRealField( "My radius is :", MyNumber1, 100, 8, 3 ) )       
if ( !Alloc( UIframe ).Init( GlobalSino ).Pose() ) exit (0)
number GlobalSinoRadius = MyNumber1.DLGGetValue()

if ( !GetFrontImage( GlobalSinoInput ) )
Throw( "No image loaded." )
GlobalSinoMask = GlobalSinoInput * 0        // create all zero-valued mask of same size as image
GlobalSinoMask = ( ( icol - MyROIx )**2 + ( irow - MyROIy )**2 < GlobalSinoRadius**2 ) ? 1 : 0                
GlobalSinoOutput := GlobalSinoMask ? GlobalSinoInput : 0
SetName( GlobalSinoOutput, GetName( GlobalSinoInput ) + " masked" )
ShowImage( GlobalSinoOutput )                    
         
}
image GlobalSinoImage := GetFrontImage()
imageDisplay MyDisplay = GlobalSinoImage.ImageGetImageDisplay( 0 )
number MyCalculation = TwoButtonDialog( "Do you want to compute it?", "Yes", "No" )
 GlobalSinoPrint( MyDisplay.ImageDisplayGetROI( 0 ), MyCalculation )
 
