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. Contrast adjustment works by manipulating the display range of the image. Pixels with value equal to or less than the minimum value of the display range appear black. Pixels with value equal to or greater than the maximum value of the display range appear white. Pixels within the display range appear as a smooth gradient of shades of gray. Adjusting the contrast spreads the pixel values across the display range, revealing much more detail in the image.
The default display range of an image is determined by the image class. For instance, the
display range for images with data type
uint8 is 0 to 255. If the
data range, or actual minimum and maximum pixel values of the image
data, is more narrow than the display range, then the displayed image does not display all
shades of gray from black to white. In this case, you can improve the image contrast by
shrinking the display range to match the data range. To highlight certain image features, you
can further shrink the display range to be less than the data range.
The Image Viewer app offers two tools that enable you to change the contrast or brightness of an image interactively. The Window/Level tool enables you to change contrast and brightness by simply dragging the mouse over the image. The Adjust Contrast tool displays a histogram of image pixel values and graphical representation of the display range so that you can see how the display range relates to pixel values.
After you open an image in Image Viewer, open the Adjust Contrast tool by clicking Adjust Contrast in the Image Viewer toolbar. For more information about opening an image in Image Viewer, see Open Image Viewer App.
The Adjust Contrast tool displays a histogram of pixel values and information about the data range. The data range is a fixed property of the image data and does not change when you adjust the display range using the Adjust Contrast tool. The Adjust Contrast tool also displays a red-tinted rectangular box, called a window, overlaid on the histogram. The window directly corresponds to the display range of the image. The tool also shows the precise values of the precise values of the range and location of the window on the histogram.
For example, in the figure, the histogram for the image shows that the data range of the
image is 7 to 253. The display range is the default display range for the
uint8 data type, 0 to 255. Therefore, no pixels appear as black or
white. Further, the histogram shows that many pixel values are clustered in the middle of
the display range, which explains why it is challenging to distinguish between the
medium-gray pixel values.
To increase the contrast of the image, narrow the range of pixel values. To increase the brightness of an image, shift the range towards large pixel values. There are three ways to adjust the display range of the image.
You can adjust the display range interactively by manipulating the window. Adjust the minimum and maximum value of the display range by clicking and dragging the left and right edges of the window. Change the position of the window by clicking and dragging the interior of the window.
You can enter specific values for the extent, width, and center of the window. You can also define these values by clicking the dropper button associated with these fields. When you do this, the pointer becomes an eye dropper shape. Position the eye dropper pointer over the pixel in the image that you want to be the minimum (or maximum) value and click the mouse button.
You can let the Adjust Contrast tool scale the display range automatically. When
you select the Match data range option, the tool makes the
display range equal to the data range of the image. When you select the
Eliminate outliers option, the tool removes an equal
percentage of pixels from the top and bottom of the display range. By default, the
tool eliminates 2% of pixels, in other words, the top 1% and the bottom 1% of pixels.
(You can perform this same operation using the
The display range of the image displayed in the Image Viewer window updates in real time when you change the display range. Image Viewer also updates the display range values displayed in the lower right corner of the app window.
For example, in the figure, the window indicates that the display range of the image is 12 to 193. Bright pixels appear much brighter than in the original image. There is better contrast between pixels with similar gray values, such as for the pillars and roof of the domed buildings.
To start the Window/Level tool, click Window/Level in the Image Viewer toolbar or select the Window/Level option from the Image Viewer Tools menu.
Move the pointer over the image. The pointer changes to the Window/Level cursor . To adjust the image contrast, click and drag the mouse horizontally. To adjust image brightness, click and drag the mouse vertically.
If you also have the Adjust Contrast tool open, then contrast adjustments you make using the Window/Level tool immediately adjust the window in the Adjust Contrast tool. For example, if you increase the brightness using the Window/Level tool, then the window in the Adjust Contrast tool shifts to the right.
When you close the Adjust Contrast tool, the Window/Level tool remains active. To stop the Window/Level tool, click the Window/Level button or any of the navigation buttons in the Image Viewer toolbar.
The Adjust Contrast tool and Window/Level tool adjust the values of the pixels used to display the image in Image Viewer but do not change the actual image data.
When using the Adjust Contrast tool, you can modify pixel values in the image to reflect the contrast adjustments by clicking the Adjust Data button. When you click the Adjust Data button, the histogram updates. 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.
The Adjust Data button is unavailable until you make a change to the contrast of the image.
When you close Image Viewer, the app does not save the modified image data. To save these changed values, use the Save As option from the Image Viewer 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. For more information, see Save and Export Results.