Histogram Processing
„ Histogram of a digital image with gray levels in
the range [0,L-1] is a discrete function
h(r
h(rk
k) =
) = n
nk
k
„ Where
„ rk : the kth gray level
„ nk : the number of pixels in the image having gray
level rk
„ h(rk) : histogram of a digital image with gray levels rk
Normalized Histogram
„ dividing each of histogram value at gray level r
rk
k
by the total number of pixels in the image, n
n
p(r
p(rk
k) =
) = n
nk
k / n
/ n
„ For k = 0,1,…,L-1
„
„ p(r
p(rk
k)
) gives an estimate of the probability of
occurrence of gray level r
rk
k
„ The sum of all components of a normalized
histogram is equal to 1
Histogram Processing
„
„ Used effectively for image enhancement
„ Information inherent in histograms also
is useful in image compression and
segmentation
„ Data-dependent pixel-based image
enhancement method.
Example rk
h(rk) or p(rk)
Dark image
Bright image
Components of
histogram are
concentrated on the
low side of the gray
scale.
Components of
histogram are
concentrated on the
high side of the gray
scale.
Example
Low-contrast image
High-contrast image
histogram is narrow
and centered toward
the middle of the
gray scale
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
Example
before after Histogram
equalization
Example
before after Histogram
equalization
The quality is
not improved
much because
the original
image already
has a broaden
gray-level scale
Histogram Equalization:
Implementation
1. Obtain the histogram of the input image.
2. For each input gray level k, compute the
cumulative sum.
3. For each gray level k, scale the sum by
(max gray level)/(number of pixels).
4. Discretize the result obtained in 3.
5. Replace each gray level k in the input
image by the corresponding level
obtained in 4.
Example
4
2
4
2
5
3
2
3
3
4
2
4
2
3
3
2
4x4 image
Gray scale = [0,9]
histogram
0 1
1
2
2
3
3
4
4
5
5
6
6
7 8 9
No. of pixels
Gray level
9
16
/
16
16
0
9
s x 9
No. of
pixels
Gray
Level(j)
9
9
9
9
8.4
≈8
6.1
≈6
3.3
≈3
0
0
16
/
16
16
/
16
16
/
16
16
/
16
15
/
16
11
/
16
6
/
16
0
0
16
16
16
16
15
11
6
0
0
0
0
0
1
4
5
6
0
0
8
7
6
5
4
3
2
1
0
∑
=
k
j
j
n
0
∑
=
=
k
j
j
n
n
s
0
Example
8
3
8
3
9
6
3
6
6
8
3
8
3
6
6
3
Output image
Gray scale = [0,9]
Histogram equalization
0 1
1
2
2
3
3
4
4
5
5
6
6
7 8 9
No. of pixels
Gray level
Note
„ It is clearly seen that
„ If the cumulative numbers of gray levels are
slightly different, they will be mapped to
little different or same gray levels as we
may have to approximate the processed gray
level of the output image to integer number
„
„ Thus the discrete transformation function
can’t guarantee the one to one mapping
relationship
Histogram Equalization
„ A gray-level transformation method that forces the
transformed gray level to spread over the entire
intensity range.
„ Fully automatic,
„ Data dependent,
„ Contrast enhanced.
„ Usually, the discrete-valued histogram equalization
algorithm does not yield exact uniform distribution of
histogram.
„ In practice, one may prefer “histogram specification”.
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
Procedure Conclusion
Indirect Method:
1. Obtain the transformation function T(r) by
calculating the histogram equalization of the
input image
2. Obtain the transformation function G(z) by
calculating histogram equalization of the
desired density function
)
(r
T
s =
)
(z
G
v =
Procedure Conclusion
3. Set v = s to obtain the inversed
transformation function G-1
4. Obtain the output image by applying the
processed gray-level from the inversed
transformation function to all the
pixels in the input image
z = G-1(s) = G-1[T(r)]
Histogram Matching: Example
„ Consider an 8-level image with
the shown histogram
„ Match it to the image with the
histogram
Histogram Matching: Example
1. Equalize the histogram of the input image
using transform s =T(r).
Histogram Matching: Example
2. Equalize the desired histogram v = G(z).
Histogram Matching: Example
3. Set v = s to obtain the composite
transform z = G-1(s) = G-1[T(r)]
In other words: Find z such that v is closest to s
​
Example
Image of Mars moon
Image is dominated by large, dark areas,
resulting in a histogram characterized by
a large concentration of pixels in pixels in
the dark end of the gray scale
Image Equalization
Result image
after histogram
equalization
Transformation function
for histogram equalization
Histogram of the result image
The histogram equalization doesn’t make the result image look better. As a
consequence, the output image is light and has a washed-out appearance.
Histogram Equalization
Histogram Specification
Solve the problem
•Since the problem with the
transformation function of the
histogram equalization was
caused by a large concentration
of pixels in the original image
with levels near 0
•a reasonable approach is to
modify the histogram of that
image so that it does not have
this property
Result image and its histogram
Original image
The output image’s histogram
Notice that the output
histogram’s low end has
shifted right toward the
lighter region of the gray
scale as desired.
After histogram
Specification
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.

Lecture 7 - Histogram Equalization and Histogram Matching.pdf

  • 1.
    Histogram Processing „ Histogramof a digital image with gray levels in the range [0,L-1] is a discrete function h(r h(rk k) = ) = n nk k „ Where „ rk : the kth gray level „ nk : the number of pixels in the image having gray level rk „ h(rk) : histogram of a digital image with gray levels rk
  • 2.
    Normalized Histogram „ dividingeach of histogram value at gray level r rk k by the total number of pixels in the image, n n p(r p(rk k) = ) = n nk k / n / n „ For k = 0,1,…,L-1 „ „ p(r p(rk k) ) gives an estimate of the probability of occurrence of gray level r rk k „ The sum of all components of a normalized histogram is equal to 1
  • 3.
    Histogram Processing „ „ Usedeffectively for image enhancement „ Information inherent in histograms also is useful in image compression and segmentation „ Data-dependent pixel-based image enhancement method.
  • 4.
    Example rk h(rk) orp(rk) Dark image Bright image Components of histogram are concentrated on the low side of the gray scale. Components of histogram are concentrated on the high side of the gray scale.
  • 5.
    Example Low-contrast image High-contrast image histogramis narrow and centered toward the middle of the gray scale 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
  • 6.
  • 7.
    Example before after Histogram equalization Thequality is not improved much because the original image already has a broaden gray-level scale
  • 8.
    Histogram Equalization: Implementation 1. Obtainthe histogram of the input image. 2. For each input gray level k, compute the cumulative sum. 3. For each gray level k, scale the sum by (max gray level)/(number of pixels). 4. Discretize the result obtained in 3. 5. Replace each gray level k in the input image by the corresponding level obtained in 4.
  • 9.
    Example 4 2 4 2 5 3 2 3 3 4 2 4 2 3 3 2 4x4 image Gray scale= [0,9] histogram 0 1 1 2 2 3 3 4 4 5 5 6 6 7 8 9 No. of pixels Gray level
  • 10.
    9 16 / 16 16 0 9 s x 9 No.of pixels Gray Level(j) 9 9 9 9 8.4 ≈8 6.1 ≈6 3.3 ≈3 0 0 16 / 16 16 / 16 16 / 16 16 / 16 15 / 16 11 / 16 6 / 16 0 0 16 16 16 16 15 11 6 0 0 0 0 0 1 4 5 6 0 0 8 7 6 5 4 3 2 1 0 ∑ = k j j n 0 ∑ = = k j j n n s 0
  • 11.
    Example 8 3 8 3 9 6 3 6 6 8 3 8 3 6 6 3 Output image Gray scale= [0,9] Histogram equalization 0 1 1 2 2 3 3 4 4 5 5 6 6 7 8 9 No. of pixels Gray level
  • 12.
    Note „ It isclearly seen that „ If the cumulative numbers of gray levels are slightly different, they will be mapped to little different or same gray levels as we may have to approximate the processed gray level of the output image to integer number „ „ Thus the discrete transformation function can’t guarantee the one to one mapping relationship
  • 13.
    Histogram Equalization „ Agray-level transformation method that forces the transformed gray level to spread over the entire intensity range. „ Fully automatic, „ Data dependent, „ Contrast enhanced. „ Usually, the discrete-valued histogram equalization algorithm does not yield exact uniform distribution of histogram. „ In practice, one may prefer “histogram specification”.
  • 14.
    Histogram Matching (Specification) „ Histogramequalization 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
  • 15.
    Procedure Conclusion Indirect Method: 1.Obtain the transformation function T(r) by calculating the histogram equalization of the input image 2. Obtain the transformation function G(z) by calculating histogram equalization of the desired density function ) (r T s = ) (z G v =
  • 16.
    Procedure Conclusion 3. Setv = s to obtain the inversed transformation function G-1 4. Obtain the output image by applying the processed gray-level from the inversed transformation function to all the pixels in the input image z = G-1(s) = G-1[T(r)]
  • 17.
    Histogram Matching: Example „Consider an 8-level image with the shown histogram „ Match it to the image with the histogram
  • 18.
    Histogram Matching: Example 1.Equalize the histogram of the input image using transform s =T(r).
  • 19.
    Histogram Matching: Example 2.Equalize the desired histogram v = G(z).
  • 20.
    Histogram Matching: Example 3.Set v = s to obtain the composite transform z = G-1(s) = G-1[T(r)] In other words: Find z such that v is closest to s ​
  • 21.
    Example Image of Marsmoon Image is dominated by large, dark areas, resulting in a histogram characterized by a large concentration of pixels in pixels in the dark end of the gray scale
  • 22.
    Image Equalization Result image afterhistogram equalization Transformation function for histogram equalization Histogram of the result image The histogram equalization doesn’t make the result image look better. As a consequence, the output image is light and has a washed-out appearance.
  • 23.
    Histogram Equalization Histogram Specification Solvethe problem •Since the problem with the transformation function of the histogram equalization was caused by a large concentration of pixels in the original image with levels near 0 •a reasonable approach is to modify the histogram of that image so that it does not have this property
  • 24.
    Result image andits histogram Original image The output image’s histogram Notice that the output histogram’s low end has shifted right toward the lighter region of the gray scale as desired. After histogram Specification
  • 25.
    Note „ Histogram specificationis 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.