OpenCV
3.4.16
Open Source Computer Vision
|
Prev Tutorial: Affine Transformations
Next Tutorial: Histogram Calculation
In this tutorial you will learn:
To accomplish the equalization effect, the remapping should be the cumulative distribution function (cdf) (more details, refer to Learning OpenCV). For the histogram \(H(i)\), its cumulative distribution \(H^{'}(i)\) is:
\[H^{'}(i) = \sum_{0 \le j < i} H(j)\]
To use this as a remapping function, we have to normalize \(H^{'}(i)\) such that the maximum value is 255 ( or the maximum value for the intensity of the image ). From the example above, the cumulative function is:
Finally, we use a simple remapping procedure to obtain the intensity values of the equalized image:
\[equalized( x, y ) = H^{'}( src(x,y) )\]
As it can be easily seen, the only arguments are the original image and the output (equalized) image.
To appreciate better the results of equalization, let's introduce an image with not much contrast, such as:
which, by the way, has this histogram:
notice that the pixels are clustered around the center of the histogram.
After applying the equalization with our program, we get this result:
this image has certainly more contrast. Check out its new histogram like this:
Notice how the number of pixels is more distributed through the intensity range.