- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Show a grayscale Open CV image with Matplotlib
To show a grayscale OpenCV image with matplotlib, we can take the following steps
- Set the figure size and adjust the padding between and around the subplots.
- The function imread loads an image from the specified file and returns it.
- The function converts an input image from one color space to another.
- Display the data as an image, i.e., on a 2D regular raster.
- To display the figure, use show() method.
Example
import cv2 from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = cv2.imread("baseball.png") image = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) plt.imshow(image, cmap="gray") plt.show()
Output
- Related Articles
- How to save an array as a grayscale image with Matplotlib/Numpy?
- How to show numpy 2D array as grayscale image in Jupyter Notebook?
- Show Matplotlib graphs to image as fullscreen
- Converting an Image to Grayscale using CSS3
- How to show an image in Matplotlib in different colors with different channels?
- PyTorch – How to convert an image to grayscale?
- Converting an image from colour to grayscale using OpenCV
- Set Grayscale Effect with CSS
- How to convert a colored image to grayscale using Java OpenCV library?
- Converting image to Grayscale without using any methods Java OpenCV.
- Overlay an image segmentation with Numpy and Matplotlib
- How to create a surface plot from a greyscale image with Matplotlib?
- Show the background image only once with CSS
- How to show mouse release event coordinates with Matplotlib?
- How to show minor tick labels on a log-scale with Matplotlib?

Advertisements