|
Image Processing : Transforming Image Geometry |
|
The SHIFT function moves elements of a vector or array along any dimension by any number of elements. All shifts are circular. Elements shifted off one end are wrapped around, appearing at the opposite end of the vector or array.
Occasionally, image files are saved with array elements offset. The SHIFT function allows you to easily correct such images assuming you know the amounts of the vertical and horizontal offsets. In the following example, the x-axis of original image is offset by a quarter of the image width, and the y-axis is offset by a third of the height.
![]() |
Using the SHIFT syntax, Result = SHIFT(Array, S1, ..., Sn), we will enter negative values for the S (dimension) amounts in order to correct the image offset.
| Example Code See shiftimageoffset.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
file = FILEPATH('shifted_endocell.png', $
SUBDIRECTORY = ['examples','data'])
image = READ_PNG(file, R, G, B)
DEVICE, DECOMPOSED = 0, RETAIN = 2 TVLCT, R, G, B
imageSize = SIZE(image, /DIMENSIONS) WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, image
image = SHIFT(image, -(imageSize[0]/4), -(imageSize[1]/3))
WINDOW, 1, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE='Shifted Image' TV, image
The following figure displays the corrected image.
IDL Online Help (March 06, 2007)