DIP Lec 6 - 7 - 8 - 9
DIP Lec 6 - 7 - 8 - 9
Where, L = 2B-1
• To understand: if B=8, then L=255
Example
• The (binary) image for bit-
plane-7 can be obtained
by processing the input
image with a thresholding
gray-level transformation.
– Map all levels between 0
and 127 to 0
– Map all levels between 128
and 255 to 255
4 2 4 3 4
3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image
Gray scale = [0,9] 0 1 2 3 4 5 6 7 8 9
Histogram
Normalized Histogram
• dividing each of histogram at gray level rk by the
total number of pixels in the image (M x N size)
p(rk) = nk / MN
• For k = 0,1,…,L-1
• p(rk) gives an estimate of the probability of
occurrence of gray level rk
• The sum of all components of a normalized
histogram is equal to 1
Histogram Processing
• Basic for numerous spatial domain
processing techniques
• Used effectively for image enhancement
• Information inherent in histograms is also
useful in image compression and
segmentation
h(rk) or p(rk)
Example
rk
•Dark image
Components of
histogram are
concentrated on the
low side of the gray
scale.
•Bright image
Components of
histogram are
concentrated on the
high side of the gray
scale.
Example
•Low-contrast image
histogram is narrow
and centered toward
the middle of the
gray scale
•High-contrast image
histogram covers broad
range of the gray scale
and the distribution of
pixels is not too far from
uniform, with very few
vertical lines being much
higher than the others
Histogram Equalization
• As the low-contrast image’s histogram is narrow
and centered toward the middle of the gray
scale, if we distribute the histogram to a wider
range the quality of the image will be improved.
• We can do it by adjusting the probability density
function of the original histogram of the image so
that the probability spread equally
Example
before after Histogram
equalization
Example
before after Histogram
equalization
4 2 4 3 4
3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)
No. of
0 0 6 5 4 1 0 0 0 0
pixels
k
n
j 0
j 0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
MN
j 0
0 0 / / / / / / / /
16 16 16 16 16 16 16 16
k nj 3.3 6.1 8.4
s=9 n 0 0 9 9 9 9 9
j 0 3 6 8
Example
No. of pixels
2 3 3 2 6
4 2 4 3 5
4
3 2 3 5 3
2 4 2 4 2
1 Gray level
Input image
0123456789
3 6 6 3 6
5
8 3 8 6 4
3
6 3 6 9
2
3 8 3 8 1
Gray level
Output image 0123456789
Histogram equalization
Exercise
Histogram Equalization
Histogram Matching
(Specification)
• Histogram equalization has a disadvantage
which is that it can generate only one type of
output image.
• With Histogram Specification, we can specify
the shape of the histogram that we wish the
output image to have.
• It doesn’t have to be a uniform histogram
Consider the continuous domain
r
s T ( r ) pr ( w )dw Histogram equalization
0
s = T(r) = G(z)
z = G-1(s) = G-1[T(r)]
Assume G-1 exists and satisfies the condition (a) and (b)
We can map an input gray level r to output gray level z
Procedure Conclusion
1. Obtain the transformation function T(r) by
calculating the histogram equalization of the
input image r
s T ( r ) pr ( w )dw
0
Pr(r) 2r 2 ;0 r 1
pr ( r )
2 0 ; elsewhere
1 r
p ( w )dw 1
0
r
0 1 2 r
Example
Pz(z)
2z ;0 z 1
2 pz ( z )
0 ; elsewhere
1 z
p ( w )dw 1
z
z 0
0 1 2
Step 1:
s=T(r) r
s T ( r ) pr ( w )dw
0
1 r
( 2 w 2 )dw
One to one 0
mapping r
function w 2w 2
0
0 r
1 r 2r
2
Step 2:
z
G ( z ) ( 2w )dw
z
z 2
z 2
0
0
Step 3:
G( z ) T ( r )
z r 2r
2 2
z 2r r 2
z k G T ( rk )
1
G 1
sk k 0 ,1,2 ,..., L 1
Example
Consider the 64 X 64 size image histogram as shown below
After histogram equalization
Note
• Histogram specification is a trial-and-error
process
• There are no rules for specifying
histograms, and one must resort to
analysis on a case-by-case basis for any
given enhancement task.