- 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
How to read an input image and print it into an array in matplotlib?
To read an input image and print it into an array in matplotlib, we can take the following steps
Steps
Set the figure size and adjust the padding between and around the subplots.
Read an image from a file into an array. Use plt.imread() method.
Print the Numpy array of the image.
To turn off the axis, use axis('off') method.
To display the figure, use Show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True im = plt.imread("forest.jpg") print("Numpy array of the image is: ", im) im = plt.imshow(im) plt.axis('off') plt.show()
Output
It will produce the following output −
On the console, you will get the NumPy array of this image −
Numpy array of the image is −
[[[ 47 129 211] [ 47 129 211] [ 49 130 212] ... [ 50 76 109] [ 52 77 108] [ 41 66 97]] [[ 47 129 211] [ 47 129 211] [ 49 130 212] ... [ 43 69 102] [ 51 76 107] [ 46 71 102]] [[ 45 130 211] [ 45 130 211] [ 48 130 212] ... [ 42 67 98] [ 45 70 101] [ 49 74 105]] ... [[102 53 21] [101 51 18] [111 59 22] ... [ 28 17 11] [ 31 16 9] [ 33 16 9]] [[ 99 49 14] [ 85 35 0] [100 50 13] ... [ 29 16 10] [ 30 15 8] [ 33 16 9]] [[ 93 45 7] [ 91 46 7] [ 93 47 11] ... [ 29 16 10] [ 36 19 12] [ 39 20 14]]]
- Related Articles
- How to convert/read an input stream into a string in java?
- How to Read and Print an Integer value in C++
- Read an image with OpenCV and display it with Tkinter
- How to read an image in Python OpenCV?
- How to read a CSV file and store the values into an array in C#?
- How to save an array as a grayscale image with Matplotlib/Numpy?
- How to plot an animated image matrix in matplotlib?
- How to read an image file in internal storage in android?
- How to convert an object into an array in JavaScript?
- How to read an input value from a JTextField and add to a JList in Java?
- How to place an image into a frame in Tkinter?
- How to read data from scanner to an array in java?
- How to remove grid lines from an image in Python Matplotlib?
- Overlay an image segmentation with Numpy and Matplotlib
- How to plot an array in Python using Matplotlib?

Advertisements