|
Object Programming: Working with Image Objects |
|
By default, IDLgrImage objects are drawn at Z=0 and are positioned and sized with respect to two points:
p1 = [LOCATION(0), LOCATION(1), 0] p2 = [LOCATION(0) + DIMENSION(0), LOCATION(1) + DIMENSION(1), 0].
where LOCATION and DIMENSION are properties of the image object. These two points are transformed in three dimensions, and then projected onto the screen to form the opposite corners of a 2-D rectangle resulting in screen space points designated as p1' and p2':
[ [p1'[0], p1'[1]], [[p2'[0], p1'[1]], [[p2'[0], p2'[1]], [[p1'[0], p2'[1]] ]
The image data is drawn on the display as a 2-D image within this 2-D rectangle whose sides are parallel to the screen sides. The image data is scaled in two dimensions (not rotated) to fit into this projected rectangle and then drawn with Z buffering disabled.
To draw an image with the current full 3D transformation (the same way other objects such as polygons are transformed), set the IDLgrImage TRANSFORM_MODE property to 1. See the IDLgrImage TRANSFORM_MODE property in the IDL Reference Guide for details.
Objects are drawn to a destination device in the order that they are added (via the Add method) to the model, view, or scene that contains them. By default, image objects do not take into account the depth locations of other objects that may be included in the view object unless you enable depth testing (see DEPTH_TEST_DISABLE for details).
This means that objects that are drawn to the destination object (window or printer) after the image is drawn will appear to be in front of the image, even if they are located behind the image object. And this also means that objects drawn after the image is drawn will appear to be in front of the image even if they are located behind the image. Since the image is drawn by default with depth testing disabled, you can think of the image primitive as `painting' the image onto the screen without regard for other objects that might already have been drawn there.
This behavior can be changed by enabling depth testing to make the image primitive behave like other primitives such as polygons when they are drawn with depth testing enabled.
The following example uses the LOCATION keyword to control image position. For information on other ways to define the position of an image object in a view, see Example: Centering an Image.
The following example imports an RGB image from the rose.jpg image file. This RGB image is a close-up photograph of a red rose and is pixel interleaved. This example extracts the three color channels of this image, and displays them as grayscale images in various locations within the same window. Complete the following steps for a detailed description of the process.
| Example Code See displaymultiples_object.pro in the examples/doc/objects subdirectory of the IDL installation directory for code that duplicates this example. |
rose.jpg file:
file = FILEPATH('rose.jpg', $
SUBDIRECTORY = ['examples', 'data'])
queryStatus = QUERY_IMAGE(file, imageInfo)
imageSize = imageInfo.dimensions
image = READ_IMAGE(file)
redChannel = REFORM(image[0, *, *]) greenChannel = REFORM(image[1, *, *]) blueChannel = REFORM(image[2, *, *])
The LOCATION keyword to the Init method of the image object can be used to position an image within a window. The LOCATION keyword uses data coordinates, which are the same as device coordinates for images. Before initializing the image objects, you should initialize the display objects. The following steps display multiple images horizontally, vertically, and diagonally.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[3, 1], $
TITLE = 'The Channels of an RGB Image')
oView = OBJ_NEW('IDLgrView', $
VIEWPLANE_RECT = [0., 0., imageSize]*[0, 0, 3, 1])
oModel = OBJ_NEW('IDLgrModel')
oRedChannel = OBJ_NEW('IDLgrImage', redChannel)
oGreenChannel = OBJ_NEW('IDLgrImage', greenChannel, $
LOCATION = [imageSize[0], 0])
oBlueChannel = OBJ_NEW('IDLgrImage', blueChannel, $
LOCATION = [2*imageSize[0], 0])
oModel -> Add, oRedChannel oModel -> Add, oGreenChannel oModel -> Add, oBlueChannel oView -> Add, oModel oWindow -> Draw, oView
The following figure shows the resulting grayscale images.
![]() |
These images can be displayed vertically in another window by first initializing another window and then updating the view and images with different location information.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[1, 3], $
TITLE = 'The Channels of an RGB Image')
oView -> SetProperty, $ VIEWPLANE_RECT = [0., 0., imageSize]*[0, 0, 1, 3]
oGreenChannel -> SetProperty, LOCATION = [0, imageSize[1]] oBlueChannel -> SetProperty, LOCATION = [0, 2*imageSize[1]]
oWindow -> Draw, oView
The following figure shows the resulting grayscale images.
![]() |
These images can also be displayed diagonally in another window by first initializing the other window and then updating the view and images with different location information.The LOCATION can also be used to create a display overlapping images. When overlapping images in Object Graphics, you must remember the last image added to the model will be in front of the previous images.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[2, 2], $
TITLE = 'The Channels of an RGB Image')
oView -> SetProperty, $ VIEWPLANE_RECT = [0., 0., imageSize]*[0, 0, 2, 2]
oGreenChannel -> SetProperty, $ LOCATION = [imageSize[0]/2, imageSize[1]/2] oBlueChannel -> SetProperty, $ LOCATION = [imageSize[0], imageSize[1]]
oWindow -> Draw, oView
The following figure shows the resulting grayscale images.
![]() |
OBJ_DESTROY, oView
IDL Online Help (March 06, 2007)