Main Content

imcontrast

Adjust Contrast tool

Description

Use the imcontrast function to create an Adjust Contrast tool. The Adjust Contrast tool enables you to interactively adjust the contrast and brightness of a displayed grayscale image. For more information about using the tool, see Tips.

Adjust Contrast tool with sliders and editable fields that enable you to adjust the histogram of pixel values.

Note

The Adjust Contrast tool adjusts the values of the pixels used to display the image but does not change the actual image data. If you want to change the image data, use the imadjust function.

imcontrast creates an Adjust Contrast tool in a separate figure that is associated with the grayscale image in the current figure.

example

imcontrast(h) creates an Adjust Contrast tool associated with the image in the graphics container h.

example

hTool = imcontrast(___) returns the figure hTool containing the Adjust Contrast tool.

Examples

collapse all

Display an image and adjust the contrast of the image.

imshow("pout.tif")
imcontrast

Adjust Contrast tool opened for imshow figure displaying pout image

Read an image into the workspace and define the handle of the figure as h1. Open a second figure window and define the handle of that figure as h2. Adjust the contrast of the first figure by specifying h1 in the call to imcontrast.

h1 = figure;
imshow("pout.tif")
h2 = figure;
imshow("coins.png")
imcontrast(h1)

Adjust Contrast tool opened for the figure with the specified handle

Input Arguments

collapse all

Graphics object containing the image, specified as a Figure, Panel, Axes, or Image object. If h is an axes or figure, then imcontrast uses the first image returned by findobj(h,Type="image").

Output Arguments

collapse all

Adjust Contrast tool, returned as a Figure object.

Tips

  • The Adjust Contrast tool displays a histogram of pixel values and information about the data range and display range.

    • The data range corresponds to the underlying pixel values of the image. The data range is a fixed property of the image data, and, by default, does not change when you adjust the display range using the Adjust Contrast tool.

    • The display range controls the display of the image. Any pixel with a value less than or equal to the minimum value of the display range displays as black. Any pixel with a value greater than or equal to the maximum value displays as white. In the Adjust Contrast tool, the red-tinted box overlaid on the histogram corresponds to the display range.

  • You can use the Adjust Contrast tool to adjust the display range of the image in these ways.

    DescriptionImage

    Adjust the minimum and maximum values of the display range by dragging the left and right edges of the red window. Change the center of the window by dragging the dotted line in the interior of the window.

    Interactively adjust display window by dragging red window limits

    Enter specific values in the Window section. You can also define the minimum or maximum value by clicking the dropper button next to the corresponding field. When you do this and move the pointer over the image, the pointer becomes an eye dropper shape. Position the eye dropper shape over the pixel with the value that you want to be the minimum or maximum and left-click.

    Manually enter display window values

    Scale the display range automatically. Select Match Data Range to make the display range equal to the data range of the image. Select Eliminate outliers to saturate an equal percentage of pixels at the top and bottom of the display range. By default, the tool eliminates 2%, so the top 1% and the bottom 1% of pixel values. This is equivalent to the operation performed by the stretchlim function.

    Automatically scale display range

  • When you use the Adjust Contrast tool, imcontrast adjusts the contrast of the displayed image by modifying the axes CLim property. To modify the actual pixel values in the target image, select Adjust Data. You cannot select Adjust Data until you make a change to the contrast of the image.

  • The Adjust Contrast tool can process grayscale images of class double and single with data ranges beyond the default display range of [0, 1]. For these images, imcontrast sets the histogram limits to fit the image data range, with padding at the upper and lower bounds.

Version History

Introduced before R2006a