You are currently viewing How to Read and Show Image using Matplotlib

How to Read and Show Image using Matplotlib

One way is to read and show image using matplotlib library in python. Matplotlib is a library for 2D plotting that has support for multiple formats, including PNG, JPG, and TIFF. You can read images using matplotlib by passing in the path to the image as a string argument to the imread() function. The imread function returns a NumPy array, which can then be used to plot the image using matplotlib’s pyplot module.

One way is to read and show image using matplotlib library in python. Matplotlib is a library for 2D plotting that has support for multiple formats, including PNG, JPG, and TIFF. You can read images using matplotlib by passing in the path to the image as a string argument to the imread() function. The imread function returns a NumPy array, which can then be used to plot the image using matplotlib’s pyplot module.

Install Imageio in Python

You can install matplotlib python library using PIP.

pip install matplotlib

Read Image using Matplotlib Code:

import matplotlib.image as mpimg
img_matplotlib = mpimg.imread('/content/solar.jpeg')
print(img_matplotlib)

Output:

[[[25 14 30]
  [28 17 33]
  [32 19 36]
  ...
  [18 16 40]
  [18 12 40]
  [20  9 39]]


 ...


 [[ 4  4  4]
  [ 4  4  4]
  [ 4  4  4]
  ...
  [ 4  4  4]
  [ 4  4  4]
  [ 4  4  4]]]

Show Image using Matplotlib Code:

from matplotlib import pyplot as plt
plt.imshow(img_matplotlib)

Output:

Other Python Libraries to Read Images:

How to Read and Show Image using OpenCV

How to Read and Show Image using Skimage

How to Read and Show Image using Pillow

How to Read and Show Image using Imageio

Leave a Reply