Resizing Images

Image resizing, or scaling, supports further image analysis by either shrinking or expanding an image. Both the CONGRID and the REBIN functions resize one-, two- or three-dimensional arrays. The CONGRID function resizes an image array by any arbitrary amount. The REBIN function requires that the output dimensions of the new array be an integer multiple of the original image's dimensions.

When magnifying an image, new values are interpolated from the source image to produce additional pixels in the output image.When shrinking an image, pixels are resampled to produce a lower number of pixels in the output image. The default interpolation method varies according to whether you are magnifying or shrinking the image.

When magnifying an image:

When shrinking an image:

The following example uses CONGRID since it offers more flexibility. However, if you wish to resize an array proportionally, REBIN returns results more quickly. For an example of magnifying an image using the CONGRID function, complete the following steps.

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

  1. Select the file and read in the data, specifying known data dimensions:
  2. file = FILEPATH('convec.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    image = READ_BINARY(file, DATA_DIMS = [248, 248]) 
    
  3. Load a color table and prepare the display device:
  4. LOADCT, 28 
    DEVICE, DECOMPOSED = 0, RETAIN = 2 
    
  5. Prepare the window and display the original image:
  6. WINDOW, 0, XSIZE = 248, YSIZE = 248 
    TV, image 
    
  7. Use the CONGRID function to increase the image array size to 600 by 600 pixels and force bilinear interpolation:
  8. magnifiedImg = CONGRID(image, 600, 600, /INTERP) 
    
  9. Display the magnified image in a new window:
  10. WINDOW, 1, XSIZE = 600, YSIZE = 600 
    TV, magnifiedImg 
    

The following figure displays the original image (left) and the magnified view of the image (right).

Figure 2-5: Original Image and Magnified Image

imggeom07ab.gif