class_docstr: Image [`Feature`] to read image data from an image file.
  
  Input: The Image feature accepts as input:
  - A `str`: Absolute path to the image file (i.e. random access is allowed).
  - A `dict` with the keys:
  
      - `path`: String with relative path of the image file to the archive file.
      - `bytes`: Bytes of the image file.
  
    This is useful for archived files with sequential access.
  
  - An `np.ndarray`: NumPy array representing an image.
  - A `PIL.Image.Image`: PIL image object.
  
  Args:
      decode (`bool`, defaults to `True`):
          Whether to decode the image data. If `False`,
          returns the underlying dictionary in the format `{"path": image_path, "bytes": image_bytes}`.
  
  Examples:
  
  ```py
  >>> from datasets import load_dataset, Image
  >>> ds = load_dataset("beans", split="train")
  >>> ds.features["image"]
  Image(decode=True, id=None)
  >>> ds[0]["image"]
  <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=500x500 at 0x15E52E7F0>
  >>> ds = ds.cast_column('image', Image(decode=False))
  {'bytes': None,
   'path': '/root/.cache/huggingface/datasets/downloads/extracted/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292/train/healthy/healthy_train.85.jpg'}
  ```
class_docstr_tok: ["Image","[","`","Feature","`","]","to","read","image","data","from","an","image","file",".","Input",":","The","Image","feature","accepts","as","input",":","-","A","`","str","`",":","Absolute","path","to","the","image","file","(","i.e",".","random","access","is","allowed",")",".","-","A","`","dict","`","with","the","keys",":","-","`","path","`",":","String","with","relative","path","of","the","image","file","to","the","archive","file",".","-","`","bytes","`",":","Bytes","of","the","image","file",".","This","is","useful","for","archived","files","with","sequential","access",".","-","An","`","np.ndarray","`",":","NumPy","array","representing","an","image",".","-","A","`","PIL.Image.Image","`",":","PIL","image","object",".","Args",":","decode","(","`","bool","`",",","defaults","to","`","True","`",")",":","Whether","to","decode","the","image","data",".","If","`","False","`",",","returns","the","underlying","dictionary","in","the","format","`","{","``","path","''",":","image_path",",","``","bytes","''",":","image_bytes","}","`",".","Examples",":","``","`","py",">",">",">","from","datasets","import","load_dataset",",","Image",">",">",">","ds","=","load_dataset","(","``","beans","''",",","split=","''","train","''",")",">",">",">","ds.features","[","``","image","''","]","Image","(","decode=True",",","id=None",")",">",">",">","ds","[","0","]","[","``","image","''","]","<","PIL.JpegImagePlugin.JpegImageFile","image","mode=RGB","size=500x500","at","0x15E52E7F0",">",">",">",">","ds","=","ds.cast_column","(","'image","'",",","Image","(","decode=False",")",")","{","'bytes","'",":","None",",","'path","'",":","'\/root\/.cache\/huggingface\/datasets\/downloads\/extracted\/b0a21163f78769a2cf11f58dfc767fb458fc7cea5c05dccc0144a2c0f0bc1292\/train\/healthy\/healthy_train.85.jpg","'","}","``","`"]
docstr: Encode example into a format for Arrow.
  
  Args:
      value (`str`, `np.ndarray`, `PIL.Image.Image` or `dict`):
          Data passed as input to Image feature.
  
  Returns:
      `dict` with "path" and "bytes" fields
docstr_tok: ["Encode","example","into","a","format","for","Arrow",".","Args",":","value","(","`","str","`",",","`","np.ndarray","`",",","`","PIL.Image.Image","`","or","`","dict","`",")",":","Data","passed","as","input","to","Image","feature",".","Returns",":","`","dict","`","with","``","path","''","and","``","bytes","''","fields"]
code: def encode_example(
      self,
      value: Union[str, bytes, dict, np.ndarray, "PIL.Image.Image"],
  ) -> dict:
      """Encode example into a format for Arrow.
  
      Args:
          value (`str`, `np.ndarray`, `PIL.Image.Image` or `dict`):
              Data passed as input to Image feature.
  
      Returns:
          `dict` with "path" and "bytes" fields
      """
      if config.PIL_AVAILABLE:
          import PIL.Image
      else:
          raise ImportError(
              "To support encoding images, please install 'Pillow'."
          )
  
      if isinstance(value, list):
          value = np.array(value)
  
      if isinstance(value, str):
          return {"path": value, "bytes": None}
      elif isinstance(value, bytes):
          return {"path": None, "bytes": value}
      elif isinstance(value, np.ndarray):
          # convert the image array to PNG/TIFF bytes
          return encode_np_array(value)
      elif isinstance(value, PIL.Image.Image):
          # convert the PIL image to bytes (default format is PNG/TIFF)
          return encode_pil_image(value)
      elif value.get("path") is not None and os.path.isfile(
          value["path"]
      ):
          # we set "bytes": None to not duplicate the data if they're already available locally
          return {"bytes": None, "path": value.get("path")}
      elif (
          value.get("bytes") is not None
          or value.get("path") is not None
      ):
          # store the image bytes, and path is used to infer the image format using the file extension
          return {
              "bytes": value.get("bytes"),
              "path": value.get("path"),
          }
      else:
          raise ValueError(
              f"An image sample should have one of 'path' or 'bytes' but they are missing or None in {value}."
          )
  
imports: import os
  import sys
  import warnings
  from dataclasses import dataclass, field
  from io import BytesIO
  from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union
  import numpy
  import pyarrow
  from ..None import config
  from ..download.download_config import DownloadConfig
  from ..download.streaming_download_manager import xopen
  from ..table import array_cast
  from ..utils.file_utils import is_local_path
  from ..utils.py_utils import first_non_null_value, no_op_if_value_is_null, string_to_dict
label_desc: Use image node_id 2 for calling the Image obj's underlying member method code with example usage: obj.encode_example(value) and returns: dict, dict, encode_np_array, encode_pil_image, dict, dict