// Script function: Image function 
// Requirement: 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 EMimgFunction(image MyInitialIMG)
	{
	image MyFunctionAction=MyInitialIMG*-1 // process the image by "*-"
		return MyFunctionAction
	}

//  Confirm an image is displayed
number MyOpenedIMG=countdocumentwindowsoftype(5)
if(MyOpenedIMG<1)
	{
		showalert("Please open an image.",2)
		exit(0)
	}

image MyFrontIMG:=getfrontimage()
string MyIMGname=getname(MyFrontIMG)

// Call the image function above
image MyFunctionAction=EMimgFunction(MyFrontIMG)
showimage(MyFunctionAction)
setname(MyFunctionAction, "Processed image from '" + MyIMGname + "'")

// Copy the tags and calibrations from the original image to the new image
taggroup MyFrontTags, MyNewImageTags
MyFrontTags=imagegettaggroup(MyFrontIMG)
MyNewImageTags=imagegettaggroup(MyFunctionAction)
taggroupcopytagsfrom(MyNewImageTags, MyFrontTags)
imagecopycalibrationfrom(MyFunctionAction, MyFrontIMG)