class_docstr: Write data and metadata into files on disk using ITK-python.
  
  .. code-block:: python
  
      import numpy as np
      from monai.data import ITKWriter
  
      np_data = np.arange(48).reshape(3, 4, 4)
  
      # write as 3d spatial image no channel
      writer = ITKWriter(output_dtype=np.float32)
      writer.set_data_array(np_data, channel_dim=None)
      # optionally set metadata affine
      writer.set_metadata({"affine": np.eye(4), "original_affine": -1 * np.eye(4)})
      writer.write("test1.nii.gz")
  
      # write as 2d image, channel-first
      writer = ITKWriter(output_dtype=np.uint8)
      writer.set_data_array(np_data, channel_dim=0)
      writer.set_metadata({"spatial_shape": (5, 5)})
      writer.write("test1.png")
class_docstr_tok: ["Write","data","and","metadata","into","files","on","disk","using","ITK-python",".","..","code-block",":",":","python","import","numpy","as","np","from","monai.data","import","ITKWriter","np_data","=","np.arange","(","48",")",".reshape","(","3",",","4",",","4",")","#","write","as","3d","spatial","image","no","channel","writer","=","ITKWriter","(","output_dtype=np.float32",")","writer.set_data_array","(","np_data",",","channel_dim=None",")","#","optionally","set","metadata","affine","writer.set_metadata","(","{","``","affine","''",":","np.eye","(","4",")",",","``","original_affine","''",":","-1","*","np.eye","(","4",")","}",")","writer.write","(","``","test1.nii.gz","''",")","#","write","as","2d","image",",","channel-first","writer","=","ITKWriter","(","output_dtype=np.uint8",")","writer.set_data_array","(","np_data",",","channel_dim=0",")","writer.set_metadata","(","{","``","spatial_shape","''",":","(","5",",","5",")","}",")","writer.write","(","``","test1.png","''",")"]
docstr: Create an ITK object from ``self.create_backend_obj(self.obj, ...)`` and call ``itk.imwrite``.
  
  Args:
      filename: filename or PathLike object.
      verbose: if ``True``, log the progress.
      kwargs: keyword arguments passed to ``itk.imwrite``,
          currently support ``compression`` and ``imageio``.
  
  See also:
  
      - https://github.com/InsightSoftwareConsortium/ITK/blob/v5.2.1/Wrapping/Generators/Python/itk/support/extras.py#L809
docstr_tok: ["Create","an","ITK","object","from","``","self.create_backend_obj","(","self.obj",",","...",")","``","and","call","``","itk.imwrite","``",".","Args",":","filename",":","filename","or","PathLike","object",".","verbose",":","if","``","True","``",",","log","the","progress",".","kwargs",":","keyword","arguments","passed","to","``","itk.imwrite","``",",","currently","support","``","compression","``","and","``","imageio","``",".","See","also",":","-","https",":","\/\/github.com\/InsightSoftwareConsortium\/ITK\/blob\/v5.2.1\/Wrapping\/Generators\/Python\/itk\/support\/extras.py","#","L809"]
code: def write(self, filename: PathLike, verbose: bool = False, **kwargs):
      """
      Create an ITK object from ``self.create_backend_obj(self.obj, ...)`` and call ``itk.imwrite``.
  
      Args:
          filename: filename or PathLike object.
          verbose: if ``True``, log the progress.
          kwargs: keyword arguments passed to ``itk.imwrite``,
              currently support ``compression`` and ``imageio``.
  
      See also:
  
          - https://github.com/InsightSoftwareConsortium/ITK/blob/v5.2.1/Wrapping/Generators/Python/itk/support/extras.py#L809
      """
      super().write(filename, verbose=verbose)
      self.data_obj = self.create_backend_obj(
          cast(NdarrayOrTensor, self.data_obj),
          channel_dim=self.channel_dim,
          affine=self.affine,
          dtype=self.output_dtype,
          affine_lps_to_ras=self.affine_lps_to_ras,  # type: ignore
          **kwargs,
      )
      itk.imwrite(
          self.data_obj,
          filename,
          compression=kwargs.pop("compression", False),
          imageio=kwargs.pop("imageio", 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 4 for calling the ITKWriter obj's underlying member method code with example usage: obj.write(filename, verbose) without return types