
// Script function: Coordinate transformation from an electron diffraction pattern rings to a polar-coordinate transform, 
// allowing the use of the DM profile extraction tool to get radial averages in 1D profile.
// Requirement: Open an diffraction 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
GetFrontImage(GlobalSinoImage)
number EMx, EMy
getsize (GlobalSinoImage, EMx, EMy)  // Read image size

number EMxCenter = EMx/2 // Specify x-coordinate of the transformation center
number EMyCenter = EMy/2 // Specify y-coordinate of the transformation center


number EMradius = maximum(EMxCenter, EMyCenter) // Transformation radius
image EMpolar := RealImage ("GlobalSino Polar", 4, EMradius, 360) // Define output image by resizing the original image
SetColorMode (EMpolar, 1) // Use Grey Scale as the color mode of created image
EMpolar = Warp (GlobalSinoImage, EMxCenter+icol*cos(2*Pi()*irow/iheight), EMyCenter+icol*sin(2*Pi()*irow/iheight)) // Coordinate transformation 
ShowImage(EMpolar)
