|
Image Processing : Transforming Image Geometry |
|
To change the orientation of an image in IDL, use either the ROTATE or the ROT function. The ROTATE function changes the orientation of an image by 90 degree increments and/or transposes the array. The ROT function rotates an image by any amount and offers additional resizing options. For more information, see Using the ROT Function for Arbitrary Rotations.
The following example changes the orientation of an image by rotating it 270°.
| Example Code See rotateimage.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
file = FILEPATH('galaxy.dat', $
SUBDIRECTORY=['examples', 'data'])
image = READ_BINARY(file, DATA_DIMS = [256, 256])
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT, 4 WINDOW, 0, XSIZE = 256, YSIZE = 256 TVSCL, image
3. See ROTATE Direction Argument Options for more information. rotateImg = ROTATE(image, 3)
Window, 1, XSIZE = 256, YSIZE = 256, TVSCL, rotateImg
The following figure displays the original (left) and the rotated image (right).
![]() |
The following table describes the Direction options available with the ROTATE function syntax, Result = ROTATE (Array, Direction).
|
Direction
|
Transpose?
|
Rotation Counterclockwise
|
Sample Image
|
|---|---|---|---|
|
0
|
No
|
None
|
|
|
1
|
No
|
90°
|
|
|
2
|
No
|
180°
|
|
|
3
|
No
|
270°
|
|
|
4
|
Yes
|
None
|
|
|
5
|
Yes
|
90°
|
|
|
6
|
Yes
|
180°
|
|
|
7
|
Yes
|
270°
|
|
The ROT function supports clockwise rotation of an image by any specified amount (not limited to 90 degree increments). Keywords also provide a means of optionally magnifying the image, selecting the pivot point around which the image rotates, and using either bilinear or cubic interpolation. If you wish to rotate an image only by 90 degree increments, ROTATE produces faster results.
The following example opens a image of a whirlpool galaxy, rotates it 33° clockwise and shrinks it to 50% of its original size.
| Example Code See arbitraryrotation.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
file = FILEPATH('m51.dat', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_BINARY(file, DATA_DIMS = [340, 440])
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT, 0
WINDOW, 0, XSIZE = 340, YSIZE = 440 TVSCL, image
Result=ROT(A,Angle, [Mag,X0,Y0] [,/INTERP] [,CUBIC=value{-1 to 0}] [, MISSING=value] [,/PIVOT])
enter the following line to rotate the image 33°, shrink it to 50% of its original size, and fill the image display with a neutral gray color where there are no original pixel values:
arbitraryImg = ROT(image, 33, .5, /INTERP, MISSING = 127)
WINDOW, 1, XSIZE = 340, YSIZE = 440 TVSCL, arbitraryImg
Your output should appear similar to the following figure.
![]() |
The MISSING keyword maintains the original image's boundaries, keeping the interpolation from extending beyond the original image size. Replacing MISSING = 127 with MISSING = 0 in the previous example creates a black background by using the default pixel color value of 0. Removing the MISSING keyword from the same statement allows the image interpolation to extend beyond the image's original boundaries.
IDL Online Help (March 06, 2007)