[1] The well-known histogram equalization method is a special case in which the specified histogram is uniformly distributed.
[2] It is possible to use histogram matching to balance detector responses as a relative detector calibration technique.
It can be used to normalize two images, when the images were acquired at the same local illumination (such as shadows) over the same location, but by different sensors, atmospheric conditions or global illumination.
It has a probability density function pr(r), where r is a grayscale value, and pr(r) is the probability of that value.
This probability can easily be computed from the histogram of the image by
Where nj is the frequency of the grayscale value rj, and n is the total number of pixels in the image.
Now consider a desired output probability density function pz(z).
A transformation of pr(r) is needed to convert it to pz(z).
Each pdf (probability density function) can easily be mapped to its cumulative distribution function by Where L is the total number of gray level (256 for a standard image).
[3] The following input grayscale image is to be changed to match the reference histogram.
The input image has the following histogram It will be matched to this reference histogram to emphasize the lower gray levels.
Following, we calculate the cumulative distribution functions of the two images' histograms –
, and this is the result of histogram matching function:
In typical real-world applications, with 8-bit pixel values (discrete values in range [0, 255]), histogram matching can only approximate the specified histogram.
One simplistic approach converts the discrete-valued image into a continuous-valued image and adds small random values to each pixel so their values can be ranked without ties.
However, this introduces noise to the output image.
Because of this there may be holes or open spots in the output matched histogram.
The histogram matching algorithm can be extended to find a monotonic mapping between two sets of histograms.
, the optimal monotonic color mapping
is calculated to minimize the distance between the two sets simultaneously, namely
The optimal solution is calculated using dynamic programming.