// Script function: Phase calculation of  Prewitt Edge filtered images.

// 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=offset(EMfront, 0, 1) // p2
	image EMp3=offset(EMfront, -1, 1) // p3
	image EMp4=offset(EMfront, 1, 0) // p4

	image EMp6=offset(EMfront, -1, 0) // p6
	image EMp7=offset(EMfront, 1, -1) // p7
	image EMp8=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)

image EMphasePrewitt = 180 * atan2(GlobalSinoY, GlobalSinoX) / Pi()
showimage (EMphasePrewitt)
string EMimgName=getname(EMfront)
setname(EMphasePrewitt, "Phase of Prewitt Filtered '"+ EMimgName +"'")

