Expanding Image Contrast

While making adjustments to brightness and contrast is often the first thing users try to do to digitized images, that is a poor strategy. Problems of color adjustment, nonuniform illumination, and noise should be corrected first as shown above. That will make those procedures more consistent and will also allow for a greater range of contrast adjustment afterwards.

The image histogram is a vitally important tool for understanding and adjusting image contrast. As shown in the Histogram Displays interactive Java tutorial, this is a plot of the number of pixels (or the fraction of the image area) as a function of the brightness level. For color images, the average of red, green and blue, or the weighted luminance that corresponds to human visual response (approximately 25 percent * red + 60 percent * blue + 10 percent * red), or any of the various color space axes shown above, may be used. The cumulative histogram, which can also be selected in the example, shows the integral of the histogram and is used for some of the adjustments shown below.

Interactive Java Tutorial

Histogram Displays

Explore a variety of histogram displays.

Another useful tool, particularly when used in conjunction with the histogram, is the transfer function. This is a plot showing the original pixel values on the horizontal axis and the new value after adjustment on the vertical axis. In the Image Contrast Adjustment interactive Java tutorial, adjusting the gain (contrast) and brightness (level) changes the slope and position of the transfer function, and shifts the values in the image and histogram.

Interactive Java Tutorial

Image Contrast Adjustment

Explore how to adjust image contrast and brightness by using a linear transfer function.

Setting the contrast and brightness to get maximum contrast without significant clipping of values to white or black is difficult. It is generally better to use the image histogram to set limits that maximize the image contrast. If this is done on individual color channels, it can produce unwanted color shifts in the image. Instead, the image should be converted to a different color space such as HSI or LAB where the brightness can be adjusted without altering colors, and then the result converted back for correct display.

Clipping of more than a tiny fraction of the pixels to black and or white should be avoided since those pixels lose any information they may have had in the original image. It is better to acquire an image with slightly less than full contrast rather than one in which significant areas exceed the dynamic range of the camera and are clipped to black or white. The Levels Adjustment interactive Java tutorial shows the effect of stretching the contrast to limits based on allowing a small fraction of the pixels to be clipped.

Interactive Java Tutorial

Levels Adjustment

Examine how contrast can be improved with controlled histogram clipping.

Nonlinear functions selectively expand contrast in one part of the brightness range by contracting contrast elsewhere. This can also be used to compensate for the characteristics of the acquisition device, which may be linear, logarithmic, or have some other response. These adjustments are best understood in terms of the transfer function. In the Image Contrast Adjustment interactive Java tutorial, the slider changes the shape of the transfer function without shifting the midpoint or end points. Applying such changes to the individual RGB channels can produce color shifts, and so operating on the intensity only while leaving color alone is the preferred method.

The cumulative histogram, illustrated above, varies from 0 to 100 percent. If the cumulative histogram is used as the transfer function it produces an image that has brightness values spread out to cover the entire range available. As shown in the Histogram Equalization interactive Java tutorial, the new cumulative histogram becomes a straight line, and peaks in the histogram are spread out so that small differences become visible. Comparison of images acquired with varying conditions, including changing specimen density, may be facilitated.

Interactive Java Tutorial

Histogram Equalization

Evaluate the application of histogram equalization in improving image contrast.

Human vision detects detail and differences based on a local percentage difference (a minimum of a few percent under most conditions). A difference between brightness values of 20 and 40 is 100 percent, but between 220 and 240 is less than 10 percent. Consequently, it is more difficult to see detail in the bright areas of images than in the dark areas. Photographers have long known that some details are easier to see in negatives. Reversing the contrast in a digital image is accomplished by subtracting the pixel value from 255 (white), as shown in the Complement Image interactive Java tutorial. This is usually done for the red, green and blue values individually, but in some cases it is more useful to reverse the intensity and leave the colors unchanged. Many programs call this operation “inverse” but of course it is not the arithmetic inverse (= 1/value).