Skip to main content
`Ctrl`+`K`

# imageio.plugins.pillow.PillowPlugin.read

PillowPlugin.read(*, index: int = None, mode: str = None, rotate: bool = False, apply_gamma: bool = False, writeable_output: bool = True, pilmode: str = None, exifrotate: bool = None, as_gray: bool = None) → ndarray

  Parses the given URI and creates a ndarray from it.

  Parameters:
    index int

      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

      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 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.

    writable_output bool

      If True, ensure that the image is writable before returning it to the user. This incurs a full copy of the pixel data if the data served by pillow is read-only. Consequentially, setting this flag to False improves performance for some images.

    pilmode str

      Deprecated, use mode instead.

    exifrotate bool

      Deprecated, use rotate instead.

    as_gray bool

      Deprecated. Exists to raise a constructive error message.

  Returns:
    ndimage ndarray

      A numpy array containing the loaded image data

  Notes

  If you read a paletted image (e.g. GIF) then the plugin will apply the palette by default. Should you wish to read the palette indices of each pixel use `mode="P"`. The coresponding color pallete can be found in the image’s metadata using the `palette` key when metadata is extracted using the `exclude_applied=False` kwarg. The latter is needed, as palettes are applied by default and hence excluded by default to keep metadata and pixel data consistent.