class_docstr: Dictionary-based wrapper of :py:class:`monai.transforms.SaveImage`.
  
  Note:
      Image should be channel-first shape: [C,H,W,[D]].
      If the data is a patch of an image, the patch index will be appended to the filename.
  
  Args:
      keys: keys of the corresponding items to be transformed.
          See also: :py:class:`monai.transforms.compose.MapTransform`
      meta_keys: explicitly indicate the key of the corresponding metadata dictionary.
          For example, for data with key ``image``, the metadata by default is in ``image_meta_dict``.
          The metadata is a dictionary contains values such as ``filename``, ``original_shape``.
          This argument can be a sequence of strings, mapped to the ``keys``.
          If ``None``, will try to construct ``meta_keys`` by ``key_{meta_key_postfix}``.
      meta_key_postfix: if ``meta_keys`` is ``None``, use ``key_{meta_key_postfix}`` to retrieve the metadict.
      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, available extensions: ``.nii.gz``, ``.nii``, ``.png``, ``.dcm``.
                  Handled by ``folder_layout`` instead, if ``folder_layout`` not ``None``.
      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``.
      output_dtype: data type for saving data. Defaults to ``np.float32``.
      allow_missing_keys: don't raise exception if key is missing.
      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 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;
          the supported built-in writer classes are ``"NibabelWriter"``, ``"ITKWriter"``, ``"PILWriter"``.
      output_name_formatter: a callable function (returning a kwargs dict) to format the output file name.
          see also: :py:func:`monai.data.folder_layout.default_name_formatter`.
          If using a custom ``folder_layout``, consider providing your own 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: ["Dictionary-based","wrapper","of",":","py",":","class",":","`","monai.transforms.SaveImage","`",".","Note",":","Image","should","be","channel-first","shape",":","[","C",",","H",",","W",",","[","D","]","]",".","If","the","data","is","a","patch","of","an","image",",","the","patch","index","will","be","appended","to","the","filename",".","Args",":","keys",":","keys","of","the","corresponding","items","to","be","transformed",".","See","also",":",":","py",":","class",":","`","monai.transforms.compose.MapTransform","`","meta_keys",":","explicitly","indicate","the","key","of","the","corresponding","metadata","dictionary",".","For","example",",","for","data","with","key","``","image","``",",","the","metadata","by","default","is","in","``","image_meta_dict","``",".","The","metadata","is","a","dictionary","contains","values","such","as","``","filename","``",",","``","original_shape","``",".","This","argument","can","be","a","sequence","of","strings",",","mapped","to","the","``","keys","``",".","If","``","None","``",",","will","try","to","construct","``","meta_keys","``","by","``","key_","{","meta_key_postfix","}","``",".","meta_key_postfix",":","if","``","meta_keys","``","is","``","None","``",",","use","``","key_","{","meta_key_postfix","}","``","to","retrieve","the","metadict",".","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",",","available","extensions",":","``",".nii.gz","``",",","``",".nii","``",",","``",".png","``",",","``",".dcm","``",".","Handled","by","``","folder_layout","``","instead",",","if","``","folder_layout","``","not","``","None","``",".","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","``",".","output_dtype",":","data","type","for","saving","data",".","Defaults","to","``","np.float32","``",".","allow_missing_keys",":","do","n't","raise","exception","if","key","is","missing",".","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","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",";","the","supported","built-in","writer","classes","are","``","``","NibabelWriter","''","``",",","``","``","ITKWriter","''","``",",","``","``","PILWriter","''","``",".","output_name_formatter",":","a","callable","function","(","returning","a","kwargs","dict",")","to","format","the","output","file","name",".","see","also",":",":","py",":","func",":","`","monai.data.folder_layout.default_name_formatter","`",".","If","using","a","custom","``","folder_layout","``",",","consider","providing","your","own","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","."]
code: def __init__(
      self,
      keys: KeysCollection,
      meta_keys: KeysCollection | None = None,
      meta_key_postfix: str = DEFAULT_POST_FIX,
      output_dir: Path | str = "./",
      output_postfix: str = "trans",
      output_ext: str = ".nii.gz",
      resample: bool = False,
      mode: str = "nearest",
      padding_mode: str = GridSamplePadMode.BORDER,
      scale: int | None = None,
      dtype: DtypeLike = np.float64,
      output_dtype: DtypeLike | None = np.float32,
      allow_missing_keys: bool = False,
      squeeze_end_dims: bool = True,
      data_root_dir: str = "",
      separate_folder: bool = True,
      print_log: bool = True,
      output_format: str = "",
      writer: type[image_writer.ImageWriter] | str | None = None,
      output_name_formatter: Callable[[dict, Transform], dict]
      | None = None,
      folder_layout: monai.data.FolderLayoutBase | None = None,
      savepath_in_metadict: bool = False,
  ) -> None:
      super().__init__(keys, allow_missing_keys)
      self.meta_keys = ensure_tuple_rep(meta_keys, len(self.keys))
      self.meta_key_postfix = ensure_tuple_rep(
          meta_key_postfix, len(self.keys)
      )
      self.saver = SaveImage(
          output_dir=output_dir,
          output_postfix=output_postfix,
          output_ext=output_ext,
          resample=resample,
          mode=mode,
          padding_mode=padding_mode,
          scale=scale,
          dtype=dtype,
          output_dtype=output_dtype,
          squeeze_end_dims=squeeze_end_dims,
          data_root_dir=data_root_dir,
          separate_folder=separate_folder,
          print_log=print_log,
          output_format=output_format,
          writer=writer,
          output_name_formatter=output_name_formatter,
          folder_layout=folder_layout,
          savepath_in_metadict=savepath_in_metadict,
      )
  
imports: from __future__ import annotations
  from pathlib import Path
  from typing import Callable
  import numpy
  import monai
  from monai.config import DtypeLike, KeysCollection
  from monai.data import image_writer
  from monai.data.image_reader import ImageReader
  from monai.transforms.io.array import LoadImage, SaveImage
  from monai.transforms.transform import MapTransform, Transform
  from monai.utils import GridSamplePadMode, ensure_tuple, ensure_tuple_rep
  from monai.utils.enums import PostFix
label_desc: Use image node_id 1 to create a new SaveImaged object from inherited base classes: MapTransform with example: obj = SaveImaged(keys, meta_keys, meta_key_postfix, output_dir, output_postfix, output_ext, resample, mode, padding_mode, scale, dtype, output_dtype, allow_missing_keys, squeeze_end_dims, data_root_dir, separate_folder, print_log, output_format, writer, output_name_formatter, folder_layout, savepath_in_metadict)