Reversing Images

The REVERSE function allows you to reverse any dimension of an array. This allows you to quickly change the viewing orientation of an image (flipping it horizontally or vertically).

Note that in the REVERSE syntax,

Result = REVERSE(Array [, Subscript_Index][,/OVERWRITE]) 

Subscript_Index specifies the dimension number beginning with 1, not 0 as with some other functions.

The following example demonstrates reversing the x-axis values (dimension 1) and the y-axis values (dimension 2) of an image of a knee.

Example Code
See reverseimage.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering reverseimage at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT reverseimage.pro.

  1. Select the DICOM image of the knee and get the image's dimensions:
  2. image = READ_DICOM (FILEPATH('mr_knee.dcm', $ 
       SUBDIRECTORY = ['examples', 'data'])) 
    imgSize = SIZE (image, /DIMENSIONS) 
    
  3. Prepare the display device and load the gray scale color table:
  4. DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT, 0 
    
  5. Use the REVERSE function to reverse the x-axis values (flipHorzImg) and y-axis values (flipVertImg):
  6. flipHorzImg = REVERSE(image, 1) 
    flipVertImg = REVERSE(image, 2) 
    
  7. Create an output window that is 2 times the size of the x-dimension of the image and 2 times the size of the y-dimension of the image:
  8. WINDOW, 0, XSIZE = 2*imgSize[0], YSIZE = 2*imgSize[1], $ 
        TITLE = 'Original (Top) & Flipped Images (Bottom)' 
    
  9. Display the images, controlling their placement in the graphics window by using the Position argument to the TV command:
  10. TV, image, 0 
    TV, flipHorzImg, 2 
    TV, flipVertImg, 3 
    

Your output should appear similar to the following figure.

Figure 2-8: Original Image (Top); Reversed Dimension 1 (Bottom Left); and Reversed Dimension 2 (Bottom Right)

imggeom10.gif