Image Enhancement Histogram Processing: by Dr. K. M. Bhurchandi
Image Enhancement Histogram Processing: by Dr. K. M. Bhurchandi
Image Enhancement Histogram Processing: by Dr. K. M. Bhurchandi
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 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
0 rk 0 rk
0 rk 0 rk
8
Histogram Processing
The last graph represent the best 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.
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
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 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.
Histogram Equalization
nk Normal 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.
(i) T(r) must be single value & monotonically increasing in the interval,
0 ≤ r ≤ 1.
Histogram Equalization
These two conditions mean:
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.
2) If condition (ii) is not satisfied then mapping will not be consistent with the
allowed range of pixel value.
Histogram Equalization
Since, the Transformation is single value & monotonically increasing, the
inverse Transformation exists.
r = T-1(S) ; 0 ≤ S ≤ 1
Histogram Equalization
Now lets find a transform which would give us a flat histogram.
S = T(r)
r
S = (L - 1) ʃ Pr(w) dw
0
ds / dr = (L - 1) Pr(r) ---------(b)
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;
k = 0, 1, 2, …….., L-1
In continuous domain,
r
In discrete domain,
Histogram Equalization
Prob. 1) Equalize the given histogram
Gray Levels (r) 0 1 2 3 4 5 6 7
Equalized Histogram:
Gray Levels (S) 0 1 2 3 4 5 6 7
Total: 4096
24
Histogram Equalization
25
Histogram Equalization