Introduction to Matplotlib
To compute the histogram of an image, we are going to use a command from a Python library named Matplotlib. Matplotlib is a vast library, and the module you need from it to plot a histogram is called pyplot
. The pyplot
module gives you access to the plotting functionality of Matplotlib. This plotting functionality is what we need to display histograms.
The code you will need to import this module is as follows:
import matplotlib.pyplot as plt
Alternatively, you can also import the pyplot
module as follows:
from matplotlib import pyplot as plt
Following is an explanation of the syntax for importing the pyplot
module:
Displaying Images with Matplotlib
Using Matplotlib, you can also display images on the console itself, unlike cv2.imshow
, which opens a new window to display the image.
To plot a grayscale image (img
) using Matplotlib, you can use the following code:
imgplot...