Skip to content

Discourage use of imread & improve its docs. #19924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,11 @@ def imread(fname, format=None):
"""
Read an image from a file into an array.

.. note::

This function exists for historical reasons. It is recommended to
use `PIL.Image.open` instead for loading images.

Parameters
----------
fname : str or file-like
Expand All @@ -1435,9 +1440,11 @@ def imread(fname, format=None):
for reading and pass the result to Pillow, e.g. with
``PIL.Image.open(urllib.request.urlopen(url))``.
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.
The image file format assumed for reading the data. The image is
loaded as a PNG file if *format* is set to "png", if *fname* is a path
or opened file with a ".png" extension, or if it is an URL. In all
other cases, *format* is ignored and the format is auto-detected by
`PIL.Image.open`.

Returns
-------
Expand All @@ -1447,6 +1454,10 @@ def imread(fname, format=None):
- (M, N) for grayscale images.
- (M, N, 3) for RGB images.
- (M, N, 4) for RGBA images.

PNG images are returned as float arrays (0-1). All other formats are
returned as int arrays, with a bit depth determined by the file's
contents.
"""
# hide imports to speed initial import on systems with slow linkers
from urllib import parse
Expand Down