OpenCV 3 Computer Vision with Python Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

To equalize histograms, a special function from OpenCV can be applied. It's called equalizeHist, and it takes an image whose contrast we need to be enhanced. Note that it takes only single-channel images, so we can use this function directly only for grayscale images. The return value of the routine is a single-channel, equalized image.

To apply this function for full color images, we need to transform them in such way as to have intensity information in one channel and color information in the other channels. The HSV color space perfectly fits this requirement, because the last V channel encodes brightness. By transforming an input image to HSV color space, applying equalizeHist to the V channel, and converting the result back to RGB, we can equalize histogram for full color images.

After following the steps from this recipe, the result should appear as follows: