Sie sind auf Seite 1von 9

Laboratory Exercises in

Image Processing: Contrast


Stretching
Introduction 2
Stretching Image Data 3
Exercise #1: Comparing Data and Stretched Values 3
Contrast Stretching 4
Exercise 2: Experimenting with Different Stretches 5
Exercise 3: Examining Data Values 7
Exercise 4: Understanding Monitors and Color 7
Self Test 9

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

Stretching Image Data


What does it mean to "stretch" image data? 
The pixels in a data file that make up an image can have any value: negative, positive, integer, or
floating point. When the image data are visualized on screen, they are displayed as brightness values for
each screen pixel. A data pixel with a larger value is brighter than one with a smaller value. However,
unlike the image data, screen pixels can only have 256 unique brightness values, varying as integers
between 0 and 255 (where 0 is black and 255 is white). Clearly this limitation prevents the data from
being displayed with brightness exactly equal to their real value. For example, how do you display a
negative data pixel or floating-point data ranging from 0 to 1? 
Stretching the image data refers to a method by which the data pixels are rescaled from their original
values into a range that the monitor can display — namely, into integer values between 0 and 255. For
example, if the image data were floating-point values that ranged from -1.0 to 1.0, the image might be
stretched such that data values of -1.0 are assigned a brightness of 0 and data with values of 1.0 are
assigned a brightness of 255. All of the intermediate data values would be assigned new stretched values
based on a simple model, or stretch type.
Commonly, a linear stretch type is used so that the stretched data values maintain the same relationship
to each other as the original data (e.g., the relative distance between two stretched values is the same as
the relative distance between the two original data values). Other stretch types use different models to
assign the intermediate values, such as Gaussian, equalization, or square root functions.
In this next exercise, you will look at the data values of an AVHRR image and compare them to the
brightness values to see the effects of a contrast stretch.

Exercise #1: Comparing Data and Stretched Values


1. From the ENVI main menu bar, select File > Open Image File. The Enter Data Filenames dialog
appears.
2. Navigate to enviintro\AVHRR, and select SE_Coast_SST.dat. Click Open.
This image comes from the NOAA-16 satellite and has a spatial resolution of 1100 m. The image
was obtained in September, 2001 and shows a large part of the Southeast coast of the U.S. The
original bands have been calibrated into sea surface temperature (SST) floating-point data in
degrees Celsius.
3. Load the single-band SST Image into a new display group.
4. From the Display group menu bar, select Tools > Cursor Location/Value. You can also double-
click in the Image window or use the Window menu to launch this tool.
5. Try to find some of the brightest and darkest pixels in the image (reposition the Image box and 
Zoom box, then use the Cursor Location/Value tool in the Zoom window). Note the data value,
the corresponding screen value (the stretched value), and the image coordinates for one of the
bright and dark pixels.
Bright pixel: coords: __________ data value: __________ screen value: __________
Dark pixel: coords: __________ data value: __________ screen value: __________

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:

Figure 1: Linear 0-255 stretch

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

Figure 2: Linear stretch

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:

Figure 3: Linear 2% stretch

Exercise 2: Experimenting with Different Stretches


1. From the Display group menu bar, select Enhance and examine the list of predefined stretches
you can apply to a display group.   

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

Exercise 3: Examining Data Values


What happens to the actual data values when the image is stretched for display? Contrast stretching an
image for display does not affect the original image data. Whenever numerical processing is performed
in ENVI, the original data from the file are used, not the contrast-stretched data that are displayed.
1. Load a gray scale image of the SST Image band into a new display group, and compare the two 
open images.
The two image displays look quite different, but the data in each display group are identical; only 
the stretch is different.
2. From the Display group menu bar in each Image window, select Tools > Pixel Locator (each 
display window has its own Pixel Locator). Arrange the windows on your screen so that you can
see both Image windows, Pixel Locators for both display groups, as well as the Cursor
Location/Value tool.
3. Using the notes you wrote down in Exercise 1, type in the sample and line value into the Pixel
Locator dialog for Display #2. Click on the Apply button in the Pixel Locator tool to move the
Zoom box.
What data value is reported by the Cursor Location/Value tool?
4. Repeat the above step for Display #1 (the display group that is virtually all black).
Do both display groups report the same data value for the bright pixel? Both display groups should
report the same data value for the same image coordinate, regardless of the stretch applied.
Optionally, repeat this test for the dark pixel you found in step 4.
If you are not finding the identical data value in both windows, be sure you are entering the same 
image coordinate for each and make sure that you are looking at the Cursor Location/Value
window immediately after you click the Apply button in the Pixel Locator, since the Cursor
Location/Value tool updates as soon as your cursor enters another window.

Exercise 4: Understanding Monitors and Color


What happens on 24-bit monitors that can show 16.7 million colors?
Even 24-bit monitors can only display 256 different brightness values. The number of colors that a
monitor can display differs from the brightness values because of the way that colors are created. Colors
are defined by a combination of individual brightness for three different color planes (red, green, and
blue).
On 8-bit systems, only 256 different screen brightness values exist; however, each brightness can be 
replaced with a color defined by a red, green, and blue triplet (an RGB triplet). Thus, 256 colors can be 
displayed. This mapping of screen brightness to colors is referred to as a Color Lookup Table, which
you will explore in more detail in a later exercise.
On 24-bit systems, you can think of the monitor as three different monitors stacked on top of each other, 
where each individual “stacked” monitor can have 256 different brightness values. If each stacked
monitor is assigned a color plane (red, green, or blue), then any given screen pixel could end up as one
of 256 x 256 x 256 (16,777,216) different colors. However, each plane still has only 256 different

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?

Das könnte Ihnen auch gefallen