// Script function: Crop a 2D image
// 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 imgOriginal, imgCreated

if ( !GetFrontImage(imgOriginal) )
 Throw( "Please open an image." )

number EMx, EMy
GetSize( imgOriginal, EMx, EMy )

number EMBoundary =  EMx/4 // Removed boundary width

// imgCreated :=  ImageClone( imgOriginal[ EMBoundary, EMBoundary, EMy - EMBoundary, EMx - EMBoundary] )

imgCreated := ImageClone( Slice2( imgOriginal, EMBoundary, EMBoundary, 0, 0, EMx-2*EMBoundary, 1, 1, EMy-2*EMBoundary, 1 ) )

SetName( imgCreated, "Cropped from '" + GetName(imgOriginal) + "'")
ShowImage( imgCreated )

 