Previous Getting Started with IDL: Images Next

Contrast Enhancement

In order to improve the look of an image, sometimes all that is necessary is a change in how the colors are represented. IDL provides several ways to manipulate the contrast.

Thresholding

One of the simplest contrast enhancements that can be performed on an image is thresholding. Thresholding produces a two-level mapping from all of the possible intensities into black and white. The IDL relational operators, EQ, NE, GE, GT, LE, and LT, return a value of 1 if the relation is true and 0 if the relation is false. When applied to images, the relation is evaluated for each pixel and an image of 1's and 0's results.

  1. To display the pixels in the image that have values greater than 140 as white and all others as black, as shown in the following, enter:
  2. TVSCL,MYIMAGE GT 140  
    

     

    Figure 6-6: Image with all values greater than 140 shown as white

    Figure 6-6: Image with all values greater than 140 shown as white

     

  3. Similarly, the pixels that have values less than 140 can be displayed as white, as shown, by entering the command:
  4. TVSCL,MYIMAGE LT 140  
    

     

    Figure 6-7: Image with all values less than 140 shown as white

    Figure 6-7: Image with all values less than 140 shown as white

     

    In many images, the pixels have values that are only a small subrange of the possible values. By spreading the distribution so that each range of pixel values contains an approximately equal number of members, the information content of the display is maximized, as shown in the following.

     

  5. The HIST_EQUAL function performs this redistribution on an array. To display a histogram-equalized version of myimage, enter the following:
  6. TV, HIST_EQUAL(myimage)  
    

     

    Figure 6-8: A histogram-equalized version of the image

    Figure 6-8: A histogram-equalized version of the image

Scaling Pixel Values

Another way to enhance the contrast of an image is to scale a subrange of pixel values to fill the entire range of displayed brightnesses. The > operator, the IDL maximum operator, returns a result equal to the larger of its two parameters. The following commands contrast the maximum and minimum operators.

  1. Scale pixels with a value of 100 or greater into the full range of displayed brightnesses:
  2. TVSCL,MYIMAGE > 100  
    

     

    Figure 6-9: Image with Pixels >100 Scaled to Full Range Of Brightness

    Figure 6-9: Image with Pixels >100 Scaled to Full Range Of Brightness

     

  3. Scale pixels with a value less than 140 into the full range of brightnesses.
  4. TVSCL,MYIMAGE < 140  
    

     

    Figure 6-10: Image with Pixels <140 Scaled to Full Range of Brightness

    Figure 6-10: Image with Pixels <140 Scaled to Full Range of Brightness

     

  5. The minimum and maximum operators can be used together for more complicated contrast enhancements. Set the minimum brightness to 140, set the maximum brightness to 200, scale myimage and display it by entering:
  6. TVSCL,MYIMAGE >140<200  
    

     

    Figure 6-11: Image Scaled from 140 to 200

    Figure 6-11: Image Scaled from 140 to 200


Note
Although this command illustrates the use of the IDL minimum and maximum operators, the same function can be executed more efficiently by IDL with the command:

TV, BYTSCL(MYIMAGE,MIN=140,MAX=200,TOP=!D.TABLE_SIZE)

  IDL Online Help (March 06, 2007)