Adjusting Image Contrast Using the Adjust Contrast Tool

Understanding Contrast Adjustment

An image lacks contrast when there are no sharp differences between black and white. Brightness refers to the overall lightness or darkness of an image.

To change the contrast or brightness of an image, the Adjust Contrast tool performs contrast stretching. In this process, pixel values below a specified value are displayed as black, pixel values above a specified value are displayed as white, and pixel values in between these two values are displayed as shades of gray. The result is a linear mapping of a subset of pixel values to the entire range of grays, from black to white, producing an image of higher contrast.

The following figure shows this mapping. Note that the lower limit and upper limit mark the boundaries of the window, displayed graphically as the red-tinted window in the Adjust Contrast tool — see Starting the Adjust Contrast Tool

Relationship of Pixel Values to Display Range

The Adjust Contrast tool accomplishes this contrast stretching by modifying the CLim property of the axes object that contains the image. The CLim property controls the mapping of image pixel values to display intensities.

By default, the Image Tool sets the CLim property to the default display range according to the data type. For example, the display range of an image of class uint8 is from 0 to 255. When you use the Adjust Contrast tool, you change the contrast in the image by changing the display range which affects the mapping between image pixel values and the black-to-white range. You create a window over the range that defines which pixels in the image map to the black in the display range by shrinking the range from the bottom up.

Starting the Adjust Contrast Tool

This section describes how to use the Adjust Contrast tool in the Image Tool.

  1. View an image in the Image Tool.

    imtool('pout.tif')

    You can also use the Adjust Contrast tool independent of the Image Tool by calling the imcontrast function.

  2. Click Adjust Contrast in the Image Tool toolbar, or select the Adjust Contrast option from the Image Tool Tools menu. The Adjust Contrast tool opens in a separate window containing a histogram of the image displayed in the Image Tool. The histogram shows the data range of the image and the display range of the image. The data range is the range of intensity values actually used in the image. The display range is the black-to-white mapping used to display the image, which is determined by the image class. The Adjust Contrast tool works by manipulating the display range; the data range of the image remains constant.

    For example, in the following figure, the histogram for the image shows that the data range of the image is 74 to 224 and the display range is the default display range for the uint8 class, 0 to 255. The pixel values for the image are clustered in the middle of the display range. Adjusting the contrast spreads the pixel values across the display range, revealing much more detail in the image.

    To adjust the contrast of the image, you can manipulate the red-tinted rectangular box, called a window, that the Adjust Contrast tool overlays on the histogram. By changing the size and position of this window using the mouse, you can modify the display range of the image and improve its contrast and brightness — see Using the Histogram Window to Adjust Image Contrast.

Using the Histogram Window to Adjust Image Contrast

To adjust image contrast using the Adjust Contrast tool, you manipulate the size of the red-tinted window displayed over the histogram, using any of the following methods.

The following figure shows these methods of adjusting contrast. The Image Tool updates the display range values displayed in the lower right corner of the Image Tool as you change the size of the window.

Using the Window/Level Tool to Adjust Image Contrast

To start the Window/Level tool, click Window/Level in the Image Tool toolbar.

Using the Window/Level tool, you can change the contrast and brightness of an image by simply dragging the mouse over the image. Moving the mouse horizontally affects contrast; moving the mouse vertically affects brightness. Note that any contrast adjustments you make using the Window/Level tool are reflected immediately in the Adjust Contrast tool. For example, if you increase the brightness, the window in the Adjust Contrast moves over the histogram.

The following table summarizes how these mouse motions affect the size and position of the window in the Adjust Contrast tool.

Mouse Motion

 

Effect

Horizontally to the left

Shrinks the window from both sides.

Horizontally to the right

Expands the window from both sides.

Vertically up

Moves the window to the right over the histogram, increasing brightness.

Vertically down

Moves the window to the left over the image histogram, decreasing brightness.

To stop the Window/Level tool, click on the Window/Level button in the Image Tool toolbar, or click any of the navigation buttons in the toolbar.

Example: Adjusting Contrast with the Window/Level Tool

  1. Read an image from a sample DICOM file included with the toolbox.

    I = dicomread('CT-MONO2-16-ankle.dcm');
  2. View the image data using the Image Tool. Because the image data is signed 16-bit data, this example uses the autoscaling syntax.

    imtool(I,'DisplayRange',[])

  3. Click the Window/Level button to start the tool, or select Window/Level from the Tools menu in the Image Tool.

  4. Move the pointer over the image. The pointer changes to the Window/Level cursor .

  5. Click and drag the left (or right) mouse button and move the pointer horizontally to the left or right to adjust the contrast, or vertically up or down to change the brightness.

Modifying Image Data

By default, the Adjust Contrast tool adjusts the values of the pixels used to display the image in the Image Tool but does not change the actual image data. To modify pixel values in the image to reflect the contrast adjustments you made, you must click the Adjust Data button.

The following example illustrates this process.

  1. Display an image in the Image Tool. The example opens an image from a file.

    imtool('moon.tif');
  2. Start the Adjust Contrast tool by clicking the Adjust contrast button, , or by selecting Adjust Contrast from the Tools menu in the Image Tool.

  3. Adjust the contrast of the image. Use one of the mechanisms provided by Adjust Contrast tool, such as resizing the window over the histogram. See Using the Histogram Window to Adjust Image Contrast. You can also adjust contrast using the Window/Level tool, moving the pointer over the image.

  4. Adjust the image data to reflect the contrast adjustment you just made. Click the Adjust Data button in the Adjust Contrast Tool. When you click the Adjust Data button, the histogram will update. You can then adjust the contrast again, if necessary. If you have other interactive modular tool windows open, they will update automatically to reflect the contrast adjustment.

Saving the Modified Image Data

By default, if you close the Image Tool, it does not save the modified image data. To save these changed values, use the Save As option from the Image Tool File menu to store the modified data in a file or use the Export to Workspace option to save the modified data in a workspace variable.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS