Professional Documents
Culture Documents
Computer Vision - Histogram Processing: Dr. S. Das IIT Madras, CHENNAI - 36
Computer Vision - Histogram Processing: Dr. S. Das IIT Madras, CHENNAI - 36
Histogram Processing
Dr. S. Das
IIT Madras, CHENNAI - 36
HISTOGRAM
• In a gray level image the probabilities
assigned to each gray level can be
given by the relation:
Input image
nk
pr (rk ) = 0 ≤ rk ≤ 1 , k = 0,1,2...L - 1
N
rk - The normalized intensity value
L - No. of gray levels in the image
nk - No. of pixels with gray level rk
N - Total number of pixels
The plot of pr(rk) with respect to rk is
called HISTOGRAM of the image histogram
Some images and their histograms
Image with
2 prominent
intensities
Foreground
white
Some images and their histograms
Image with more
prominent dark
background
Where
0 ≤ rk ≤ 1, k = 0,1,2,...., L − 1
– nj is the number of times the jth gray level appears
in the image
– L is the number of gray levels
– Pr(rj) is the probability of the j th gray level and
– N is the total number of pixels in the image
• Unlike the continuous part the discrete transformation
may not produce the discrete equivalent of a uniform
pdf. Nevertheless, it spreads the histogram to span a
larger range.
Discussion on Histogram equalization
• This method is completely
automatic. ALGORITHM
• Inverse transformation
INPUT: Input image
rk=T-1(sk) satisfies both the OUTPUT: Output image after
conditions (onto and one to equalization
one) and hence can be used in
the continuous case 1. Compute histogram h(xi)
2. Calculate normalized sum
• In case of discrete histogram,
of histogram (CDF)
it is possible if the input 3. Transform input image to
image has all the gray levels. output image
pr ( r ) = −2 r + 2 , 0 ≤ r ≤ 1
CDF is calculated as :- 0 1 r
r
s = T ( r ) = ∫ ( −2 w + 2 )dw 1
0
s T(r)
= -r + 2 r
2
gives r − 2 r + s = 0
2 0 1 r
Example on histogram equalization
(Continuous Case)
2 ± 4 - 4s
r= = 1± 1− s
2 (Taking
dr 1 derivative with
r = 1− 1− s , =
ds 2 1 − s respect to s)
pr ( r ) = −2( 1 − 1 − s ) + 2 , pr ( r ) = 2 1 − s
dr
ps ( s ) = pr ( r ) , ps ( s ) = 1 (Uniform pdf)
ds
Example on histogram equalization
(Discrete case)
(a) rk (b) nk (c) pr(rk) (d) Cdf = sk (e) Quant. Values
0 790 0.19 0.19 1/7
1/7 1023 0.25 0.44 3/7
2/7 850 0.21 0.65 5/7
3/7 656 0.16 0.81 6/7
4/7 329 0.08 0.89 6/7
5/7 245 0.06 0.95 1
6/7 122 0.03 0.98 1
1 81 0.02 1.00 1
total 4096 1.00
(a) Quantized Gray levels; (b) a sample histogram; (c) its pdf;
(d) Computed CDF and (e) approximated to the nearest gray level.
Example on histogram equalization
(Discrete case)(Contd..)
(a) rk (b) nk (c) pr(rk) rk sk = T(r) sk nk ps(sk)
0 790 0.19 0 1/7 0 0 0
1/7 1023 0.25 1/7 3/7 1/7 790 0.19
2/7 850 0.21 2/7 0 0
2/7 5/7
3/7 656 0.16 3/7 1023 0.25
3/7 6/7
4/7 329 0.08
4/7 6/7 4/7 0 0
5/7 245 0.06
5/7 7/7 5/7 850 0.21
6/7 122 0.03
6/7 7/7 6/7 985 0.24
1 81 0.02
total 4096 1.00 1 7/7 7/7=1 448 0.11
s 2 0.1
1
0
0 0 2 4 6
0 2 4 6
r s
HISTOGRAM EQUALISATION - revisited
Here, the goal is to obtain a uniform histogram for the output image.
Some features of Histogram equalization are as follows:
−[ s / a − ( c + b / a )]2
Then, ps ( s ) = ae
Histogram specification
Histogram specification method develops a gray
level transformation such that the histogram of the
output image matches that of the pre-specified
histogram of a target image. Figure below shows the
flow diagram of histogram specification method
A(x,y) C(x,y)
Input T(x,y) Output
Image Target Image
Image
HC(DC)
HT(DT)
HA(DA)
DT 255
0 DA 255 0 DC 255
Steps:
• Read the Input image and the Target image.
• Obtain the histogram of the input image and the target image.
• Equalize the input and the target images using the equation (1).
• Calculate the transformation function G of the target Image.
• Map the original image gray level rk to the final gray level zk
s Mapping from rk to sk Mapping from zk to vk
via T(r) v via G(z)
1 1
sk vq G(z)
T(r)
0 rk L-1 r z
0 zk L-1
v
1
sk
G(z)
Inverse Mapping from
sk to zk
0 zk z
L-1
A hand worked example (1)
• Two histograms are given to us
rk nk pk zk p (zk)
0/7 790 0.19 0/7 0
1/7 1023 0.25 1/7 0
2/7 850 0.21 2/7 0
3/7 656 0.16 3/7 0.15
4/7 329 0.08 4/7 0.2
5/7 245 0.06 5/7 0.3
6/7 122 0.03 6/7 0.2
7/7 81 0.02 7/7 0.15
2/7 0 0 0/7 2
s 1
3/7 0.15 0.15 1/7 0
0 2 4 6
4/7 0.2 0.35 2/7
z
5/7 0.3 0.65 5/7 G(z)
6/7 0.2 0.85 6/7
7/7 0.15 1 1
T(r) ps(sk)
7
T(r)
6 0.3 P(s)
5
4 0.2
3
s 2 0.1
1
0
0 0 2 4 6
0 2 4 6
r s
7
6
5
4
3
2
p(z) s 1
0
0 2 4 6
z z
G(z)
A hand-worked example (4)
Mapping stage
rk sk =
cdf(pk) G(zK) zk
0/7 0.19 0 0/7
1/7 0.44 0 1/7 Mapping
function
2/7 0.65 0 2/7
3/7 0.81 0.15 3/7 0 3
4/7 0.89 0.35 4/7 1 4
5/7 0.95 0.65 5/7 2 5
6/7 0.98 0.85 6/7 3,4 6
7/7 1 1 7/7 5,6,7 7
Equalized input Equalized target
histogram histogram
Target Image
DHS Output Image
Target Image
Source Image Direct Histogram
Specification
Target Image DHS Output Image
Source Image Direct Histogram
Specification
DHS Output Image
Target Image
End of Lectures -
Histogram Processing