Image Processing Toolbox    

Intensity Adjustment

Intensity adjustment is a technique for mapping an image's intensity values to a new range. For example, rice.tif. is a low contrast image. The histogram of rice.tif, shown in Figure 10-4, indicates that there are no values below 40 or above 225. If you remap the data values to fill the entire intensity range [0, 255], you can increase the contrast of the image.

You can do this kind of adjustment with the imadjust function. The general syntax of imadjust is

where low_in and high_in are the intensities in the input image which are mapped to low_out and high_out in the output image. For example, this code performs the adjustment described above.

The first vector passed to imadjust, [0.15 0.9], specifies the low and high intensity values that you want to map. The second vector, [0 1], specifies the scale over which you want to map them. Thus, the example maps the intensity value 0.15 in the input image to 0 in the output image, and 0.9 to 1.

Note that you must specify the intensities as values between 0 and 1 regardless of the class of I. If I is uint8, the values you supply are multiplied by 255 to determine the actual values to use; if I is uint16, the values are multiplied by 65535. To learn about an alternative way to set this limits automatically, see Setting the Adjustment Limits Automatically.

This figure displays the adjusted image and its histogram. Notice the increased contrast in the image, and that the histogram now fills the entire range.

Figure 10-6: Rice.tif After an Intensity Adjustment and a Histogram of Its Adjusted Intensities

Similarly, you can decrease the contrast of an image by narrowing the range of the data, as in this call.

In addition to increasing or decreasing contrast, you can perform a wide variety of other image enhancements with imadjust. In the example below, the man's coat is too dark to reveal any detail. The call to imadjust maps the range [0,51] in the uint8 input image to [128,255] in the output image. This brightens the image considerably, and also widens the dynamic range of the dark portions of the original image, making it much easier to see the details in the coat. Note, however, that because all values above 51 in the original image get mapped to 255 (white) in the adjusted image, the adjusted image appears "washed out."

Figure 10-7: Remapping and Widening the Dynamic Range

Setting the Adjustment Limits Automatically

To use imadjust, you must typically perform two steps:

  1. View the histogram of the image to determine the intensity value limits.
  2. Specify these limits as a fraction between 0.0 and 1.0 so that you can pass them to imadjust in the [low_in high_in] vector.

For a more convenient way to specify these limits, use the stretchlim function. This function calculates the histogram of the image and determines the adjustment limits automatically. The stretchlim function returns these values as fractions in a vector that you can pass as the [low_in high_in] argument to imadjust; for example,

By default, stretchlim uses the intensity values that represent the bottom 1% (0.01) and the top 1% (0.99) of the range as the adjustment limits. By trimming the extremes at both ends of the intensity range, stretchlim makes more room in the adjusted dynamic range for the remaining intensities. But you can specify other range limits as an argument to stretchlim. See the stretchlim reference page for more information.

Gamma Correction

imadjust maps low to bottom, and high to top. By default, the values between low and high are mapped linearly to values between bottom and top. For example, the value halfway between low and high corresponds to the value halfway between bottom and top.

imadjust can accept an additional argument which specifies the gamma correction factor. Depending on the value of gamma, the mapping between values in the input and output images may be nonlinear. For example, the value halfway between low and high may map to a value either greater than or less than the value halfway between bottom and top.

Gamma can be any value between 0 and infinity. If gamma is 1 (the default), the mapping is linear. If gamma is less than 1, the mapping is weighted toward higher (brighter) output values. If gamma is greater than 1, the mapping is weighted toward lower (darker) output values.

The figure below illustrates this relationship. The three transformation curves show how values are mapped when gamma is less than, equal to, and greater than 1. (In each graph, the x-axis represents the intensity values in the input image, and the y-axis represents the intensity values in the output image.)

Figure 10-8: Plots Showing Three Different Gamma Correction Settings

The example below illustrates gamma correction. Notice that in the call to imadjust, the data ranges of the input and output images are specified as empty matrices. When you specify an empty matrix, imadjust uses the default range of [0,1]. In the example, both ranges are left empty; this means that gamma correction is applied without any other adjustment of the data.

Figure 10-9: Forest.tif Before and After Applying Gamma Correction of 0.5

Histogram Equalization

The process of adjusting intensity values can be done automatically by the histeq function. histeq performs histogram equalization, which involves transforming the intensity values so that the histogram of the output image approximately matches a specified histogram. (By default, histeq tries to match a flat histogram with 64 bins, but you can specify a different histogram instead; see the reference page for histeq.)

This example illustrates using histeq to adjust an intensity image. The original image has low contrast, with most values in the middle of the intensity range. histeq produces an output image having values evenly distributed throughout the range.

Figure 10-10: Pout.tif Before and After Histogram Equalization

The example below shows the histograms for the two images.

Figure 10-11: Histogram Before Equalization (left) and After Equalization (right)

histeq can return an additional 1-by-256 vector that shows, for each possible input value, the resulting output value. (The values in this vector are in the range [0,1], regardless of the class of the input image.) You can plot this data to get the transformation curve. For example,

Notice how this curve reflects the histograms in the previous figure, with the input values being mostly between 0.3 and 0.6, while the output values are distributed evenly between 0 and 1.

For an interactive demonstration of intensity adjustment, try running imadjdemo.


  Image Enhancement Noise Removal