code: def nifti_to_dicom_seg(
      series_dir, label, label_info, file_ext="*", use_itk=True
  ) -> str:
      start = time.time()
  
      label_np, meta_dict = LoadImage(image_only=False)(label)
      unique_labels = np.unique(label_np.flatten()).astype(np.int_)
      unique_labels = unique_labels[unique_labels != 0]
  
      info = label_info[0] if label_info and 0 < len(label_info) else {}
      model_name = info.get("model_name", "AIName")
  
      segment_attributes = []
      for i, idx in enumerate(unique_labels):
          info = (
              label_info[i]
              if label_info and i < len(label_info)
              else {}
          )
          name = info.get("name", "unknown")
          description = info.get("description", "Unknown")
          rgb = list(
              info.get(
                  "color", GENERIC_ANATOMY_COLORS.get(name, (255, 0, 0))
              )
          )[0:3]
          rgb = [int(x) for x in rgb]
  
          logger.info(f"{i} => {idx} => {name}")
  
          segment_attribute = info.get(
              "segmentAttribute",
              {
                  "labelID": int(idx),
                  "SegmentLabel": name,
                  "SegmentDescription": description,
                  "SegmentAlgorithmType": "AUTOMATIC",
                  "SegmentAlgorithmName": "MONAILABEL",
                  "SegmentedPropertyCategoryCodeSequence": {
                      "CodeValue": "123037004",
                      "CodingSchemeDesignator": "SCT",
                      "CodeMeaning": "Anatomical Structure",
                  },
                  "SegmentedPropertyTypeCodeSequence": {
                      "CodeValue": "78961009",
                      "CodingSchemeDesignator": "SCT",
                      "CodeMeaning": name,
                  },
                  "recommendedDisplayRGBValue": rgb,
              },
          )
          segment_attributes.append(segment_attribute)
  
      template = {
          "ContentCreatorName": "Reader1",
          "ClinicalTrialSeriesID": "Session1",
          "ClinicalTrialTimePointID": "1",
          "SeriesDescription": model_name,
          "SeriesNumber": "300",
          "InstanceNumber": "1",
          "segmentAttributes": [segment_attributes],
          "ContentLabel": "SEGMENTATION",
          "ContentDescription": "MONAI Label - Image segmentation",
          "ClinicalTrialCoordinatingCenterName": "MONAI",
          "BodyPartExamined": "",
      }
  
      logger.info(json.dumps(template, indent=2))
      if not segment_attributes:
          logger.error("Missing Attributes/Empty Label provided")
          return ""
  
      if use_itk:
          output_file = itk_image_to_dicom_seg(
              label, series_dir, template
          )
      else:
          template = pydicom_seg.template.from_dcmqi_metainfo(template)
          writer = pydicom_seg.MultiClassWriter(
              template=template,
              inplane_cropping=False,
              skip_empty_slices=False,
              skip_missing_segment=False,
          )
  
          # Read source Images
          series_dir = pathlib.Path(series_dir)
          image_files = series_dir.glob(file_ext)
          image_datasets = [
              dcmread(str(f), stop_before_pixels=True)
              for f in image_files
          ]
          logger.info(f"Total Source Images: {len(image_datasets)}")
  
          mask = SimpleITK.ReadImage(label)
          mask = SimpleITK.Cast(mask, SimpleITK.sitkUInt16)
  
          output_file = tempfile.NamedTemporaryFile(suffix=".dcm").name
          dcm = writer.write(mask, image_datasets)
          dcm.save_as(output_file)
  
      logger.info(
          f"nifti_to_dicom_seg latency : {time.time() - start} (sec)"
      )
      return output_file
  
imports: import json
  import logging
  import os
  import pathlib
  import tempfile
  import time
  import numpy
  import pydicom
  import pydicom_seg
  import SimpleITK
  from monai.transforms import LoadImage
  from pydicom.filereader import dcmread
  from monailabel.datastore.utils.colors import GENERIC_ANATOMY_COLORS
  from monailabel.transform.writer import write_itk
  from monailabel.utils.others.generic import run_command
label_desc: Use image node_id 3 for calling a global function with example usage: nifti_to_dicom_seg(series_dir, label, label_info, file_ext, use_itk) and returns: output_file, str