Understanding Image Contrast Algorithms

A histogram is simply a bar chart representing [in this case] different frequencies of colors in an image.


The previous code is overly simplistic. A proper implementation would map the RGB color space to HSL. Then, it would modify the luminance values and then convert the image back to the RGB color space. However, modifying the RGB values in this way still illustrates the point without increasing the article’s scope.


Photo by Giancarlo Corti on Unsplash

It’s also important to note that the general shape of the histogram is preserved with this approach. This won’t be the case with future algorithms we’ll look at.

If we wanted to apply this same approach to an RGB image, we’d need to convert the image to a Hue, Saturation, Intensity (HSI) color space. Then, we’d perform the same calculation above on just the Intensity value and then map the result back to the RGB color space.

Credit: Wikipedia
0, 3028
1, 1216
2, 1188
3, 1262
4, 1242

Calculating all of these frequencies and probabilities helps us in the transformation of the histogram into a uniform distribution.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store