|
Image Processing : Mapping an Image onto Geometry |
|
The following Object Graphics example maps a satellite image from the Los Angeles, California vicinity onto a DEM (Digital Elevation Model) containing the area's topographical features. The realism resulting from mapping the image onto the corresponding elevation data provides a more informative view of the area's topography. The process is segmented into the following three sections:
| Note Data can be either regularly gridded (defined by a 2D array) or irregularly gridded (defined by irregular x, y, z points). Both the image and elevation data used in this example are regularly gridded. If you are dealing with irregularly gridded data, use GRIDDATA to map the data to a regular grid. |
Complete the following steps for a detailed description of the process.
| Example Code See elevation_object.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
The following steps read in the satellite image and DEM files and display the elevation data.
imageFile = FILEPATH('elev_t.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, imageFile, image
demFile = FILEPATH('elevbin.dat', $
SUBDIRECTORY = ['examples', 'data'])
dem = READ_BINARY(demFile, DATA_DIMS = [64, 64])
dem = CONGRID(dem, 128, 128, /INTERP)
DEVICE, DECOMPOSED = 0 WINDOW, 0, TITLE = 'Elevation Data' SHADE_SURF, dem
After reading in the satellite image and DEM data, continue with the next section to create the objects necessary to map the satellite image onto the elevation surface.
After reading in the image and surface data in the previous steps, you will need to create objects containing the data. When creating an IDL Object Graphics display, it is necessary to create a window object (oWindow), a view object (oView) and a model object (oModel). These display objects, shown in the conceptual representation in the following figure, will contain a geometric surface object (the DEM data) and an image object (the satellite image). These user-defined objects are instances of existing IDL object classes and provide access to the properties and methods associated with each object class.
![]() |
| Note The XOBJVIEW utility (described in Mapping an Image Object onto a Sphere) automatically creates window and view objects. |
Complete the following steps to initialize the necessary IDL objects.
oNewObject = OBJ_NEW('Class_Name') to create these objects:
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, COLOR_MODEL = 0)
oView = OBJ_NEW('IDLgrView')
oModel = OBJ_NEW('IDLgrModel')
STYLE = 2, draws the elevation data using a filled line style:
oSurface = OBJ_NEW('IDLgrSurface', dem, STYLE = 2)
oImage = OBJ_NEW('IDLgrImage', image, INTERLEAVE = 0, $
/INTERPOLATE)
INTERLEAVE = 0 indicates that the satellite image is organized using pixel interleaving, and therefore has the dimensions (3, m, n). The INTERPOLATE keyword forces bilinear interpolation instead of using the default nearest-neighbor interpolation method.
This section displays the objects created in the previous steps. The image and surface objects will first be displayed in an IDL Object Graphics window and then with the interactive XOBJVIEW utility.
oSurface -> GETPROPERTY, XRANGE = xr, YRANGE = yr, $ ZRANGE = zr xs = NORM_COORD(xr) xs[0] = xs[0] - 0.5 ys = NORM_COORD(yr) ys[0] = ys[0] - 0.5 zs = NORM_COORD(zr) zs[0] = zs[0] - 0.5 oSurface -> SETPROPERTY, XCOORD_CONV = xs, $ YCOORD_CONV = ys, ZCOORD = zs
oSurface -> SetProperty, TEXTURE_MAP = oImage, $ COLOR = [255, 255, 255]
For clearest display of the texture map, set COLOR = [255, 255, 255]. If the image does not have dimensions that are exact powers of 2, IDL resamples the image into a larger size that has dimensions which are the next powers of two greater than the original dimensions. This resampling may cause unwanted sampling artifacts. In this example, the image does have dimensions that are exact powers of two, so no resampling occurs.
| Note If your texture does not have dimensions that are exact powers of 2 and you do not want to introduce resampling artifacts, you can pad the texture with unused data to a power of two and tell IDL to map only a subset of the texture onto the surface. For example, if your image is 40 by 40, create a 64 by 64 image and fill part of it with the image data: textureImage = BYTARR(64, 64, /NOZERO)Then, construct texture coordinates that map the active part of the texture to a surface (oSurface): textureCoords = [[], [], [], []]The surface object in IDL 5.6 is has been enhanced to automatically perform the above calculation. In the above example, just use the image data (the 40 by 40 array) to create the image texture and do not supply texture coordinates. IDL computes the appropriate texture coordinates to correctly use the 40 by 40 image. |
| Note Some graphic devices have a limit for the maximum texture size. If your texture is larger than the maximum size, IDL scales it down into dimensions that work on the device. This rescaling may introduce resampling artifacts and loss of detail in the texture. To avoid this, use the TEXTURE_HIGHRES keyword to tell IDL to draw the surface in smaller pieces that can be texture mapped without loss of detail. |
oModel -> Add, oSurface oView -> Add, oModel
oModel -> ROTATE, [1, 0, 0], -90 oModel -> ROTATE, [0, 1, 0], 30 oModel -> ROTATE, [1, 0, 0], 30
oWindow -> Draw, oView
![]() |
SCALE = 1 (instead of the default value of 1/SQRT3) to increase the size of the initial display: XOBJVIEW, oModel, /BLOCK, SCALE = 1
This results in the following display.
![]() |
After displaying the model, you can rotate it by clicking in the application window and dragging your mouse. Select the magnify button, then click near the middle of the image. Drag your mouse away from the center of the display to magnify the image or toward the center of the display to shrink the image. Select the left-most button on the XOBJVIEW toolbar to reset the display.
OBJ_DESTROY, [oView, oImage]
The oModel and oSurface objects are automatically destroyed when oView is destroyed.
For an example of mapping an image onto a regular surface using both Direct and Object Graphics displays, see Mapping an Image onto a Sphere.
IDL Online Help (March 06, 2007)