
// Script function: Smoothen an image
// 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 GlobalSinoImage
 
if ( !GetFrontImage( GlobalSinoImage ) )
Throw( "Please open an image" )

GlobalSinoImage:=GetFrontImage()

number EMxScale, EMyScale
GetScale(GlobalSinoImage, EMxScale, EMyScale)

number EMxSize, EMySize, EMx, EMy
getsize(GlobalSinoImage, EMxSize, EMySize)
number EMValueMinus1x, EMValueMinus1y, EMValue, EMValuePlus1x, EMValuePlus1y

for (EMy = 1; EMy < EMySize-1; EMy++) {
for (EMx = 1; EMx < EMxSize-1; EMx++) {

EMValueMinus1x = GetPixel(GlobalSinoImage, EMx-1, EMy);
EMValueMinus1y = GetPixel(GlobalSinoImage, EMx, EMy-1);
EMValue = GetPixel(GlobalSinoImage, EMx, EMy);
EMValuePlus1x = GetPixel(GlobalSinoImage, EMx+1, EMy);
EMValuePlus1y = GetPixel(GlobalSinoImage, EMx, EMy+1);

EMValue = (EMValueMinus1x + EMValueMinus1y + EMValue + EMValuePlus1x + EMValuePlus1y)/5

SetPixel(GlobalSinoImage, EMx, EMy, EMValue)
}
}

String EMLengthUnits = GetUnitString(GlobalSinoImage)

GlobalSinoImage.SetName("Smoothen from " + GlobalSinoImage.GetName())
ShowImage(GlobalSinoImage)