|
Image Processing : Working with Masks and Image Statistics |
|
Masking (also known as thresholding) is used to isolate features within an image above, below, or equal to a specified pixel value. The value (known as the threshold level) determines how masking occurs. In IDL, masking is performed with the relational operators. IDL's relational operators are shown in the following table.
|
Operator
|
Description
|
|---|---|
|
EQ
|
Equal to
|
|
NE
|
Not equal to
|
|
GE
|
Greater than or equal to
|
|
GT
|
Greater than
|
|
LE
|
Less than or equal to
|
|
LT
|
Less than
|
For example, if you have an image variable and you want to mask it to include only the pixel values equaling 125, the resulting mask variable is created with the following IDL statement.
mask = image EQ 125
The mask level is applied to every element in the image array, which results in a binary image.
| Note You can also provide both upper and lower bounds to masks by using the bitwise operators; AND, NOT, OR, and XOR. See Bitwise Operators in the Application Programming for more information on these operators. |
The following example uses masks derived from the image contained in the worldelv.dat file, which is in the examples/data directory. Masks are derived to extract the oceans and land. These masks are applied back to the image to show only on the oceans or the land. Masks are applied by multiplying them with the original image. Complete the following steps for a detailed description of the process.
| Example Code See maskingimages.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]
image = READ_BINARY(file, DATA_DIMS = imageSize)
DEVICE, DECOMPOSED = 0 LOADCT, 38
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'World Elevation' TV, image
The following figure shows the original image, which represents the elevation levels of the world.
oceanMask = image LT 125
maskedImage = image*oceanMask
WINDOW, 1, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Oceans Mask (left) and Resulting Image (right)' TVSCL, oceanMask, 0 TV, maskedImage, 1
The following figure shows the mask of the world's oceans and the results of applying it to the original image.
![]() |
landMask = image GE 125
maskedImage = image*landMask
WINDOW, 2, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Land Mask (left) and Resulting Image (right)' TVSCL, landMask, 0 TV, maskedImage, 1
The following figure shows the mask of the land masses of the world and the results of applying it to the original image.
IDL Online Help (March 06, 2007)