Skip to content

Commit c278744

Browse files
authored
Merge pull request #19924 from anntzer/imreadd
DOC: Discourage use of imread & improve its docs.
2 parents 5858cad + f008a90 commit c278744

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/matplotlib/image.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,11 @@ def imread(fname, format=None):
14251425
"""
14261426
Read an image from a file into an array.
14271427
1428+
.. note::
1429+
1430+
This function exists for historical reasons. It is recommended to
1431+
use `PIL.Image.open` instead for loading images.
1432+
14281433
Parameters
14291434
----------
14301435
fname : str or file-like
@@ -1435,9 +1440,11 @@ def imread(fname, format=None):
14351440
for reading and pass the result to Pillow, e.g. with
14361441
``PIL.Image.open(urllib.request.urlopen(url))``.
14371442
format : str, optional
1438-
The image file format assumed for reading the data. If not
1439-
given, the format is deduced from the filename. If nothing can
1440-
be deduced, PNG is tried.
1443+
The image file format assumed for reading the data. The image is
1444+
loaded as a PNG file if *format* is set to "png", if *fname* is a path
1445+
or opened file with a ".png" extension, or if it is an URL. In all
1446+
other cases, *format* is ignored and the format is auto-detected by
1447+
`PIL.Image.open`.
14411448
14421449
Returns
14431450
-------
@@ -1447,6 +1454,10 @@ def imread(fname, format=None):
14471454
- (M, N) for grayscale images.
14481455
- (M, N, 3) for RGB images.
14491456
- (M, N, 4) for RGBA images.
1457+
1458+
PNG images are returned as float arrays (0-1). All other formats are
1459+
returned as int arrays, with a bit depth determined by the file's
1460+
contents.
14501461
"""
14511462
# hide imports to speed initial import on systems with slow linkers
14521463
from urllib import parse

0 commit comments

Comments
 (0)