0% found this document useful (0 votes)
0 views

lecture5 computer archers notes

Lecture 5 of the Digital Image Processing course covers histogram, contrast stretching, and histogram equalization techniques. It explains how contrast stretching enhances low-contrast images by increasing the dynamic range of gray levels and introduces histogram equalization as a method to achieve a uniform distribution of gray levels in an image. Various transformation functions and examples illustrate the application of these techniques in digital image processing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

lecture5 computer archers notes

Lecture 5 of the Digital Image Processing course covers histogram, contrast stretching, and histogram equalization techniques. It explains how contrast stretching enhances low-contrast images by increasing the dynamic range of gray levels and introduces histogram equalization as a method to achieve a uniform distribution of gray levels in an image. Various transformation functions and examples illustrate the application of these techniques in digital image processing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Digital Image Processing CPE3643

Lecture 5:

Histogram, Contrast Stretching


and Histogram Equalization

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 1

Contrast Stretching

Contrast stretching
Goal:
Increase the dynamic range of the gray levels for low contrast
images

Low-contrast images can result from


– poor illumination
– lack of dynamic range in the imaging sensor
– wrong setting of a lens aperture during image acquisition

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 2

1
Contrast stretching through histogram
If rmax and rmin are the maximum and minimum gray level of the input
image and L is the total gray levels of output image
The transformation function for contrast stretching will be
 
s = T (r ) = (r − rmin )
L

 rmax − rmin 

rmin rmax

0 L-1
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 3

Piecewise-linear transformation: contrast stretching


Method

where a1, a2, and a3 control the result of contrast stretching


if a1 = a2 = a3 = 1 no change in gray levels
if a1 = a3 = 0 and r1 = r2, T(*) is a thresholding function,
the result is a binary image
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 4

2
Contrast Stretching Example

Form of
Transformation Original low-
function contrast image

Result of Result of
contrast thresholding
stretching

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 5

Histogram equalization: continuous case


▪ Idea: To find a non-linear transformation
s = T (r)
to be applied to each pixel of the input image f(x,y), such that a
uniform distribution of gray levels in the entire range results for
the output image g(x,y).

▪ Assuming ideal, continuous case, with normalized histograms


– that 0  r  1 and 0  s  1
– T(r) is single valued i.e., there exists r= T-1(r)
– T(r) is monotonically increasing

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 6

3
Single valued monotonically increasing function
A function T(r) is monotonically increasing
if T(r1) < T(r2) for r1 < r2,
and monotonically decreasing
if T(r1) > T(r2) for r1 < r2.

Example of a transformation function


which is both single valued and
monotonically increasing
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 7

Background (probability distribution)


▪ Assume continuous random variables
Cumulative Distribution Function (cdf)
▪ The probability that the random variable is less than or equal to a
specified constant a. We write this as

for all values of a (i.e., −  < a < ),

▪ The probability density function (pdf) or density function of


random variable x is defined as the derivative of the cdf:

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 8

4
Histogram equalization: continuous case
▪ Fr(r) and Fs(s) : cdfs of original and transformed gray levels r and s.
▪ pr(r) and ps(s) : pdfs of original and transformed gray levels r and s.
For strictly monotonically increasing transformation function
Fs(s) = Fr(r) or ps(s) ds = pr(r) dr
Goal of histogram equalization:
Gray levels are uniformly distributed
i.e. pdf ps(s) = 1 over the range 0  s  1
 dr  ds dT (r )
ps ( s) = pr (r )  = 1 or pr (r ) = =
 ds  dr dr
r
 s = T (r ) =  pr ( )d
0

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 9

Histogram equalization
If the following transformation function is used
r
s = T (r ) =  pr ( )d for 0  r 1
0
Then the pdf ps(s) = 1 over the range 0  s  1

In words
If we select T(r) as the cumulative distribution of r
Then the output image will have a uniform pdf of gray levels

Now Consider
1. a digital (gray level) case
2. the gray levels 0  r  L −1
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 10

10

5
Histogram equalization: Discrete case
The discrete approximation of the transformation
function for histogram equalization is:
k
sk = T (rk ) =  pr (r j ) for 0  k  L − 1
j =0

nj L −1

where pr (rj ) = , j = 0,........,L − 1 and n =  n j


n j =0
nj : number of pixels with gray level rj
n : total number of pixels
Note: For digital images, gray-level pdf cannot be
exactly uniform after histogram equalization
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 11

11

Histogram equalization examples


Input image Output image

Input histogram and cdf Output histogram and cdf


3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 12

12

6
Histogram equalization examples
Low contrast image Output image

Equalized histogram

Equalized histogram
high contrast image Output image

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 13

13

Histogram equalization examples


Dark input image Output image

Equalized histogram

Equalized histogram
Bright input image Output image

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 14

14

7
Histogram equalization examples

Transformation functions for


histogram equalization
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 15

15

Histogram equalization examples

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 16

16

8
Histogram equalization examples

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 17

17

Histogram equalization examples

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 18

18

9
Histogram equalization examples

3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 19

19

10

You might also like