Resize Image Arrays

You can shrink or expand one-, two-, or three-dimensional image arrays using the CONGRID and REBIN functions. CONGRID resizes an array by any arbitrary amount, and REBIN resizes by an integer multiple of the original dimensions.

For more information on how these functions work, see How Image Arrays are Resized.

Resizing to a Specific Size

The following example uses the CONGRID function. This example data is available in the examples/data directory of your IDL installation. The code shown below creates the graphics shown here.

Original image array image array after congrid resize

Copy the entire code block and paste it into the IDL command line to run it.

; Select the file.

file = FILEPATH('convec.dat', SUBDIRECTORY=['examples', 'data'])

 

; Use READ_BINARY to read in the data,

; specifying known data dimensions.

data = READ_BINARY(file, DATA_DIMS=[248, 248])

 

; Use the IMAGE function to display the original image with a color table.

im = IMAGE(data, RGB_TABLE=28)

 

; Use the CONGRID function to increase the image array

; size to 600 by 600 pixels and force bilinear interpolation.

magnifiedIm = CONGRID(data, 600, 600, /INTERP)

 

; Display the magnified image in a new window

; with a color table.

im2 = IMAGE(magnifiedIm, RGB_TABLE=28)

Resizing to a Multiple of the Image Array Size

You can achieve similar results using REBIN, but you need to specify a multiple of the original array size.

The following example uses the same data as the previous example, using REBIN to resize the image display:

; Select the file.

file = FILEPATH('convec.dat', SUBDIRECTORY=['examples', 'data'])

 

; Use READ_BINARY to read in the data,

; specifying known data dimensions.

convec_image = READ_BINARY(file, DATA_DIMS=[248, 248])

 

; Use the IMAGE function to display

; the original image with a color table.

im = IMAGE(convec_image, RGB_TABLE=28)

 

; Use the REBIN function to increase the

; image array size to three times the original size

rebinIm = REBIN(convec_image, 744, 744)

 

; Display the resized image in a new window with a color table.

im2 = IMAGE(rebinIm, RGB_TABLE=28)

How Image Arrays are Resized

When expanding an image array, new values are interpolated from the source image to produce additional pixels in the output image array:

When shrinking an image array, IDL resamples pixels to produce a lower number of pixels in the output image array:

Resources