code: def __call__(self, data) -> Tuple[Any, Any]:
      logger.setLevel(data.get("logging", "INFO").upper())
  
      path = data.get("image_path")
      ext = file_ext(path) if path else None
      dtype = data.get(self.key_dtype, None)
      compress = data.get(self.key_compress, False)
      write_to_file = data.get(self.key_write_to_file, True)
  
      ext = (
          data.get(self.key_extension)
          if data.get(self.key_extension)
          else ext
      )
      write_to_file = write_to_file if ext else False
      logger.info(
          f"Result ext: {ext}; write_to_file: {write_to_file}; dtype: {dtype}"
      )
  
      if isinstance(data[self.label], MetaTensor):
          image_np = data[self.label].array
      else:
          image_np = data[self.label]
  
      # Always using Restored as the last transform before writing
      meta_dict = data.get(f"{self.ref_image}_{self.meta_key_postfix}")
      affine = meta_dict.get("affine") if meta_dict else None
      if affine is None and isinstance(
          data[self.ref_image], MetaTensor
      ):
          affine = data[self.ref_image].affine
  
      logger.debug(
          f"Image: {image_np.shape}; Data Image: {data[self.label].shape}"
      )
  
      output_file = None
      output_json = data.get(self.json, {})
      if write_to_file:
          output_file = tempfile.NamedTemporaryFile(suffix=ext).name
          logger.debug(f"Saving Image to: {output_file}")
  
          if self.is_multichannel_image(image_np):
              if ext != ".seg.nrrd":
                  logger.warning(
                      f"Using extension '{ext}' with multi-channel 4D label will probably fail"
                      + "Consider to use extension '.seg.nrrd'"
                  )
              labels = data.get("labels")
              color_map = data.get("color_map")
              logger.debug("Using write_seg_nrrd...")
              write_seg_nrrd(
                  image_np,
                  output_file,
                  dtype,
                  affine,
                  labels,
                  color_map,
              )
          # Issue with slicer:: https://discourse.itk.org/t/saving-non-orthogonal-volume-in-nifti-format/2760/22
          elif (
              self.nibabel
              and ext
              and ext.lower() in [".nii", ".nii.gz"]
          ):
              logger.debug("Using MONAI write_nifti...")
              write_nifti(
                  image_np,
                  output_file,
                  affine=affine,
                  output_dtype=dtype,
              )
          else:
              write_itk(
                  image_np,
                  output_file,
                  affine if len(image_np.shape) > 2 else None,
                  dtype,
                  compress,
              )
      else:
          output_file = image_np
  
      return output_file, output_json
  
imports: import logging
  import tempfile
  from typing import Any, Dict, Iterable, List, Optional, Tuple
  import itk
  import nrrd
  import numpy
  import torch
  from monai.data import MetaTensor
  from monai.data.image_writer import NibabelWriter
  from monailabel.utils.others.detection import create_slicer_detection_json
  from monailabel.utils.others.generic import file_ext
  from monailabel.utils.others.pathology import create_asap_annotations_xml, create_dsa_annotations_json
label_desc: Use image node_id 2 for calling the Writer obj's underlying member method code with example usage: obj.__call__(data) and returns: output_file,  output_json