Histograms with OpenCV
OpenCV also gives you a command to generate histograms. To plot, you will need Matplotlib as well. The core strength of this method is that it allows you to find the histogram of your selected region of interest (ROI) in an image. This ROI is communicated to the command with the use of an appropriate mask. This mask is a binary image. It has white pixels on the ROI and black pixels elsewhere.
The command used to compute the histogram of a particular channel of an image is as follows:
cv2.calcHist([images], [channels], mask, [histSize], \ Â Â Â Â Â Â Â Â Â Â Â Â Â [ranges])
Note
The inputs with square brackets must always be given as lists.
Let's take a look at the different parameters:
[images]
: This is the list containing your input image(s). It may be 2D or 3D.[channels]
: This is the index of the plane of the image whose histogram you want to compute. For a grayscale or binary...