I have a DigitalMicrograph image which I would like to rotate by a certain amount (not 90 degree). This can be done by the menu item "Process...\Rotate" but I would like to do this by script. I have a script which computes the angle based on a line-ROI found on the image. (see below), but I do not know how I can then rotate the image.
Number kPi = 3.14159265359
Image front := GetFrontImage()
ImageDisplay fDisp = front.ImageGetImageDisplay(0)
ROI line = fDisp.ImageDisplayGetRoi(0)
if ( line.RoiIsValid() )
{
if ( line.RoiIsLine() )
{
number sx,sy,ex,ey
line.RoiGetLine(sx,sy,ex,ey)
number dy = ey - sy
number dx = ex - sx
number angle = atan( dy / dx ) * 180/kPi
if ( dx < 0 )
angle = angle + 180
Result("\n Rotate image by " + angle + " degree.")
}
}
Nice idea for a tool and good coding so far.
The command you are looking for is simply called
Rotate()
. You 've possibly missed it in the help documentation because it is (unfortunately) not listed in the 'image' section. There is a dedicated "reference" section meant to summarize the "simple" script commands of everyday quick-scripting:With this command, your script can be modified to the one below. Note that I've also replaced your
kPi
by the commandPI()
. TheRotate()
command requires the rotation angle to be given in radians. The size of the resulting image will be enlarged and the image is zero-padded. Also: I've replaced your If - statement with an abbreviated version.