Clipping Images

Clipping is used to enhance features within an image. You provide a threshold level to determine how the clipping occurs. The values above (or below) the threshold level remain the same while the other values are set equal to the level.

In IDL, clipping is performed with the minimum and maximum operators. IDL's minimum and maximum operators are shown in the following table.

Table 4-3: IDL's Minimum and Maximum Operators

Operator
Description
<

Less than or equal to

>

Greater than or equal to

The operators are used in an expression that contains an image array, the operator, and then the threshold level. For example, if you have an image variable and you want to scale it to include only the values greater than or equal to 125, the resulting clippedImage variable is created with the following IDL statement.

clippedImage = image > 125 

The threshold level is applied to every element in the image array. If the element value is less than 125, it is set equal to 125. If the value is greater than or equal to 125, it is left unchanged.

Note
When clipping is combined with byte-scaling, this is equivalent to performing a stretch on an image. See "Determining Intensity Values for Threshold and Stretch" in Chapter 9 for more information.

The following example shows how to threshold an image of Hurricane Gilbert, which is in the hurric.dat file in the examples/data directory. Two clipped images are created. One contains all data values greater than 125 and the other contains all values less than 125. Since these clipped images are grayscale images and do not use the entire 0 to 255 range, they are displayed with the TV procedure and then scaled with the TVSCL procedure, which scales the range of the image from 0 to 255. Complete the following steps for a detailed description of the process.

Example Code
See clippingimages.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering clippingimages at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT clippingimages.pro.

  1. Determine the path to the worldtmp.png file:
  2. file = FILEPATH('hurric.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    
  3. Define the image size parameter:
  4. imageSize = [440, 340] 
    
  5. Import the image from the file:
  6. image = READ_BINARY(file, DATA_DIMS = imageSize) 
    
  7. Initialize the display:
  8. DEVICE, DECOMPOSED = 0 
    LOADCT, 0 
    
  9. Create a window and display the image:
  10. WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Hurricane Gilbert' 
    TV, image 
     

    The following figure shows the original image of Hurricane Gilbert.

    Figure 4-4: Image of Hurricane Gilbert

    imgmath04.gif

  11. Clip the image to determine which pixel values are greater than 125:
  12. topClippedImage = image > 125 
    
  13. Create another window and display the clipped image with the TV (left) and the TVSCL (right) procedures:
  14. WINDOW, 1, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Image Greater Than 125, TV (left) ' + $ 
       'and TVSCL (right)' 
    TV, topClippedImage, 0 
    TVSCL, topClippedImage, 1 
     

    The following figure shows the resulting image of pixel values greater than 125 with the TV and TVSCL procedures.

    Figure 4-5: Pixel Values Greater Than 125, TV (left) and TVSCL (right)

    imgmath05.gif

  15. Clip the image to determine which pixel values are less than a 125:
  16. bottomClippedImage = image < 125 
    
  17. Create another window and display the clipped image with the TV and the TVSCL procedures:
  18. WINDOW, 1, XSIZE = 2*imageSize[0], YSIZE = imageSize[1], $ 
       TITLE = 'Image Less Than 125, TV (left) ' + $ 
       'and TVSCL (right)' 
    TV, bottomClippedImage, 0 
    TVSCL, bottomClippedImage, 1 
     

    The following figure shows the resulting image of pixel values less than 125 with the TV (left) and TVSCL (right) procedures.

    Figure 4-6: Pixel Values Less Than 125, TV (left) and TVSCL (right)

    imgmath06.gif