code: def _save_data_3d(
      vol_idx, vol_image, vol_label, dataset_dir, relative_path
  ):
      data_list: list[dict[str, str | int]] = []
  
      image_count = 0
      label_count = 0
      unique_labels_count = 0
  
      image_file_prefix = f"vol_idx_{vol_idx:0>4d}"
      image_file = os.path.join(
          dataset_dir, "images", image_file_prefix
      )
      image_file += ".npy"
  
      os.makedirs(os.path.join(dataset_dir, "images"), exist_ok=True)
      np.save(image_file, vol_image)
      image_count += 1
  
      # Test Data
      if vol_label is None:
          data_list.append(
              {
                  "image": image_file.replace(
                      dataset_dir + os.pathsep, ""
                  )
                  if relative_path
                  else image_file
              }
          )
      else:
          # For all Labels
          unique_labels = np.unique(vol_label.flatten())
          unique_labels = unique_labels[unique_labels != 0]
          unique_labels_count = max(
              unique_labels_count, len(unique_labels)
          )
  
          for idx in unique_labels:
              label_file_prefix = (
                  f"{image_file_prefix}_region_{int(idx):0>2d}"
              )
              label_file = os.path.join(
                  dataset_dir, "labels", label_file_prefix
              )
              label_file += ".npy"
  
              curr_label = (vol_label == idx).astype(np.float32)
              os.makedirs(
                  os.path.join(dataset_dir, "labels"), exist_ok=True
              )
              np.save(label_file, curr_label)
  
              label_count += 1
              data_list.append(
                  {
                      "image": image_file.replace(
                          dataset_dir + os.pathsep, ""
                      )
                      if relative_path
                      else image_file,
                      "label": label_file.replace(
                          dataset_dir + os.pathsep, ""
                      )
                      if relative_path
                      else label_file,
                      "region": int(idx),
                  }
              )
  
      if unique_labels_count >= 20:
          logging.warning(
              f"Unique labels {unique_labels_count} exceeds 20. Please check if this is correct."
          )
  
      logging.info(
          "{} => Image Shape: {} => {}; Label Shape: {} => {}; Unique Labels: {}".format(
              vol_idx,
              vol_image.shape,
              image_count,
              vol_label.shape if vol_label is not None else None,
              label_count,
              unique_labels_count,
          )
      )
      return data_list
  
file_path: MONAI/monai/apps/deepgrow/dataset.py
imports: from __future__ import annotations
  import logging
  import os
  from collections.abc import Sequence
  import numpy
  from monai.config import PathLike
  from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, Orientationd, Spacingd, SqueezeDimd, Transform
  from monai.utils import GridSampleMode
label_desc: Use image node_id 4 for calling a global function with example usage: _save_data_3d(vol_idx, vol_image, vol_label, dataset_dir, relative_path) and returns: data_list