Contrast Stretching
Contrast Stretching
Contrast Stretching
1
Laboratory Exercises in Image Processing: Contrast Stretching
Introduction
These exercises introduce you to fundamentals of stretching image data. In this section, you will:
l Learn why image data are stretched when displayed on a screen
l See the effects of different contrast stretches on a remote sensing image
l Understand how color monitors work with different ranges of colors
2
Laboratory Exercises in Image Processing: Contrast Stretching
3
Laboratory Exercises in Image Processing: Contrast Stretching
Contrast Stretching
The stretch used to rescale image data into brightness values can make a drastic difference in the way
that the image appears. You can adjust the parameters of the stretch in order to maximize the
information content of the display for the features in which you are most interested. This process is
referred to as contrast stretching because it changes contrast in the image. Contrast refers to the relative
differences in the brightness of the data values (i.e., increasing contrast means that the dark pixels are
darker, and the bright pixels are brighter, so the brightness difference between the two increases).
For example, consider an image whose data numbers (DN) are integers that range between 35 and 85
(51 different data values). If this image was stretched with a simple “one-to-one” model where a data
value of 0 is assigned 0 brightness, and a data value of 255 is assigned 255 brightness, then the image
display is quite dim (since the brightest pixel is only a brightness of 85). This linear 0-255 stretch
produces a low-contrast image because a difference in data value of one unit is represented by a
difference in brightness of one unit. Furthermore, much of the range of available screen brightness is not
being used because there are only 51 different values in the image data (there are no pixels with a
brightness between 51 and 255, so these brightness values are unused). Following is an example:
The image contrast could be maximized by assigning a brightness of 0 to the minimum data value of 35,
a brightness of 255 to the maximum data value of 85, and linearly stretching the remaining 49 data
values through the rest of the available brightness range. This increases the contrast because adjacent
data values now differ by several units of brightness rather than just 1, making it easier to visually
distinguish slight differences in the data values. Following is an example:
4
Laboratory Exercises in Image Processing: Contrast Stretching
Through careful adjustment of the image stretch, it is possible to highlight certain features in an image.
ENVI provides several sophisticated tools for this purpose.
ENVI’s default stretch (defined in the ENVI configuration file) is a 2% linear stretch, where the image
histogram is computed and the cumulative 2% and 98% tails are determined. Then the data value that
defines the threshold for the 2% tail is assigned a brightness of 0, the data value that defines the 98% tail
is assigned a brightness of 255, and a linear model is used to assign the intermediate values. In order to
speed processing, the initial stretch (the very first time the image is displayed) is computed using the
data contained only in the Scroll window. The following figure shows how a linear 2% stretch works:
5
Laboratory Exercises in Image Processing: Contrast Stretching
Several contrast stretches can be applied to the displayed image without having to manually
define the parameters for the stretch. Each of these predefined stretches is based on image
statistics, so there are three versions of each: one that computes the histogram statistics from only
the data in the Image window, one that uses only the Scroll window data, and one that uses only
the Zoom window data.
l The Linear stretch sets the data minimum and maximum to screen values (brightness) of 0
and 255 and stretches all other data values linearly between 0 and 255.
l The Linear 0-255 stretch sets a data value of 0 to a screen value of 0 and a data value of
255 to a screen value of 255 and stretches all data values between 0 and 255 linearly. This
is the same as applying no stretch to the data.
l The Linear 2% stretch sets the highest and lowest 2% of data values to screen values of 0
and 255, and it stretches all other data values linearly (the same method as ENVI’s default
stretch).
l The Gaussian stretch sets the data mean value to a screen value of 127, the data value
three standard deviations below the mean value to a screen value of 0, and the data value
three standard deviations above the mean value to a screen value of 255. Intermediate data
values are assigned screen values using a Gaussian curve.
l The Equalization stretch scales the data to equalize the number of DNs in each display
histogram bin.
l The Square Root stretch takes the square root of the input histogram and applies a linear
stretch.
2. Move the Image box in the Scroll window to an area along the coast. From the Display group
menu bar, select Enhance > [Image] Equalization. What features does this equalization stretch
highlight?
3. Move the Image box in the Scroll window to the lower right-hand part of the image. This part of
the image contains many clouds. Perform another [Image] Equalization stretch.
What happened to the definition of the coastline on the left side of the image? Why do you think
this happened?
Because the data in the Image window have changed, the image statistics changed and the
applied stretch was quite different.
4. Find an area in the image with the very brightest pixels (there is a small area around image
coordinate [570, 1200] that is nearly saturated with white pixels). Zoom in on this white patch so
that the Zoom window contains mostly white pixels.
5. Using the Cursor Location/Value tool, note that even though the pixels in the Zoom window all
appear to have the same brightness, they actually do have slightly different data values.
6. From the Display group menu bar, select Enhance > [Zoom] Equalization.
This approach should display some of the more subtle data variations in only the very brightest
pixels of this cloud. Using the Zoom stretch is a fast way to explore image data for very specific,
small-scale features.
6
Laboratory Exercises in Image Processing: Contrast Stretching
7
Laboratory Exercises in Image Processing: Contrast Stretching
brightness values. Even on hardware that can support 24-bit color, where more than 16.7 million
different colors can be displayed simultaneously, image data going into each color plane must still be
stretched before it can be displayed.
1. From the ENVI main menu bar, select File > Open Image File. The Enter Filenames dialog
appears.
2. Navigate to enviintro\Landsat, and select bighorn.dat. Click Open.
3. Replace Display #1 with a Band (5,4,3) RGB composite from bighorn.dat.
4. Use the Cursor Location/Value tool to look at the RGB data and screen values. Note that each
color channel's band is stretched independently into an integer screen brightness value.
Because a 24-bit monitor can display any combination of colors simultaneously, running ENVI in this
mode allows you to display an unlimited number of RGB images at the same time. This behavior is not
possible when running on a monitor in 8-bit mode because there are only 256 total colors that can be
displayed (one for each screen brightness value).
However, ENVI is able to emulate 24-bit true color display properties even on 8-bit monitors by
breaking the system color table into multiple, small color tables, with each color table “subset” defined
by the colors needed to display one of the RGB image windows. The size of each color table subset is
defined in the ENVI configuration file (which you can change by choosing the File > Preferences >
Display Defaults tab).
ENVI’s default is 40 colors per gray scale and 64 colors per RGB, which means when displaying a
RGB image on an 8-bit monitor, the image data for each color plane are stretched into only 64 different
values (instead of 256). A 64-entry color lookup table is defined then by the stretched image’s RGB
triplets.
8
Laboratory Exercises in Image Processing: Contrast Stretching
Self Test
1. Would a Linear 0-255 stretch show much contrast in an image with only 30 different data values?
Why or why not?
2. Can you think of an example where a 2% linear stretch would be helpful in highlighting features
in an image?
3. When you perform any type of numerical processing in ENVI, does ENVI use the original data
from the image or the contrast-stretched values?
4. How many different colors can be displayed on a 24-bit monitor? How many different brightness
values can be displayed?
5. What term is used to describe the mapping of screen brightness values to colors in ENVI?