class_docstr: Save the image (in the form of torch tensor or numpy ndarray) and metadata dictionary into files.
  
  The name of saved file will be `{input_image_name}_{output_postfix}{output_ext}`,
  where the `input_image_name` is extracted from the provided metadata dictionary.
  If no metadata provided, a running index starting from 0 will be used as the filename prefix.
  
  Args:
      output_dir: output image directory.
      Handled by ``folder_layout`` instead, if ``folder_layout`` is not ``None``.
      output_postfix: a string appended to all output file names, default to `trans`.
      Handled by ``folder_layout`` instead, if ``folder_layout`` is not ``None``.
      output_ext: output file extension name.
      Handled by ``folder_layout`` instead, if ``folder_layout`` is not ``None``.
      output_dtype: data type (if not None) for saving data. Defaults to ``np.float32``.
      resample: whether to resample image (if needed) before saving the data array,
          based on the ``"spatial_shape"`` (and ``"original_affine"``) from metadata.
      mode: This option is used when ``resample=True``. Defaults to ``"nearest"``.
          Depending on the writers, the possible options are
  
          - {``"bilinear"``, ``"nearest"``, ``"bicubic"``}.
            See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample
          - {``"nearest"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``, ``"area"``}.
            See also: https://pytorch.org/docs/stable/nn.functional.html#interpolate
  
      padding_mode: This option is used when ``resample = True``. Defaults to ``"border"``.
          Possible options are {``"zeros"``, ``"border"``, ``"reflection"``}
          See also: https://pytorch.org/docs/stable/nn.functional.html#grid-sample
      scale: {``255``, ``65535``} postprocess data by clipping to [0, 1] and scaling
          [0, 255] (``uint8``) or [0, 65535] (``uint16``). Default is ``None`` (no scaling).
      dtype: data type during resampling computation. Defaults to ``np.float64`` for best precision.
          if ``None``, use the data type of input data. To set the output data type, use ``output_dtype``.
      squeeze_end_dims: if ``True``, any trailing singleton dimensions will be removed (after the channel
          has been moved to the end). So if input is (C,H,W,D), this will be altered to (H,W,D,C), and
          then if C==1, it will be saved as (H,W,D). If D is also 1, it will be saved as (H,W). If ``False``,
          image will always be saved as (H,W,D,C).
      data_root_dir: if not empty, it specifies the beginning parts of the input file's
          absolute path. It's used to compute ``input_file_rel_path``, the relative path to the file from
          ``data_root_dir`` to preserve folder structure when saving in case there are files in different
          folders with the same file names. For example, with the following inputs:
  
          - input_file_name: ``/foo/bar/test1/image.nii``
          - output_postfix: ``seg``
          - output_ext: ``.nii.gz``
          - output_dir: ``/output``
          - data_root_dir: ``/foo/bar``
  
          The output will be: ``/output/test1/image/image_seg.nii.gz``
  
          Handled by ``folder_layout`` instead, if ``folder_layout`` is not ``None``.
      separate_folder: whether to save every file in a separate folder. For example: for the input filename
          ``image.nii``, postfix ``seg`` and ``folder_path`` ``output``, if ``separate_folder=True``, it will be
          saved as: ``output/image/image_seg.nii``, if ``False``, saving as ``output/image_seg.nii``.
          Default to ``True``.
          Handled by ``folder_layout`` instead, if ``folder_layout`` is not ``None``.
      print_log: whether to print logs when saving. Default to ``True``.
      output_format: an optional string of filename extension to specify the output image writer.
          see also: ``monai.data.image_writer.SUPPORTED_WRITERS``.
      writer: a customised ``monai.data.ImageWriter`` subclass to save data arrays.
          if ``None``, use the default writer from ``monai.data.image_writer`` according to ``output_ext``.
          if it's a string, it's treated as a class name or dotted path (such as ``"monai.data.ITKWriter"``);
          the supported built-in writer classes are ``"NibabelWriter"``, ``"ITKWriter"``, ``"PILWriter"``.
      channel_dim: the index of the channel dimension. Default to ``0``.
          ``None`` to indicate no channel dimension.
      output_name_formatter: a callable function (returning a kwargs dict) to format the output file name.
          If using a custom ``monai.data.FolderLayoutBase`` class in ``folder_layout``, consider providing
          your own formatter.
          see also: :py:func:`monai.data.folder_layout.default_name_formatter`.
      folder_layout: A customized ``monai.data.FolderLayoutBase`` subclass to define file naming schemes.
          if ``None``, uses the default ``FolderLayout``.
      savepath_in_metadict: if ``True``, adds a key ``"saved_to"`` to the metadata, which contains the path
          to where the input image has been saved.
class_docstr_tok: ["Save","the","image","(","in","the","form","of","torch","tensor","or","numpy","ndarray",")","and","metadata","dictionary","into","files",".","The","name","of","saved","file","will","be","`","{","input_image_name","}","_","{","output_postfix","}","{","output_ext","}","`",",","where","the","`","input_image_name","`","is","extracted","from","the","provided","metadata","dictionary",".","If","no","metadata","provided",",","a","running","index","starting","from","0","will","be","used","as","the","filename","prefix",".","Args",":","output_dir",":","output","image","directory",".","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","is","not","``","None","``",".","output_postfix",":","a","string","appended","to","all","output","file","names",",","default","to","`","trans","`",".","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","is","not","``","None","``",".","output_ext",":","output","file","extension","name",".","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","is","not","``","None","``",".","output_dtype",":","data","type","(","if","not","None",")","for","saving","data",".","Defaults","to","``","np.float32","``",".","resample",":","whether","to","resample","image","(","if","needed",")","before","saving","the","data","array",",","based","on","the","``","``","spatial_shape","''","``","(","and","``","``","original_affine","''","``",")","from","metadata",".","mode",":","This","option","is","used","when","``","resample=True","``",".","Defaults","to","``","``","nearest","''","``",".","Depending","on","the","writers",",","the","possible","options","are","-","{","``","``","bilinear","''","``",",","``","``","nearest","''","``",",","``","``","bicubic","''","``","}",".","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/nn.functional.html","#","grid-sample","-","{","``","``","nearest","''","``",",","``","``","linear","''","``",",","``","``","bilinear","''","``",",","``","``","bicubic","''","``",",","``","``","trilinear","''","``",",","``","``","area","''","``","}",".","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/nn.functional.html","#","interpolate","padding_mode",":","This","option","is","used","when","``","resample","=","True","``",".","Defaults","to","``","``","border","''","``",".","Possible","options","are","{","``","``","zeros","''","``",",","``","``","border","''","``",",","``","``","reflection","''","``","}","See","also",":","https",":","\/\/pytorch.org\/docs\/stable\/nn.functional.html","#","grid-sample","scale",":","{","``","255","``",",","``","65535","``","}","postprocess","data","by","clipping","to","[","0",",","1","]","and","scaling","[","0",",","255","]","(","``","uint8","``",")","or","[","0",",","65535","]","(","``","uint16","``",")",".","Default","is","``","None","``","(","no","scaling",")",".","dtype",":","data","type","during","resampling","computation",".","Defaults","to","``","np.float64","``","for","best","precision",".","if","``","None","``",",","use","the","data","type","of","input","data",".","To","set","the","output","data","type",",","use","``","output_dtype","``",".","squeeze_end_dims",":","if","``","True","``",",","any","trailing","singleton","dimensions","will","be","removed","(","after","the","channel","has","been","moved","to","the","end",")",".","So","if","input","is","(","C",",","H",",","W",",","D",")",",","this","will","be","altered","to","(","H",",","W",",","D",",","C",")",",","and","then","if","C==1",",","it","will","be","saved","as","(","H",",","W",",","D",")",".","If","D","is","also","1",",","it","will","be","saved","as","(","H",",","W",")",".","If","``","False","``",",","image","will","always","be","saved","as","(","H",",","W",",","D",",","C",")",".","data_root_dir",":","if","not","empty",",","it","specifies","the","beginning","parts","of","the","input","file's","absolute","path",".","It","'s","used","to","compute","``","input_file_rel_path","``",",","the","relative","path","to","the","file","from","``","data_root_dir","``","to","preserve","folder","structure","when","saving","in","case","there","are","files","in","different","folders","with","the","same","file","names",".","For","example",",","with","the","following","inputs",":","-","input_file_name",":","``","\/foo\/bar\/test1\/image.nii","``","-","output_postfix",":","``","seg","``","-","output_ext",":","``",".nii.gz","``","-","output_dir",":","``","\/output","``","-","data_root_dir",":","``","\/foo\/bar","``","The","output","will","be",":","``","\/output\/test1\/image\/image_seg.nii.gz","``","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","is","not","``","None","``",".","separate_folder",":","whether","to","save","every","file","in","a","separate","folder",".","For","example",":","for","the","input","filename","``","image.nii","``",",","postfix","``","seg","``","and","``","folder_path","``","``","output","``",",","if","``","separate_folder=True","``",",","it","will","be","saved","as",":","``","output\/image\/image_seg.nii","``",",","if","``","False","``",",","saving","as","``","output\/image_seg.nii","``",".","Default","to","``","True","``",".","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","is","not","``","None","``",".","print_log",":","whether","to","print","logs","when","saving",".","Default","to","``","True","``",".","output_format",":","an","optional","string","of","filename","extension","to","specify","the","output","image","writer",".","see","also",":","``","monai.data.image_writer.SUPPORTED_WRITERS","``",".","writer",":","a","customised","``","monai.data.ImageWriter","``","subclass","to","save","data","arrays",".","if","``","None","``",",","use","the","default","writer","from","``","monai.data.image_writer","``","according","to","``","output_ext","``",".","if","it","'s","a","string",",","it","'s","treated","as","a","class","name","or","dotted","path","(","such","as","``","``","monai.data.ITKWriter","''","``",")",";","the","supported","built-in","writer","classes","are","``","``","NibabelWriter","''","``",",","``","``","ITKWriter","''","``",",","``","``","PILWriter","''","``",".","channel_dim",":","the","index","of","the","channel","dimension",".","Default","to","``","0","``",".","``","None","``","to","indicate","no","channel","dimension",".","output_name_formatter",":","a","callable","function","(","returning","a","kwargs","dict",")","to","format","the","output","file","name",".","If","using","a","custom","``","monai.data.FolderLayoutBase","``","class","in","``","folder_layout","``",",","consider","providing","your","own","formatter",".","see","also",":",":","py",":","func",":","`","monai.data.folder_layout.default_name_formatter","`",".","folder_layout",":","A","customized","``","monai.data.FolderLayoutBase","``","subclass","to","define","file","naming","schemes",".","if","``","None","``",",","uses","the","default","``","FolderLayout","``",".","savepath_in_metadict",":","if","``","True","``",",","adds","a","key","``","``","saved_to","''","``","to","the","metadata",",","which","contains","the","path","to","where","the","input","image","has","been","saved","."]
docstr: Set the options for the underlying writer by updating the `self.*_kwargs` dictionaries.
  
  The arguments correspond to the following usage:
  
      - `writer = ImageWriter(**init_kwargs)`
      - `writer.set_data_array(array, **data_kwargs)`
      - `writer.set_metadata(meta_data, **meta_kwargs)`
      - `writer.write(filename, **write_kwargs)`
docstr_tok: ["Set","the","options","for","the","underlying","writer","by","updating","the","`","self",".","*","_kwargs","`","dictionaries",".","The","arguments","correspond","to","the","following","usage",":","-","`","writer","=","ImageWriter","(","*","*","init_kwargs",")","`","-","`","writer.set_data_array","(","array",",","*","*","data_kwargs",")","`","-","`","writer.set_metadata","(","meta_data",",","*","*","meta_kwargs",")","`","-","`","writer.write","(","filename",",","*","*","write_kwargs",")","`"]
code: def set_options(
      self,
      init_kwargs=None,
      data_kwargs=None,
      meta_kwargs=None,
      write_kwargs=None,
  ):
      """
      Set the options for the underlying writer by updating the `self.*_kwargs` dictionaries.
  
      The arguments correspond to the following usage:
  
          - `writer = ImageWriter(**init_kwargs)`
          - `writer.set_data_array(array, **data_kwargs)`
          - `writer.set_metadata(meta_data, **meta_kwargs)`
          - `writer.write(filename, **write_kwargs)`
  
      """
      if init_kwargs is not None:
          self.init_kwargs.update(init_kwargs)
      if data_kwargs is not None:
          self.data_kwargs.update(data_kwargs)
      if meta_kwargs is not None:
          self.meta_kwargs.update(meta_kwargs)
      if write_kwargs is not None:
          self.write_kwargs.update(write_kwargs)
      return self
  
imports: from __future__ import annotations
  import inspect
  import logging
  import sys
  import traceback
  import warnings
  from collections.abc import Sequence
  from pathlib import Path
  from pydoc import locate
  from typing import Callable
  import numpy
  import torch
  from monai.config import DtypeLike, NdarrayOrTensor, PathLike
  from monai.data import image_writer
  from monai.data.folder_layout import FolderLayout, FolderLayoutBase, default_name_formatter
  from monai.data.image_reader import ImageReader, ITKReader, NibabelReader, NrrdReader, NumpyReader, PILReader, PydicomReader
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import is_no_channel
  from monai.transforms.transform import Transform
  from monai.transforms.utility.array import EnsureChannelFirst
  from monai.utils import GridSamplePadMode
  from monai.utils import ImageMetaKey
  from monai.utils import OptionalImportError, convert_to_dst_type, ensure_tuple, look_up_option, optional_import
label_desc: Use image node_id 2 for calling the SaveImage obj's underlying member method code with example usage: obj.set_options(init_kwargs, data_kwargs, meta_kwargs, write_kwargs) and returns: self