You are on page 1of 28

HistogramEqualization

HistogramProcessing
i Assume we have image with nk pixels with
intensity rk , k = 0,1,..., L 1
i We define the image histogram as h(rk ) = nk ,
and we define the normalized histogram as:
p (rk ) = h(rk ) / ( M N )
i The normalized histogram is an estimate
of the probability of occurrence of intensity
level rk in an image
i The normalized histogram sums to 1
20120702 2
Fourbasicimagetypes:
dark
light
lowcontrast
highcontrast
Theircorrespondinghistograms

20120702 3
HistogramProcessing
Intuitively,imageswhosepixelsoccupythe
entirerangeofintensitylevelsandtendtobe
distributeduniformlywillhaveanappearance
ofhighcontrast
Itispossibletodevelopatransformation
functionthatcanautomaticallyachievethis
effect,basedonthehistogramoftheinput
image.

20120702 4
HistogramEqualization
i assume continuous intensity values with
intensity r
i assume r in the range [ 0, L 1]
i consider transform of the form s = T (r ), 0 r L 1
i assume:
- T (r ) monotonically increasing in range 0 r L 1
- 0 T (r ) L 1 for 0 r L 1
i possible for multiple values of r to map to a
single value of s

20120702 5
HistogramEqualization
i pr (r ) is the PDF of r
i ps ( s ) is the PDF of s
i if pr (r ) and T (r ) are known, and T (r ) is
continuous and differentiable over the range
of interest, then ps ( s ) can be obtained as:
dr
ps ( s ) = pr (r )
ds
i with
r
s = T (r ) = ( L 1) pr ( w) dw
0

i the right side of the above eqn. is the CDF of r


20120702 6
HistogramEqualization
i find ps ( s ) corresponding to transformation
s = T (r ) :
dr
ps ( s ) = pr (r )
ds
d
r
ds d T (r )
= = ( L 1) pr ( w) dw
dr dr dr 0
= ( L 1) pr (r )
i thus:
1 1
ps ( s ) = pr (r ) = ; 0 s L 1
( L 1) pr (r ) L 1
i thus ps ( s ) is a uniform PDF.
20120702 7
HistogramEqualization

20120702 8
HistogramEqualization Example
i assume:
2r
pr (r ) = ; 0 r L 1
( L 1) 2

r
s = T (r ) = ( L 1) pr ( w) dw
0
r
2 r2
=
( L 1) 0
w dw =
L 1
i thus:
r2
s = T (r ) =
L 1
1
dr ds 1
ps ( s ) = pr (r ) = pr ( r ) =
ds dr ( L 1)
20120702 9
HistogramEqualization DiscreteCase
i for discrete case we have:
k
sk = T (rk ) = ( L 1) pr (rj )
j =0

( L 1) k
=
M N j =0
nj 0 k L 1

i assume L = 8, M = N = 64, M N = 4096


0
i s0 = T (r0 ) = 7 pr (rj ) = 7 pr (0) = 1.33 1
j =0
1
i s1 = T (r1 ) = 7 pr (rj ) = 7 ( pr (0) + pr (1)) = 3.08 3
j =0
2
i s2 = T (r2 ) = 7 pr (rj ) = 7 ( pr (0) + pr (1) + pr (2)) = 4.55 5
j =0

s3 = 5.67 6, s4 = 6.23 6, s5 = 6.65 7, s6 = 6.86 7, s7 = 7.00 7


20120702 10
HistogramEqualization Discrete

20120702 11
HistogramEqualization Discrete
i final transform:
r0 s0 = 1 790 pixels map to 1
r1 s1 = 3 1023 pixels map to 3
r2 s2 = 5 850 pixels map to 5
r3 s3 = 6 656 + 329 = 985 pixels map to 6
r4 s4 = 6 656 + 329 = 985 pixels map to 6
r5 s5 = 7 245 + 122 + 81 = 458 pixels m ap to 7
r6 s6 = 7 245 + 122 + 81 = 458 pixels map to 7
r7 s7 = 7 245 + 122 + 81 = 458 pixels map to 7

20120702 12
HistogramEqualization

20120702 13
HistogramMatching
HistogramMatching
i specify shape of histogram that we want processed
image to have
i let pr (r ) and pz ( z ) represent the PDFs of r and z ,
where r is the input pixel intensity level and z is the
output pixel intensity level)
i estimate pr (r ) from input image histogram

20120702 15
HistogramMatching
i let s be a random variable of the form:
r
s = T (r ) = ( L 1) pr ( w) dw (1)
0

i define random variable z with property:


z
G ( z ) = ( L 1) pz (t ) dt (2)
0

i thus we have:
G ( z ) = T (r ) (3)
z = G 1[T (r )] = G 1 ( s ) (4)
i thus T (r ) is obtained from the input image
intensity PDF and G ( z ) is obtained as s
20120702 16
HistogramMatchingProcess
1. obtain pr (r ) from input image
2. obtain values of s = T (r )
3. obtain G ( z ) from specified PDF (Equation (2))
4. obtain inverse transformation, z = G 1 ( s );
since z obtained from s, this is an s to z
mapping
5. obtain pixel image by equalizing input image
(to uniform PDF); for each pixel with value
s, obtain z = G 1 ( s ) to get output image pixel value
20120702 17
HistogramMatchingExample
i input image intensity levels obey PDF
2r
pr (r ) = 0 r L 1
( L 1) 2

i output image intensity levels approximate PDF


3z 2
pz ( z ) = 0 z L 1
( L 1) 3

i first find histogram equalization transform ation:


r r
2 r2
s = T (r ) = ( L 1) pr ( w) dw = pr ( w) dw =
0
( L 1) 0 ( L 1)
i next find G ( z ) as:
z z
3 z3
G ( z ) = ( L 1) pz ( w) dw = 2
w dw =
2

0
( L 1) 0
( L 1) 2

20120702 18
HistogramMatchingExample
i we require G ( z ) = s; thus:
z3
s=
( L 1) 2
1/3
z = ( L 1) 2 s
i next we multiply the histogram equalized pixels
by ( L 1) 2 and take the cube root of the resulting
pixel values, giving an image whose intensities, z ,
have PDF of pz ( z ) = 3 z 2 / ( L 1)3
1/3
z = ( L 1) 2 s = ( L 1) 2 r / ( L 1) 2
1/3
= ( L 1) r 2
i note that we can skip the intermediate step of
equalizing the input image
20120702 19
HistogramMatchingExample
i histogram equalization gives:
k
sk = T (rk ) = ( L 1) pr (rj )
j =0

( L 1) k
=
MN j =0
nj 0 k L 1 (5)

i given the value of sk , we can solve for zq as:


q
G ( zq ) = ( L 1) pz ( zi ) (6)
i =0

i for a value of q, so that:


G ( zq ) = sk (7)
i we can find zq as:
zq = G 1 ( sk ) (8)
i this is the mapping from s to z
20120702 20
HistogramMatchingExample

i In practice, we don't need the inverse of G since


all intensity levels are integers; can instead compute
all possible vlaues of G by performing all sumes in
Eq. (6). The values zq are scaled and rounded to the
nearest integer value.

20120702 21
HistogramMatching DiscreteCase
i Discrete Case Solution
1. compute histogram, pr (r ), of image; find histogram equalization transformation:
( L 1) k
sk = T (rk ) = nj
M N j =0
0 k L 1

round all values of sk to nearest integer in [0, L 1]


2. compute all values of transformation G
q
G ( zq ) = ( L 1) pz ( zi )
i =0

for q = 0,1,..., L 1 where pz ( zi ) are values of specified histogram; round values of G


to integers in range [0, L 1]; store values of G in table
3. for every value of sk , 0 k L 1, use stored values of G to find corresponding value
of zq so that G ( zq ) is closest to sk , and store these mappings from s to z. For
multiple zq matches to sk , choose smallest zq .
4. form histogram matched image by first histogram equalizing input image and then
mapping every equalized pixel value, sk , to the corresponding value, zq , using the
mappings in Step 3.
20120702 22
HistogramMatching DiscreteCase

20120702 23
HistogramMatching Example

i first obtain scaled histogram equalized values:


s0 = 1; s1 = 3; s2 = 5; s3 = 6; s4 = 6; s5,6,7 = 7
i next compute and round all values of transformation G :
G ( z0 ) = 0 0; G ( z1 ) = 0 0; G ( z2 ) = 0 0;
G ( z3 ) = 1.05 1; G ( z4 ) = 2.45 2; G ( z5 ) = 4.55 5;
G ( z6 ) = 5.95 6; G ( z7 ) = 7 7
i need to find smallest value of zq so that G ( zq ) is closest
to sk ; do this for all sk to create required mapping:
20120702 s1 z3 ; s3 z4 ; s5 z5 ; s6 z6 ; s7 z7 24
HistogramMatching Example
k sk Q[ sk ] zq G ( zq ) Q[G ( zq )]

0 1.33 1 0 0 0
1 3.08 3 1 0 0
2 4.55 5 2 0 0
3 5.67 6 3 1.05 1
4 6.23 6 4 2.45 2
5 6.65 7 5 4.55 5
6 6.86 7 6 5.95 6
7 7 7 7 7 7

20120702 25
HistogramMatching Example

i Find smallest value of zq so that


G ( zq ) is closest to sk
sk G ( zq ) zq
1 1 3
3 2 4
5 5 5
6 6 6 6
7 77 7 7

20120702 26
HistogramMatching Example2

20120702 27
HistogramMatching Example2

20120702 28

You might also like