|
Image Processing : Transforming Image Geometry |
|
Cropping an image extracts a rectangular region of interest from the original image. This focuses the viewer's attention on a specific portion of the image and discards areas of the image that contain less useful information. Using image cropping in conjunction with image magnification allows you to zoom in on a specific portion of the image. This section describes how to exactly define the portion of the image you wish to extract to create a cropped image. For information on how to magnify a cropped image, see Resizing Images.
Image cropping requires a pair of (x, y) coordinates that define the corners of the new, cropped image. The following example extracts the African continent from an image of the world. Complete the following steps for a detailed description of the process.
| Example Code See cropworld.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
R,G,B arguments to obtain the image's color information:
world = READ_PNG (FILEPATH ('avhrr.png', $
SUBDIRECTORY = ['examples', 'data']), R, G, B)
DEVICE, RETAIN = 2, DECOMPOSED = 0 TVLCT, R, G, B
worldSize = SIZE(world, /DIMENSIONS) WINDOW, 0, XSIZE = worldSize[0], YSIZE = worldSize[1]
TV, world
In this example, we will crop the image to display only the African continent as shown in the following figure. Two sets of coordinates, (LeftLowX, LeftLowY) and (RightTopX, RightTopY), will be used to create the new, cropped image array.
![]() |
In the following step, use the CURSOR function to define the boundaries of the cropped image. The values returned by the CURSOR function will be defined as the variables shown in the previous image.
| Note To crop an image without interactively defining the cursor position, you can use the actual coordinates of the cropped image array in place of the coordinate variables, (LeftLowX, LeftLowY) and (RightTopX, RightTopY). See CropWorld.pro in the examples/doc/image subdirectory of the IDL installation directory for an example. |
CURSOR, LeftLowX, LeftLowY, /DEVICE
The cursor changes to a cross hair symbol when it is positioned over the graphics window. Click in the area to the left and below the African continent.
| Note The values for LeftLowX and LeftLowY appear in the IDLDE Variable Watch window. Alternately, use PRINT, LeftLowX, LeftLowY to display these values. |
CURSOR, RightTopX, RightTopY, /DEVICE
africa = world[LeftLowX:RightTopX, LeftLowY:RightTopY]
WINDOW, 2, XSIZE = (RightTopX - LeftLowX + 1), $ YSIZE = (RightTopY - LeftLowY + 1)
TV, africa
Your image should appear similar to the following figure.
IDL Online Help (March 06, 2007)