// Script function: Sobel Edge filter.

// 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 EMfront:=getfrontimage()

	image EMp1=offset(EMfront, 1, 1) // p1
	image EMp2=2*(offset(EMfront, 0, 1)) // p2
	image EMp3=offset(EMfront, -1, 1) // p3
	image EMp4=2*(offset(EMfront, 1, 0)) // p4

	image EMp6=2*(offset(EMfront, -1, 0)) // p6
	image EMp7=offset(EMfront, 1, -1) // p7
	image EMp8=2*(offset(EMfront, 0, -1)) // p8
    image EMp9=offset(EMfront, -1, -1) // p9

		
image GlobalSinoX = EMp1+EMp2+EMp3-EMp7-EMp8-EMp9
image GlobalSinoY = EMp3+EMp6+EMp9-EMp1-EMp4-EMp7

image GlobalSinoPrewitt=sqrt(GlobalSinoX**2+GlobalSinoY**2)

showimage (GlobalSinoPrewitt)
string EMimgName=getname(EMfront)
setname(GlobalSinoPrewitt, "Sobel Filtered '"+ EMimgName +"'")