// Script function: Top hat filter // 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 realimage GlobalSinoImage, MyHat1, MyHat2, MyHat3, MyHat4, MyHat5 GlobalSinoImage:=getfrontimage() showimage(GlobalSinoImage) string MyUnitString number scalex, scaley getunitstring(GlobalSinoImage, MyUnitString) getscale(GlobalSinoImage, scalex, scaley) string name = getname(GlobalSinoImage) GetOneImage ("Please select an image", GlobalSinoImage) MyHat1= offset(GlobalSinoImage,0,-1) MyHat2 = offset(GlobalSinoImage,-1,0) MyHat3= offset(GlobalSinoImage,0,0) MyHat4 = offset(GlobalSinoImage,1,0) MyHat5 = offset(GlobalSinoImage,0,1) image MyHatSum = MyHat1 + MyHat2 + MyHat3 + MyHat4 + MyHat5 image MyClone:= ImageClone(GlobalSinoImage) image MySumOFoffsetIMG, MyxyIMG, MyTempImage MySumOFoffsetIMG = MyClone - MyClone MyxyIMG = MyClone - MyClone number EMNumber GetNumber("Enter your desired brim radii in pixel:", 2, EMNumber) number MyxAxis, MyyAxis for (MyxAxis = -EMNumber; MyxAxis < EMNumber+1; MyxAxis++) { for (MyyAxis = -EMNumber; MyyAxis < EMNumber+1; MyyAxis++) { MyTempImage = offset(GlobalSinoImage, MyxAxis, MyyAxis) image MyCloneForSum:= ImageClone(MyTempImage) MySumOFoffsetIMG = MyCloneForSum +MySumOFoffsetIMG image brimmax=maximum(MySumOFoffsetIMG) } } image MyBrimAverage = (MySumOFoffsetIMG-MyHatSum)/(((2*EMNumber+1)**2)-5) image MyHatDirect = (MyHatSum/5) - MyBrimAverage MyHatDirect = (MyHatDirect + abs(MyHatDirect))/2 SetName(MyHatDirect, "My diff pattern from top-hat-filtering") showimage (MyHatDirect) setscale(MyHatDirect, scalex, scaley) setunitstring(MyHatDirect, MyUnitString)