Histogram equalization


In the last post I explained briefly what are histograms and today I’ll continue a little more and show how it can be useful to process images. Some examples of how histograms can be used are: image enhancement, texture classification, image segmentation, etc. In this post I’ll cover the most common use for histogram which is histogram equalization.


As discussed before, an histogram give us a rough idea of how an image is, if it’s too dark or too bright for example. In the first case we will note that most of pixels have low values and in the second case, most of the pixels have high values and maybe they are not equally spread in the range of 0 and 255. The idea of this technique is to get the maximum variance of histogram of an image and then improve image’s contrast. Figure 1 shows the waveform of an ideal histogram equalization.



Figure 1


Now take a look in figure 2 which is dark and then has histogram with low values only, less then 100.



Figure 2


The histogram can be plot in octave using the following commands:


Figure 3 shows figure 2 after an histogram equalization:


lena_eq_from_darkFigure 3


We can see clearly that figure 3 improved image’s contrast. Note what happened with its histogram. We can see that pixels now are spread from 0 to 255 and roughly with same quantity of pixels for each level.


Figure 4 is the result of histogram equalization from the image which was brighter in the last post.


lena_eq_from_brightFigure 4


Pay attention that the images in figure 3 and 4 are not equals and nor their histograms.

Finally, let’s take a look in the original image in grayscale and after an histogram equalization. We can see that we have a better contrast as expected.


lena_gray_eq_destFigure 5


This technique is very useful to improve an image contrast. A practical use could be to improve fingerprints images to have a better minutia detection and then fingerprint recognition. It worth to mention that this technique has some limitations and some variations and extensions exist, like histogram matching and local histogram equalization where we process only a part of an image instead of the whole image at once.



Marcelo Jo

Marcelo Jo is an electronics engineer with 10+ years of experience in embedded system, postgraduate in computer networks and masters student in computer vision at Université Laval in Canada. He shares his knowledge in this blog when he is not enjoying his wonderful family – wife and 3 kids. Live couldn’t be better.