Histogram Computation

Build on the fundamentals of a histogram and learn to compute histograms in this lesson.

What is a histogram?

In OpenCV, the histogram is used to visualize the distribution of pixel intensities in an image. It is a graphical plot that depicts the number of pixels in images with certain intensities.

Histogram-based data analysis is one of the most important uses of the OpenCV library. It is widely used in image classification and recognition.

To calculate a histogram, we can count the number of pixels that have certain intensities. For example, if there are 4 pixels with intensity 9, there will be a point at (4,9) in the histogram. In a similar manner, points are taken from all different intensities and the histogram is drawn. Let’s learn to draw a histogram using OpenCV.

Histogram for grayscale image

First, we need to convert our image to grayscale.

 ...