Masking Images
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.
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. Run the example procedure by entering maskingimages at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT maskingimages.pro.
- Determine the path to the file:
- Initialize the image size parameter:
- Import the image from the file:
- Initialize the display:
- Create a window and display the image:
- Make a mask of the oceans:
- Multiply the ocean mask by the original image:
- Create another window and display the mask and the results of the multiplication:
- Make a mask of the land:
- Multiply the land mask by the original image:
- Create another window and display the mask and the results of the multiplication:
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'World Elevation' TV, imageThe following figure shows the original image, which represents the elevation levels of the world.
WINDOW, 1, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Oceans Mask (left) and Resulting Image (right)' TVSCL, oceanMask, 0 TV, maskedImage, 1The following figure shows the mask of the world's oceans and the results of applying it to the original image.


