Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Computer Vision Workshop

You're reading from   The Computer Vision Workshop Develop the skills you need to use computer vision algorithms in your own artificial intelligence projects

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201774
Length 568 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Nikhil Singh Nikhil Singh
Author Profile Icon Nikhil Singh
Nikhil Singh
Hafsa Asad Hafsa Asad
Author Profile Icon Hafsa Asad
Hafsa Asad
Vishwesh Ravi Shrimali Vishwesh Ravi Shrimali
Author Profile Icon Vishwesh Ravi Shrimali
Vishwesh Ravi Shrimali
Arrow right icon
View More author details
Toc

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:

Figure 3.2: Explanation of the syntax

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime