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: Resample ``self.dataobj`` if needed.  This method assumes ``self.data_obj`` is a 'channel-last' ndarray.
  
  Args:
      meta_dict: a metadata dictionary for affine, original affine and spatial shape information.
          Optional key is ``"spatial_shape"``.
      resample: if ``True``, the data will be resampled to the spatial shape specified in ``meta_dict``.
      options: keyword arguments passed to ``self.resample_if_needed``,
          currently support ``mode``, defaulting to ``bicubic``.
docstr_tok: ["Resample","``","self.dataobj","``","if","needed",".","This","method","assumes","``","self.data_obj","``","is","a","'channel-last","'","ndarray",".","Args",":","meta_dict",":","a","metadata","dictionary","for","affine",",","original","affine","and","spatial","shape","information",".","Optional","key","is","``","``","spatial_shape","''","``",".","resample",":","if","``","True","``",",","the","data","will","be","resampled","to","the","spatial","shape","specified","in","``","meta_dict","``",".","options",":","keyword","arguments","passed","to","``","self.resample_if_needed","``",",","currently","support","``","mode","``",",","defaulting","to","``","bicubic","``","."]
code: def set_metadata(
      self,
      meta_dict: Mapping | None = None,
      resample: bool = True,
      **options,
  ):
      """
      Resample ``self.dataobj`` if needed.  This method assumes ``self.data_obj`` is a 'channel-last' ndarray.
  
      Args:
          meta_dict: a metadata dictionary for affine, original affine and spatial shape information.
              Optional key is ``"spatial_shape"``.
          resample: if ``True``, the data will be resampled to the spatial shape specified in ``meta_dict``.
          options: keyword arguments passed to ``self.resample_if_needed``,
              currently support ``mode``, defaulting to ``bicubic``.
      """
      spatial_shape = self.get_meta_info(meta_dict)
      if self.output_dtype is None and hasattr(
          self.data_obj, "dtype"
      ):  # pylint: disable=E0203
          self.output_dtype = self.data_obj.dtype  # type: ignore
      self.data_obj = self.resample_and_clip(
          data_array=self.data_obj,
          output_spatial_shape=spatial_shape if resample else None,
          mode=options.pop("mode", InterpolateMode.BICUBIC),
      )
  
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 3 for calling the PILWriter obj's underlying member method code with example usage: obj.set_metadata(meta_dict, resample) without return types