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:
- images: It represents the source image of type uint8 or float32 provided as a list (example, [gray_img]).
- channels: It represents the index of the channel for which we calculate the histogram provided as a list (for example, [0] for grayscale images, or [0],[1],[2] for multi-channel images to calculate the histogram for the first, second, or third channel, respectively...