Posted on

What Histogram Equalization does is to improve the contrast of the image.

hist

The picture above shows distribution of pixel intensity in grayscale.

x-axis : The intensity value ranged from 0 - 255.
y-axis : The number of pixel given the particular intensity value.

pros: be useful in images with backgrounds and foregrounds that are both bright or both dark.

cons: comes along with a side-effect which may indiscriminately increase the contrast of background noise.


Before introduce histogram equlization, here’s a question.
What is the difference between Histogram Equalization and Normalization ? Aren’t they both do something like stretch out the range of pixel intensity distribution?

This link has the comprehensive comparison about Histogram Equalization and contract strectching (also named as Normalization)


Ok, Let’s dive into how global histogram equalization works.

Take the grayscale picture below as an instance:

  • cdf (x) : the cumulative number of pixels with intensity below x.

  • Max_hist : Max intensity of whole picture. (that is, the highest value of the histogram)

  • Max_cdf : Max cdf value of whole cdf distribution.

In order to show the trend of cdf relative to intensity value, we need to normalize cdf with

$$ cdf\_normalize = \frac{Max\_hist * cdf(x)} {Max\_cdf} $$

hist result

Note: You can apply histogram both on grayscale (1-channel) and RGB image (3-channels). For RGB image case, you should first convert RGB colorspace to other colorspace such as YUV which can seperate luminance signal (Y) and chrominance signal (U, V). Cause you may just want contrast and brightness to be adjust, not on color.

For more application details, please see Wikipedia of Histogram equalization.

For implementation on Numpy or OpenCV, look at OpenCV documentation.

comments powered by Disqus