docstr: Read ndimage metadata.
  
  Parameters
  ----------
  index : {integer, None}
      If the ImageResource contains multiple ndimages, and index is an
      integer, select the index-th ndimage from among them and return its
      metadata. If index is an ellipsis (...), read and return global
      metadata. If index is None, this plugin reads metadata from the
      first image of the file (index=0) unless the image is a GIF or APNG,
      in which case global metadata is read (index=...).
  exclude_applied : bool
      If True, exclude metadata fields that are applied to the image while
      reading. For example, if the binary data contains a rotation flag,
      the image is rotated by default and the rotation flag is excluded
      from the metadata to avoid confusion.
  
  Returns
  -------
  metadata : dict
      A dictionary of format-specific metadata.
docstr_tok: ["Read","ndimage","metadata",".","Parameters","--","--","--","--","--","index",":","{","integer",",","None","}","If","the","ImageResource","contains","multiple","ndimages",",","and","index","is","an","integer",",","select","the","index-th","ndimage","from","among","them","and","return","its","metadata",".","If","index","is","an","ellipsis","(","...",")",",","read","and","return","global","metadata",".","If","index","is","None",",","this","plugin","reads","metadata","from","the","first","image","of","the","file","(","index=0",")","unless","the","image","is","a","GIF","or","APNG",",","in","which","case","global","metadata","is","read","(","index=","...",")",".","exclude_applied",":","bool","If","True",",","exclude","metadata","fields","that","are","applied","to","the","image","while","reading",".","For","example",",","if","the","binary","data","contains","a","rotation","flag",",","the","image","is","rotated","by","default","and","the","rotation","flag","is","excluded","from","the","metadata","to","avoid","confusion",".","Returns","--","--","--","-","metadata",":","dict","A","dictionary","of","format-specific","metadata","."]
code: def metadata(
      self, index: int = None, exclude_applied: bool = True
  ) -> Dict[str, Any]:
      """Read ndimage metadata.
  
      Parameters
      ----------
      index : {integer, None}
          If the ImageResource contains multiple ndimages, and index is an
          integer, select the index-th ndimage from among them and return its
          metadata. If index is an ellipsis (...), read and return global
          metadata. If index is None, this plugin reads metadata from the
          first image of the file (index=0) unless the image is a GIF or APNG,
          in which case global metadata is read (index=...).
      exclude_applied : bool
          If True, exclude metadata fields that are applied to the image while
          reading. For example, if the binary data contains a rotation flag,
          the image is rotated by default and the rotation flag is excluded
          from the metadata to avoid confusion.
  
      Returns
      -------
      metadata : dict
          A dictionary of format-specific metadata.
  
      """
  
      if index is None:
          if self._image.format == "GIF":
              index = Ellipsis
          elif self._image.custom_mimetype == "image/apng":
              index = Ellipsis
          else:
              index = 0
  
      if isinstance(index, int) and self._image.tell() != index:
          self._image.seek(index)
  
      metadata = self._image.info.copy()
      metadata["mode"] = self._image.mode
      metadata["shape"] = self._image.size
  
      if self._image.mode == "P" and not exclude_applied:
          metadata["palette"] = np.asarray(
              tuple(self._image.palette.colors.keys())
          )
  
      if self._image.getexif():
          exif_data = {
              ExifTags.TAGS.get(key, "unknown"): value
              for key, value in dict(self._image.getexif()).items()
          }
          exif_data.pop("unknown", None)
          metadata.update(exif_data)
  
      if exclude_applied:
          metadata.pop("Orientation", None)
  
      return metadata
  
imports: import sys
  import warnings
  from io import BytesIO
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, cast
  import numpy
  from PIL import ExifTags, GifImagePlugin, Image, ImageSequence, UnidentifiedImageError
  from PIL import __version__
  from ..core.request import URI_BYTES, InitializationError, IOMode, Request
  from ..core.v3_plugin_api import ImageProperties, PluginV3
  from ..typing import ArrayLike
label_desc: Use image node_id 9 for calling the PillowPlugin obj's underlying member method code with example usage: obj.metadata(index, exclude_applied) and returns: metadata