imageio.plugins.pillow.PillowPlugin.read#

PillowPlugin.read(*, index=None, mode=None, rotate=False, apply_gamma=False) ndarray[source]#

Parses the given URI and creates a ndarray from it.

Parameters:
index{integer}

If the ImageResource contains multiple ndimages, and index is an integer, select the index-th ndimage from among them and return it. If index is an ellipsis (…), read all ndimages in the file and stack them along a new batch dimension and return them. If index is None, this plugin reads the first image of the file (index=0) unless the image is a GIF or APNG, in which case all images are read (index=…).

mode{str, None}

Convert the image to the given mode before returning it. If None, the mode will be left unchanged. Possible modes can be found at: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes

rotate{bool}

If set to True and the image contains an EXIF orientation tag, apply the orientation before returning the ndimage.

apply_gamma{bool}

If True and the image contains metadata about gamma, apply gamma correction to the image.

Returns:
ndimagendarray

A numpy array containing the loaded image data

Notes

If you open a GIF - or any other format using color pallets - you may wish to manually set the mode parameter. Otherwise, the numbers in the returned image will refer to the entries in the color pallet, which is discarded during conversion to ndarray.