Grayscale histograms

OpenCV provides the cv2.calcHist() function in order to calculate the histogram of one or more arrays. Therefore, this function can be applied to single-channel images (for example, grayscale images) and to multi-channel images (for example, BGR images).

In this section, we are going to see how to calculate histograms for grayscale images. The signature for this function is as follows:

cv2.calcHist(images, channels, mask, histSize, ranges[, hist[, accumulate]])

To this, the following applies: