|
Image Processing : Warping Images |
|
Image warping requires selection of corresponding control points in an input image and either a reference image or a regular grid. The input image is warped so that the input image control points match the control points specified in the reference image.
Using Direct Graphics, the following example warps the input image, a Magnetic Resonance Image (MRI) proton density scan of a human thoracic cavity, to the reference image, a Computed Tomography (CT) bone scan of the same region. Complete the following steps for a detailed description of the process.
| Example Code See mriwarping_direct.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
mriFile= FILEPATH('pdthorax124.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, mriFile, mriImg DEVICE, DECOMPOSED = 0 LOADCT, 0 WINDOW, 0, XSIZE = 256, YSIZE = 256, $ TITLE = 'MRI Proton Density Input Image' TV, mriImg
ctboneFile = FILEPATH('ctbone157.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, ctboneFile, ctboneImg WINDOW, 2, XSIZE = 483, YSIZE = 410, $ TITLE = 'CT Bone Scan Reference Image'
LOADCT, 20 TV, ctboneImg LOADCT, 0
Proceed with the following section to begin selecting control points.
This section describes selecting corresponding control points in the two displayed images. The array of control points (Xi, Yi) in the input image will be mapped to the array of points (Xo, Yo) selected in the reference image. The following image shows the points to be selected in the input image.
![]() |
WSET, 0
CURSOR, xi1, yi1, /DEVICE
| Note The values for xi1 and yi1 are displayed in the IDLDE Variable Watch window. If you are not running the IDLDE, you can type PRINT, xi1, yi1 to see the values. |
| Note After entering the first line and selecting the first control point in the display window, place your cursor in the IDL command line and press the Up Arrow key. The last line entered is displayed and can be easily modified. |
CURSOR, xi2, yi2, /DEVICE CURSOR, xi3, yi3, /DEVICE CURSOR, xi4, yi4, /DEVICE CURSOR, xi5, yi5, /DEVICE CURSOR, xi6, yi6, /DEVICE CURSOR, xi7, yi7, /DEVICE CURSOR, xi8, yi8, /DEVICE CURSOR, xi9, yi9, /DEVICE
WSET, 2
| Note The Xi and Yi vectors and the Xo and Yo vectors must be the same length, meaning that you must select the same number of control points in the reference image as you selected in the input image. The control points must also be selected in the same order since the point Xi1, Yi1 will be warped to Xo1, Yo1. |
The following figure displays the control points to be selected in the next step.
|
![]()
|
CURSOR, xo1, yo1, /DEVICE CURSOR, xo2, yo2, /DEVICE CURSOR, xo3, yo3, /DEVICE CURSOR, xo4, yo4, /DEVICE CURSOR, xo5, yo5, /DEVICE CURSOR, xo6, yo6, /DEVICE CURSOR, xo7, yo7, /DEVICE CURSOR, xo8, yo8, /DEVICE CURSOR, xo9, yo9, /DEVICE
Xi = [xi1, xi2, xi3, xi4, xi5, xi6, xi7, xi8, xi9] Yi = [yi1, yi2, yi3, yi4, yi5, yi6, yi7, yi8, yi9] Xo = [xo1, xo2, xo3, xo4, xo5, xo6, xo7, xo8, xo9] Yo = [yo1, yo2, yo3, yo4, yo5, yo6, yo7, yo8, yo9]
This section uses the control points defined in the previous section to warp the original MRI scan to the CT scan, using both of IDL's warping routines, WARP_TRI and POLY_2D. After outputting the warped image, it will be altered for display as a transparency in Direct Graphics.
Result = WARP_TRI(Xo, Yo, Xi, Yi, Image, OUTPUT_SIZE=vector] [, /QUINTIC] [, /EXTRAPOLATE])
set the OUTPUT_SIZE equal to the reference image dimensions since this image forms the basis of the warped, output image. Use the EXTRAPOLATE keyword to display the portions of the image which fall outside of the boundary of the selected control points:
warpTriImg = WARP_TRI(Xo, Yo, Xi, Yi, mriImg, $ OUTPUT_SIZE=[483, 410], /EXTRAPOLATE)
| Note Images requiring more aggressive warp models may not have good results outside of the extent of the control points when WARP_TRI is used with the /EXTRAPOLATE keyword. |
WINDOW, 3, XSIZE = 483, YSIZE = 410, TITLE = 'WARP_TRI image' TV, warpTriImg
You can see the how precisely the control points were selected by the amount of distortion in the resulting warped image. The following figure shows little distortion.
POLYWARP, Xi, Yi, Xo, Yo, 1, p, q
Result = POLY_2D( Array, P, Q [, Interp [, Dimx, Dimy]]
[, CUBIC={-1 to 0}] [, MISSING=value] )
Specify a value of 1 for the Interp argument to use bilinear interpolation and set DimX, DimY equal to the reference image dimensions:
warpPolyImg = POLY_2D(mriImg, p, q, 1, 483, 410)
WINDOW, 4, XSIZE = 483, YSIZE = 410, TITLE = 'Poly_2D image' TV, warpPolyImg
The following image shows little difference from the WARP_TRI image other than more accurate placement in the display window.
Direct Graphics displays in IDL allow you to display a combination of images in the same Direct Graphics window. The following steps display various intensities of the warped image and the reference image in a Direct Graphics window.
XPALETTE
In the XPALETTE utility, display a color table by selecting the Predefined button. In the resulting XLOADCT dialog, scroll down and select Hue Saturation Lightness 2. Click Done. In the XPALETTE utility, click Redraw. Compare the bone scan image, displayed in window 2, to the displayed color table. To mask out the less important background information, select a color close to that of the body color in the image.
The following figure displays a portion of the XPALETTE utility with such a selection.
![]() |
ctboneMask = BYTSCL((ctboneImg GT 55) * ctboneImg)
blendImg = BYTSCL(ctboneMask + 0.75 * warpPolyImg)
WINDOW, 5, XSIZE = 483, YSIZE = 410, TITLE = 'Blended Image' TV, blendImg
The clavicles and rib bones of the reference image are clearly displayed in the following figure.
While Direct Graphics supports displaying indexed images as transparent blended images, you could also apply alpha blending to RGB images that are output to a TrueColor display. However, creating image transparencies which retain their color information is more easily accomplished using Object Graphics. For an example of using Object Graphics to display a warped image transparency over another image see Warping Image Objects.
IDL Online Help (March 06, 2007)