DIP
DIP
Lecture 5
Contrast stretching
aims to increase (expand) the dynamic range of an image. It transforms
the gray levels in the range {0,1,, L-1} by a piecewise linear function.
The figure below shows a typical transformation used for contrast
stretching.
The locations of points
(r1, s1) and (r2, s2)
control the shape of the
transformation function.
Contrast Stretching
28
75
255
240
225
210
195
180
165
150
135
120
105
90
75
60
45
30
15
0
0
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255
(227 5040)/47
Page 1
Image Processing
Lecture 5
will be used to increase the contrast of the image shown in the figure
below:
(a)
(b)
(c)
(d)
Figure 5.3 Contrast stretching. (a) Original image. (b) Histogram of (a). (c) Result of contrast
stretching. (d) Histogram of (c).
For a given plot, we use the equation of a straight line to compute the
piecewise linear function for each line:
Page 2
Image Processing
Lecture 5
For example the plot in Figure 5.2, for the input gray values in the
interval [28 to 75] we get:
28 =
255 28
( 28)
75 28
= (227 5040)/47
28
75
< 90
90 138
> 138
255
204
153
102
51
0
15
30
45
60
75
90
105
120
135
150
165
180
195
210
225
240
255
Page 3
Image Processing
Lecture 5
(a)
(b)
(c)
(d)
Figure 5.5 (a) Low-contrast image. (b) Histogram of (a). (c) High-contrast image resulted
from applying full contrast-stretching in Figure 5.4 on (a). (d) Histogram of (c)
Gray-level slicing
Gray-level slicing aims to highlight a specific range [AB] of gray
levels. It simply maps all gray levels in the chosen range to a high value.
Other gray levels are either mapped to a low value (Figure 5.6(a)) or left
unchanged (Figure 5.6(b)). Gray-level slicing is used for enhancing
features such as masses of water in satellite imagery. Thus it is useful for
feature extraction.
Page 4
Image Processing
Lecture 5
(a)
(b)
Figure 5.6 Gray-level slicing
Page 5
Image Processing
Lecture 5
changed to black)
Histogram Equalization
is an automatic enhancement technique which produces an output
(enhanced) image that has a near uniformly distributed histogram.
For continuous functions, the intensity (gray level) in an image
may be viewed as a random variable with its probability density function
(PDF). The PDF at a gray level r represents the expected proportion
(likelihood) of occurrence of gray level r in the image. A transformation
function has the form
Page 6
Image Processing
Lecture 5
= ( ) = ( 1)
( )
( 1)
= ( 1)
= 0,1,2, , 1
The right side of this equation is known as the cumulative histogram for
the input image. This transformation is called histogram equalization or
histogram linearization.
Because a histogram is an approximation to a continuous PDF, perfectly
flat histograms are rare in applications of histogram equalization. Thus,
the histogram equalization results in a near uniform histogram. It spreads
the histogram of the input image so that the gray levels of the equalized
(enhanced) image span a wider range of the gray scale. The net result is
contrast enhancement.
Page 7
Image Processing
Lecture 5
Example:
Suppose that a 3-bit image (L = 8) of size 64 64 pixels has the gray
level (intensity) distribution shown in the table below.
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
Solution:
M N = 4096
We compute the normalized histogram:
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
( )= /
0.19
0.25
0.21
0.16
0.08
0.06
0.03
0.02
Page 8
Image Processing
Lecture 5
Normalized histogram
= 7 ( ) = 1.33
= ( )=7
= 7 ( ) + 7 ( ) = 3.08
and
= 4.55,
= 5.67,
= 6.23,
= 6.65,
= 6.86,
= 7.00
Transformation function
= 3.08 3
= 6.86 7
= 7.00 7
= 5.67 6
= 6.23 6
= 4.55 5
= 6.65 7
Page 9
Image Processing
Lecture 5
These are the values of the equalized histogram. Note that there are only
five gray levels.
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
s0 =
s1 =
s2 =
s3 =
s4 =
s5 =
s6 =
s7 =
1
3
5
6
6
7
7
7
790
1023
850
985
448
( )=
0.19
0.25
0.21
0.24
0.11
Page 10
Image Processing
Lecture 5
Figure 5.8 Left column original images. Center column corresponding histogram equalized
images. Right column histograms of the images in the center column.
Page 11
Image Processing
Lecture 5
Although all the histograms of the equalized images are different, these
images themselves are visually very similar. This is because the
difference between the original images is simply one of contrast, not of
content.
However, in some cases histogram equalization does not lead to a
successful result as shown below.
Page 12
Image Processing
Lecture 5
We clearly see that histogram equalization did not produce a good result
in this case. We see that the intensity levels have been shifted to the upper
one-half of the gray scale, thus giving the image a washed-out
appearance. The cause of the shift is the large concentration of dark
components at or near 0 in the original histogram. In turn, the cumulative
transformation function obtained from this histogram is steep, as shown
in the figure below, thus mapping the large concentration of pixels in the
low end of the gray scale to the high end of the scale.
In other cases, HE may introduce noise and other undesired effect to the
output images as shown in the figure below.
Page 13
Image Processing
Lecture 5
Page 14
Image Processing
Lecture 5
= ( ) = ( 1)
=
= ( 1)
( 1)
= 0,1,2, , 1
( )
= 0,1,2, , 1
Then round the values of G to integers in the range [0, L-1]. Store
the values of G in a table.
3. Perform inverse mapping. For every value of
so
(i.e. the
, of this
in the histogram-specified
Page 15
Image Processing
Lecture 5
Example:
Suppose the 3-bit image of size 64 64 pixels with the gray level
distribution shown in the table, and the specified histogram below.
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
Solution:
Step 1:
M N = 4096
We compute the normalized histogram:
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
( )= /
0.19
0.25
0.21
0.16
0.08
0.06
0.03
0.02
Page 16
Image Processing
Lecture 5
Normalized histogram
= 7 ( ) = 1.33
= ( )=7
= 7 ( ) + 7 ( ) = 3.08
and
= 4.55,
= 5.67,
= 6.23,
= 6.65,
= 3.08 3
= 6.86 7
= 7.00 7
= 5.67 6
= 6.23 6
= 6.86,
= 7.00
= 4.55 5
= 6.65 7
Step 2:
We compute the values of the transformation G
Page 17
Image Processing
Lecture 5
( )=7
( ) =0
( )=7
( ) = 7[ ( ) + ( )] = 0
and
( )=0 ,
( ) = 1.05 ,
( ) = 4.55 ,
( ) = 2.45
( ) = 5.95 ,
( ) = 7.00
( )
0
0
0
1
2
5
6
7
.
1
3
5
6
7
( ) is the
3
4
5
6
7
Page 18
Image Processing
Lecture 5
Step 4:
r0 = 0
r1 = 1
r2 = 2
r3 = 3
r4 = 4
r5 = 5
r6 = 6
r7 = 7
790
1023
850
656
329
245
122
81
s0 =
s1 =
s2 =
s3 =
s4 =
s5 =
s6 =
s7 =
3
4
5
6
6
7
7
7
790
1023
850
985
448
( )=
0.19
0.25
0.21
0.24
0.11
Page 19
Image Processing
Lecture 5
Page 20