CONGRID Function

Standard Library function that shrinks or expands an image or array.

Usage

    result = CONGRID(image, col, row)

Input Parameters

image—The two-dimensional image to resample. Can be of any data type except string.

col—The number of columns to be in the resulting image.

row—The number of rows to be in the resulting image.

Returned Value

result—The resampled image or array.

Keywords

Interp—Specifies the interpolation method to be used in the resampling:

  • If zero, uses the nearest neighbor method.

  • If nonzero, uses the bilinear interpolation method.

Discussion

CONGRID shrinks or expands the number of elements in image by interpolating values at intervals where there might not have been values before. The resulting image is of the same data type as the input image.

The nearest neighbor interpolation method is not linear, because new values that are needed are merely set equal to the nearest existing value of image. Therefore, when increasing the image size, the result may appear as individual blocks. For more information, see the PV‑WAVE User Guide.

Example 1

The following commands demonstrate what the mandrill image looks like before and after resizing. The results are shown in Using CONGRID to Shrink Images. CONGRID has been used to shrink this 512-by-512 mandrill image to one measuring 400-by-256.

OPENR, lun, !Data_dir + 'mandril.img', /Get_lun
mandril_img = BYTARR(512,512)
READU, lun, mandril_img
new_image = CONGRID(mandril_img, 400, 256)
TVSCL, mandril_img
ERASE
TVSCL, new_image

Using CONGRID to Shrink Images

Example 2

x = DIST(100)
new_x = CONGRID(x, 500, 200)
TVSCL, x
ERASE
TVSCL, new_x

See Also

BILINEAR,  REBIN