Here we want to convert the image so that it has a particular histogram that can be arbitrarily specified. Such a mapping function can be found in three steps:
We first equalize the histogram of the input image
:
We then equalize the desired histogram of the output image
:
The inverse of the above transform is
However, as the image gray levels are discrete, the continuous mapping
obtained above can only be approximated. The discrete histograms
and
are not necessarily identical. We therefore need to relate
each gray level in
with
to a gray level in
with
, so that the mapping from
to
can be established.
Here are the steps of the algorithm:
Example:
The histogram of the given image and the histogram desired are shown below:
![]() |
![]() |
![]() |
![]() |
0 | 790 | 0.19 | 0.19 |
1 | 1023 | 0.25 | 0.44 |
2 | 850 | 0.21 | 0.65 |
3 | 656 | 0.16 | 0.81 |
4 | 329 | 0.08 | 0.89 |
5 | 245 | 0.06 | 0.95 |
6 | 122 | 0.03 | 0.98 |
7 | 81 | 0.02 | 1.00 |
![]() |
![]() |
![]() |
0 | 0.0 | 0.0 |
1 | 0.0 | 0.0 |
2 | 0.0 | 0.0 |
3 | 0.15 | 0.15 |
4 | 0.20 | 0.35 |
5 | 0.30 | 0.65 |
6 | 0.20 | 0.85 |
7 | 0.15 | 1.0 |
![]() |
![]() |
![]() |
![]() |
0 | 0.19 | 0.0 | 3 |
1 | 0.44 | 0.0 | 4 |
2 | 0.65 | 0.0 | 5 |
3 | 0.81 | 0.15 | 6 |
4 | 0.89 | 0.35 | 6 |
5 | 0.95 | 0.65 | 7 |
6 | 0.98 | 0.85 | 7 |
7 | 1.0 | 1.0 | 7 |
i | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
j | 3 | 4 | 5 | 6 | 6 | 7 | 7 | 7 |
This is the histogram of the resulting image:
In the following example, the desired histogram is a triangle with linear increase in the lower half of the the gray level range, and linear decrease in the upper half. Again the cumulative histogram shows indeed the density histogram is such a triangle.