|
Image Processing : Working with Masks and Image Statistics |
|
Locating pixel values within an image helps to segment features. You can use IDL's WHERE function to determine where features characterized by specific values appear within the image. The WHERE function returns a vector of one-dimensional indices, locating where the specified values occur within the image. The values are specified with an expression input argument to the WHERE function. The expression is defined with the relational operators, similar to how masking is performed. See Masking Images for more information on relational operators.
Since the WHERE function only returns the one-dimensional indices, you must derive the column and row locations with the following statements.
column = index MOD imageSize[0] row = index/imageSize[0]
where index is the result from the WHERE function and imageSize[0] is the width of the image.
The WHERE function returns one-dimensional indices to allow you to easily use these results as subscripts within the original image array or another array. This ability allows you to combine values from one image with another image. The following example combines specific values from the image within the worldelv.dat file with the image within the worldtmp.png file. The worldelv.dat file is in the examples/data directory and the worldtmp.png file is in the examples/demo/demodata directory. First, the temperature data is shown in the oceans and the elevation data is shown on the land. Then, the elevation data is shown in the oceans and the temperature data is shown on the land. Complete the following steps for a detailed description of the process.
| Example Code See combiningimages.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
file = FILEPATH('worldelv.dat', $
SUBDIRECTORY = ['examples', 'data'])
imageSize = [360, 360]
elvImage = READ_BINARY(file, DATA_DIMS = imageSize)
DEVICE, DECOMPOSED = 0 LOADCT, 38
WINDOW, 0, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'World Elevation (left) and Temperature (right)' TV, elvImage, 0
file = FILEPATH('worldtmp.png', $
SUBDIRECTORY = ['examples', 'demo', 'demodata'])
tmpImage = READ_PNG(file)
TV, tmpImage, 1
The following figure shows the original world elevation and temperature images.
![]() |
ocean = WHERE(elvImage LT 125)
image = tmpImage
image[ocean] = elvImage[ocean]
WINDOW, 1, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Temperature Over Land (left) ' + 'and Over Oceans (right)' TV, image, 0
land = WHERE(elvImage GE 125)
image = tmpImage
image[land] = elvImage[land]
TV, image, 1
The following figure shows two possible image combinations using the world elevation and temperature images.
![]() |
| Tip You could also construct the same image using masks and adding them together. For example, to create the second image (temperature over oceans), you could have done the following: mask = elvImage GE 125For large images, using masks may be faster than using the WHERE routine. |
IDL Online Help (March 06, 2007)