Transposing Images

Transposing an image array interchanges array dimensions, reflecting an image about a diagonal (for example, reflecting a square image about a 45 degree line). By default, the TRANSPOSE function reverses the order of the dimensions. However, you can control how the dimensions are altered by specifying the optional vector, P, in the following statement:

Result = TRANSPOSE(Array[,P]) 

The values for P start at zero and correspond to the dimensions of the array. The following example transposes a photomicrograph of smooth muscle cells.

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

  1. Open the file and prepare to display it with a color table:
  2. READ_JPEG, FILEPATH('muscle.jpg', $ 
       SUBDIRECTORY=['examples', 'data']), image 
    DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT, 0 
    
  3. Display the original image:
  4. WINDOW, 0, XSIZE = 652, YSIZE = 444, TITLE = 'Original Image' 
    TV, image 
    
  5. Reduce the image size for display purposes:
  6. smallImg = CONGRID(image, 183, 111) 
    
  7. Using the TRANSPOSE function, reverse the array dimensions. This essentially flips the image across its main diagonal axis, moving the upper left corner of the image to the lower right corner.
  8. transposeImg1 = TRANSPOSE(smallImg) 
    WINDOW, 1, XSIZE = 600, YSIZE = 183, TITLE = 'Transposed 
    Images' 
    TV, transposeImg1, 0 
    
  9. Specifying the reversal of the array dimensions leads to the same result since this is the default behavior of the TRANSPOSE function.
  10. transposeImg2 = TRANSPOSE(smallImg, [1,0]) 
    TV, transposeImg2, 2 
    
  11. However, specifying the original arrangement of the array dimensions results in no image transposition.
  12. transposeImg3 = TRANSPOSE(smallImg, [0,1]) 
    TV, transposeImg3, 2 
    

The following figure displays the original image (top) and the results of the various TRANSPOSE statements (bottom).

Figure 2-9: Original (Top) and Transposed Images (Bottom) from Left to Right, transposeImg1, transposeImg2, and transposeImg3

imggeom11.gif