You are on page 1of 25

DIGITAL IMAGE PROCESSING

IMAGE ENHANCEMENT
HISTOGRAM PROCESSING
by
Dr. K. M. Bhurchandi
2

Histogram Processing
Histogram:
It is a plot of frequency of occurrence of an
event.

freq. of
occurrence

0 1 2 3 event
3

Histogram Processing

 Histogram of images provide a global description of their


appearance.

Enormous information is obtained.

It is a spatial domain technique.

Histogram of an image represents relative frequency of


occurrence of various gray levels.

Histogram can be plotted in two ways:


4

Histogram Processing
First Method:

X-axis has gray levels & Y-axis has No. of pixels in each gray
levels.
nk
Gray Level No. of Pixels (nk) 40

0 40 30
1 20
2 10
3 15 20
4 10
5 3
6 2 10

0 1 2 3 4 5 6
Gray Levels
5

Histogram Processing
Second Method:
X-axis has gray levels & Y-axis has probability of occurrence of gray
levels.
P(µk) = nk / n; where, µk – gray level
nk – no. of pixels in kth gray level
n – total number of pixels in an image
Prob. Of Occurrence 1

0.8
Gray Level No. of Pixels (nk) P(µk) 0.7
0 40 0.4 0.6
1 20 0.2 0.5
2 10 0.1 0.4
3 15 0.15 0.3
4 10 0.1 0.2
5 3 0.03 0.1
6 2 0.02
n = 100 1 0 1 2 3 4 5 6 µk
6

Histogram Processing
 Advantage of 2nd method: Maximum value plotted will always be 1.
White – 1, Black – 0.
Great deal of information can be obtained just by looking at histogram.
Types of Histograms:

P(µk) P(µk)

0 rk 0 rk

P(µk) P(µk)

0 rk 0 rk
7

 Advantage of 2nd method: Maximum value plotted will always be 1.


White – 1, Black – 0.
Great deal of information can be obtained just by looking at histogram.
Types of Histograms:

P(µk) Dark Image P(µk) Bright Image

0 rk 0 rk

P(µk) Low Contrast Image P(µk) Equalized Image

0 rk 0 rk
8

Histogram Processing
The last graph represent the best image.

It is a high contrast image.

Our aim would be to transform the first 3 histograms into the 4th type.

In other words we try to increase the dynamic range of the image.

Normalized histogram is nothing but PDF (Probability Density


Function) of an image.
9

Histogram Stretching
1) Linear stretching:
Here, we don’t alter the basic shape.
We use basic equation of a straight line having a slope.
(Smax - Smin)/(rmax - rmin)
Where, Smax – max gray level of output image
Smin – min gray level of output image
rmax – max gray level of input image
rmin – min gray level of input image

0 min max 0 min max


10

Histogram
•  Processing

Smax

Smin
rmin rmax
11

Histogram Equalization
2) Histogram Equalization:

o Linear stretching is a good technique but not perfect since the shape remains
the same.

o Most of the time we need a flat histogram.

o It can’t be achieved by Histogram Stretching.

o Thus, the technique of Histogram Equalization came into use.

o Perfect image is one where all gray levels have equal number of pixels.

o Here, our objective is not only to spread the dynamic range but also to have
equal pixels at all gray levels.

o It is used to enhance visual content of image.


12

Histogram Equalization
nk Normal Histogram

nk Equalized Histogram nk Linearly Stretched Histogram

S S
14

Histogram Equalization
o We have to search for a transform that converts any random histogram
into flat histogram.
o S = T(r)

o We have to find ‘T’ which produces equal values in each gray levels.

o The Transform should satisfy following 2 conditions:

(i) T(r) must be single value & monotonically increasing in the interval,
0 ≤ r ≤ 1.

(ii) 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1


0 ≤ S ≤ 1 for 0 ≤ r ≤ 1
Here, range of r is [0, 1] (Normalized range) instead of [0, 255].
15

Histogram Equalization
These two conditions mean:

1) If T(r) is not single value:

S T(r) S T(r)
S2

S1 S1

r1 r2 r r1 r2 r
fig. (a) fig. (b)
16

Histogram Equalization
 In fig.(a) r1 & r2 are mapped as single gray level i.e. S1.

 Two different gray levels occupy same in modified image.

 Big Drawback, If reconstruction is required.

 Hence, transformation has to be single value.

 This preserves order from black to white.

 A gray level transformation with single value and monotonically increasing is


shown in fig.(b).

2) If condition (ii) is not satisfied then mapping will not be consistent with the
allowed range of pixel value.

 S will go beyond the valid range.


17

Histogram Equalization
 Since, the Transformation is single value & monotonically increasing, the
inverse Transformation exists.
r = T-1(S) ; 0 ≤ S ≤ 1

 Gray levels for continuous variables can be characterized by their


probability density Pr(r) & Ps(S).

 From Probability theory, we know that,


 If Pr(r) & Ps(S) are known & if T-1(S) satisfies condition (i) then the
probability density of the transferred gray level is

Ps(S) = Pr(r). |dr/ ds| ----(a)

Prob. Density = Prob. Density x inv. Slope of transformation


(Transformed Image) (Original Image)
18

Histogram Equalization
 Now lets find a transform which would give us a flat histogram.

 Cumulative Density Function (CDF) is preferred.

 CDF is obtained by simply adding up all the PDF’s.

S = T(r)
r

S = (L - 1) ʃ Pr(w) dw
0

differentiate with respect to r

ds / dr = (L - 1) Pr(r) ---------(b)

Equating eqn(a) & eqn(b), we get

Ps(s) = 1 / L - 1 ; 0 ≤ S ≤ L - 1
19

Histogram Equalization
 A bad Histogram becomes a flat histogram when we find the CDF.

Pr(r) Ps(s)
A 1/L-1
CDF
Pr(r) dr

0 L-1 f 0 L-1 S
Non-Uniform Function Uniform Function
20

Histogram Equalization
 NOTE: If an image has MxN pixels, then PDF is given by:

Pr(rk) = nk / MN;

Where, nk – no. of pixels with intensity rk

k = 0, 1, 2, …….., L-1

In continuous domain,
r

S = T(r) = (L-1)ʃ Pr(w) dw


0

In discrete domain,

Sk = T(rk) = (L - 1)Σ Pr(rj) (CDF)


j=0
21

Histogram Equalization
Prob. 1) Equalize the given histogram
Gray Levels (r) 0 1 2 3 4 5 6 7

No. of Pixels 790 1023 850 656 329 245 122 81


22

Gray No. of (PDF) (CDF) (L-1) sk = Rounding


Histogram Equalization
Levels
(rk)
Pixels
nk
Pr(rk) =
nk/n
sk = Σ pk (rk) 7 x sk off

0 790 0.19 0.19 1.33 1


1 1023 0.25 0.44 3.08 3
2 830 0.21 0.65 4.55 5
3 656 0.16 0.81 5.67 6
4 329 0.08 0.89 6.23 6
5 245 0.06 0.95 6.65 7
6 122 0.03 0.98 6.86 7
7 81 0.02 1 7 7
n = 4096 1

Equating Gray Levels to No. of Pixels:


0 -> 0 4 -> 0
1 -> 790 5 -> 850
2 -> 0 6 -> 985
3 -> 1023 7 -> 448 Total : 4096 Hence Verified!!!
23

Equalized Histogram:
Gray Levels (S) 0 1 2 3 4 5 6 7

No. of Pixels 0 790 0 1023 0 850 985 448

Total: 4096
24

Histogram Equalization
25

Histogram Equalization

You might also like