You are on page 1of 22

CS-407:

Digital Image Processing

U M E R J AV E D
( U M E R . J AV E D @ I I U . E D U . P K )

D E PA R T M E N T O F E L E C T R O N I C
ENGINEERING,
FA C U LT Y O F E N G I N E E R I N G & T E C H N O L O G Y,
IIUI

SPRING 2017
CS-407:
Digital Image Processing

U M E R J AV E D
( U M E R . J AV E D @ I I U . E D U . P K )

CHAPTER: 3
I N T E N S I T Y T R A N S F O R M AT I O N S A N D
S PAT I A L F I LT E R I N G

SLIDE # 6
H I S T O G R A M E Q U A L I Z AT I O N
Intensity Transformations

Earlier we discussed,
 Threshold based transformations

 Inverse transformation

 Log transformation

 Gamma transformation

 Piecewise transformation

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 3


Histogram
What is the histogram of a digital image?
 It gives the graphical representation of intensity distribution in a
digital image.
 The histogram of a digital image with gray values r0 , r1 ,, rL1 is
the discrete function:
nk
p(rk )=
N

nk: Number of pixels with gray value rk


N: total Number of pixels in the image

 The function p(rk) represents the fraction of the total number of


pixels with gray value rk.

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 4


Some Histograms

Dark image

Bright image

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 5


Some Histograms

Low contrast
image

High contrast
image

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 6


As before, we assume that:
(1) T(r) is a monotonically increasing function for 0 r 1
(preserves order from black to white).
(2) T(r) maps [0,1] into [0,1] (preserves the range of allowed
Gray values).

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 7


Let us denote the inverse transformation by r =T -1(s) . We
assume that the inverse transformation also satisfies the above
two conditions.

We consider the gray values in the input image and output
image as random variables in the interval [0, 1].

Let pin(r) and pout(s) denote the probability density of the


Gray values in the input and output images.

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 8


If pin(r) and T(r) are known, and r =T -1(s) satisfies condition 1, we can
write (result from probability theory):

 dr 
pout ( s) =  pin (r ) 
 ds  r =T 1 ( s )
One way to enhance the image is to design a transformation
T(.) such that the gray values in the output is uniformly
distributed in [0, 1], i.e. pout (s)= 1, 0  s1

In terms of histograms, the output image will have all


gray values in “equal proportion” .

This technique is called histogram equalization.

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 9


Next we derive the gray values in the output is uniformly distributed in
[0, 1].

Consider the transformation

r
s = T (r ) =  pin (w)dw, 0  r 1
0

Note that this is the cumulative distribution function (CDF) of pin (r) and
satisfies the previous two conditions.

From the previous equation and using the fundamental


theorem of calculus,

ds
= pin (r )
dr

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 10


Therefore, the output histogram is given by

 1 
pout ( s) =  pin (r )   = 1r =T 1 ( s ) = 1, 0  s 1
 pin (r )  r =T 1 ( s )
The output probability density function is uniform, regardless of the
input.

Thus, using a transformation function equal to the CDF of input gray


values r, we can obtain an image with uniform gray values.

This usually results in an enhanced image, with an increase in the


dynamic range of pixel values.

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 11


How to implement histogram equalization?

Step 1:For images with discrete gray values, compute:

nk
pin (rk ) = 0  rk  1 0  k  L 1
n
L: Total number of gray levels

nk: Number of pixels with gray value rk

n: Total number of pixels in the image

Step 2: Based on CDF, compute the discrete version of the previous


transformation :

k
s k =T(rk )=  L-1  pin (rj ) 0  k  L 1
j=0

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 12


# pixels Fraction
of #
pixels

Gray Normalized gray value


value

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 13


k
 Applying the transformation, sk = T(rk ) =  L - 1  pin (rj ) we have
j=0

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 14


Notice that there are only five distinct gray levels --- (1/7, 3/7,
5/7, 6/7, 1) in the output image. We will relabel them as (s0,
s1, …, s4 ).

With this transformation, the output image will have


histogram

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 15


Histogram of output
image

# pixels

Gray values

Note that the histogram of output image is only approximately, and not exactly,
uniform. This should not be surprising, since there is no result that claims
uniformity in the discrete case.

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 16


Example Original image and its histogram

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 17


Histogram equalized image and its histogram

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 18


Histogram
 The shape of a histogram provides useful
information for
contrast enhancement.

Fig. 8 (a) Poor Image Fig. 8(b) Image Histogram


Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 19
Histogram
 The shape of a histogram provides useful
information for
contrast enhancement.

Fig. 9 (a) Equalized Image Fig. 9(b) Image Histogram


Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 20
 Comments:
Histogram equalization may not always produce desirable
results, particularly if the given histogram is very narrow. It
can produce false edges and regions. It can also increase
image “graininess” and “patchiness.”

Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 21


Umer Javed, CS:407: Digital Image Processing Chapter:3, Slide # 22

You might also like