W3cubDocs

/Matplotlib 3.1

matplotlib.pyplot.imread

matplotlib.pyplot.imread(fname, format=None) [source]

Read an image from a file into an array.

Parameters:
fname : str or file-like

The image file to read. This can be a filename, a URL or a Python file-like object opened in read-binary mode.

format : str, optional

The image file format assumed for reading the data. If not given, the format is deduced from the filename. If nothing can be deduced, PNG is tried.

Returns:
imagedata : numpy.array

The image data. The returned array has shape

  • (M, N) for grayscale images.
  • (M, N, 3) for RGB images.
  • (M, N, 4) for RGBA images.

Notes

Matplotlib can only read PNGs natively. Further image formats are supported via the optional dependency on Pillow. Note, URL strings are not compatible with Pillow. Check the Pillow documentation for more information.

Examples using matplotlib.pyplot.imread

© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imread.html