Digital Image Processing CPE3643
Lecture 6:
Histogram equalization and
processing
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 1
In the last lecture
▪ Contrast Stretching
▪ Piecewise linear contrast stretching
▪ Image Histogram
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 2
1
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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 4
2
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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 5
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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 6
3
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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 7
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/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 8
4
Histogram equalization examples
Input image Output image
Input histogram and cdf Output histogram and cdf
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 9
Histogram equalization examples
Low contrast image Output image
Equalized histogram
Equalized histogram
high contrast image Output image
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 10
10
5
Histogram equalization examples
Dark input image Output image
Equalized histogram
Equalized histogram
Bright input image Output image
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 11
11
Histogram equalization examples
Transformation functions for
histogram equalization
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 12
12
6
Histogram equalization examples
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 13
13
Histogram equalization examples
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 14
14
7
Histogram equalization examples
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 15
15
Histogram equalization examples
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 16
16
8
Local histogram processing
The histogram processing methods mentioned up to now
are global transformation where:
▪ Function is designed according to the gray-level
distribution over an entire image
▪ Global transformation methods may not be suitable for
enhancing details over small areas (where number of
pixels may have negligible influence on designing the
global transformation function)
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 17
17
Local histogram processing
Implementation steps
1: Define a square or rectangular neighborhood (block), compute the
histogram in the local block
2: Generate the transformation function by histogram equalization or
specification and perform the gray level mapping for each pixel
3: Move the center of the block to an adjacent pixel location and
repeat the procedure
Note
▪ Histogram can be updated each time without re-computing the
histogram over all pixels in the new block
▪ If utilizing non-overlapping region shift, the processed image
usually has an undesirable checkerboard effect
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 18
18
9
Local histogram equalization example
Result of Global Result of local
Original Image Histogram Histogram
Equalization Equalization
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 19
19
Local histogram equalization example
Original Image Result of local Histogram
Equalization using 9x9
window
3/27/2025 Capital University of Science and Technology Digital Image Processing CPE3643 20
20
10