class_docstr: Write image data into files on disk using pillow.
  
  It's based on the Image module in PIL library:
  https://pillow.readthedocs.io/en/stable/reference/Image.html
  
  .. code-block:: python
  
      import numpy as np
      from monai.data import PILWriter
  
      np_data = np.arange(48).reshape(3, 4, 4)
      writer = PILWriter(np.uint8)
      writer.set_data_array(np_data, channel_dim=0)
      writer.write("test1.png", verbose=True)
class_docstr_tok: ["Write","image","data","into","files","on","disk","using","pillow",".","It","'s","based","on","the","Image","module","in","PIL","library",":","https",":","\/\/pillow.readthedocs.io\/en\/stable\/reference\/Image.html","..","code-block",":",":","python","import","numpy","as","np","from","monai.data","import","PILWriter","np_data","=","np.arange","(","48",")",".reshape","(","3",",","4",",","4",")","writer","=","PILWriter","(","np.uint8",")","writer.set_data_array","(","np_data",",","channel_dim=0",")","writer.write","(","``","test1.png","''",",","verbose=True",")"]
docstr: Create a PIL object from ``data_array``.
  
  Args:
      data_array: input data array.
      dtype: output data type.
      scale: {``255``, ``65535``} postprocess data by clipping to [0, 1] and scaling
          [0, 255] (uint8) or [0, 65535] (uint16). Default is None to disable scaling.
      reverse_indexing: if ``True``, the data array's first two dimensions will be swapped.
      kwargs: keyword arguments. Currently ``PILImage.fromarray`` will read
          ``image_mode`` from this dictionary, defaults to ``None``.
  
  See also:
  
      - https://pillow.readthedocs.io/en/stable/reference/Image.html
docstr_tok: ["Create","a","PIL","object","from","``","data_array","``",".","Args",":","data_array",":","input","data","array",".","dtype",":","output","data","type",".","scale",":","{","``","255","``",",","``","65535","``","}","postprocess","data","by","clipping","to","[","0",",","1","]","and","scaling","[","0",",","255","]","(","uint8",")","or","[","0",",","65535","]","(","uint16",")",".","Default","is","None","to","disable","scaling",".","reverse_indexing",":","if","``","True","``",",","the","data","array","'s","first","two","dimensions","will","be","swapped",".","kwargs",":","keyword","arguments",".","Currently","``","PILImage.fromarray","``","will","read","``","image_mode","``","from","this","dictionary",",","defaults","to","``","None","``",".","See","also",":","-","https",":","\/\/pillow.readthedocs.io\/en\/stable\/reference\/Image.html"]
code: def create_backend_obj(
      cls,
      data_array: NdarrayOrTensor,
      dtype: DtypeLike = None,
      scale: int | None = 255,
      reverse_indexing: bool = True,
      **kwargs,
  ):
      """
      Create a PIL object from ``data_array``.
  
      Args:
          data_array: input data array.
          dtype: output data type.
          scale: {``255``, ``65535``} postprocess data by clipping to [0, 1] and scaling
              [0, 255] (uint8) or [0, 65535] (uint16). Default is None to disable scaling.
          reverse_indexing: if ``True``, the data array's first two dimensions will be swapped.
          kwargs: keyword arguments. Currently ``PILImage.fromarray`` will read
              ``image_mode`` from this dictionary, defaults to ``None``.
  
      See also:
  
          - https://pillow.readthedocs.io/en/stable/reference/Image.html
      """
      data: np.ndarray = super().create_backend_obj(data_array)
      if scale:
          # scale the data to be in an integer range
          data = np.clip(
              data, 0.0, 1.0
          )  # png writer only can scale data in range [0, 1]
  
          if scale == np.iinfo(np.uint8).max:
              data = (scale * data).astype(np.uint8, copy=False)
          elif scale == np.iinfo(np.uint16).max:
              data = (scale * data).astype(np.uint16, copy=False)
          else:
              raise ValueError(
                  f"Unsupported scale: {scale}, available options are [255, 65535]."
              )
      if dtype is not None:
          data = data.astype(
              get_equivalent_dtype(dtype, np.ndarray), copy=False
          )
      if reverse_indexing:
          data = np.moveaxis(data, 0, 1)
  
      return PILImage.fromarray(
          data, mode=kwargs.pop("image_mode", None)
      )
  
imports: from __future__ import annotations
  from collections.abc import Mapping, Sequence
  from typing import TYPE_CHECKING, Any, cast
  import numpy
  from monai.apps.utils import get_logger
  from monai.config import DtypeLike, NdarrayOrTensor, PathLike
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import affine_to_spacing, ensure_tuple, ensure_tuple_rep, orientation_ras_lps, to_affine_nd
  from monai.transforms.spatial.array import Resize, SpatialResample
  from monai.transforms.utils_pytorch_numpy_unification import ascontiguousarray, moveaxis
  from monai.utils import GridSampleMode, GridSamplePadMode, InterpolateMode, MetaKeys, OptionalImportError, SpaceKeys, convert_data_type, convert_to_tensor, get_equivalent_dtype, look_up_option, optional_import, require_pkg
label_desc: Use image node_id 7 for calling the PILWriter obj's underlying member method code with example usage: obj.create_backend_obj(cls, data_array, dtype, scale, reverse_indexing) and returns: PILImage