code: def split_consep_dataset(
      d,
      output_dir,
      nuclei_id_key="nuclei_id",
      crop_size=256,
  ):
      dataset_json = []
      # logger.debug(f"Process Image: {d['image']} => Label: {d['label']}")
  
      images_dir = output_dir
      labels_dir = os.path.join(output_dir, "labels", "final")
      os.makedirs(images_dir, exist_ok=True)
      os.makedirs(labels_dir, exist_ok=True)
  
      # Image
      image = Image.open(d["image"]).convert("RGB")
      image_np = np.array(image)
      image_id = get_basename_no_ext(d["image"])
  
      # Label
      m = scipy.io.loadmat(d["label"])
      label_map = m["type_map"]
  
      label_map[label_map == 4] = 3
      label_map[label_map > 4] = 4
  
      for nuclei_id, (class_id, (y, x)) in enumerate(
          zip(m["inst_type"], m["inst_centroid"]), start=1
      ):
          x, y = (int(x), int(y))
          class_id = int(class_id)
          class_id = (
              3
              if class_id in (3, 4)
              else 4
              if class_id in (5, 6, 7)
              else class_id
          )  # override
  
          if crop_size:
              bbox = compute_bbox(crop_size, (x, y), image.size)
              cropped_image_np = image_np[
                  bbox[0] : bbox[2], bbox[1] : bbox[3], :
              ]
              cropped_label_np = label_map[
                  bbox[0] : bbox[2], bbox[1] : bbox[3]
              ]
  
              # cropped_image_np = np.array(cropped_image_np)
              # cropped_image_np[:, :, 0] = np.where(cropped_label_np > 0, cropped_label_np * 20, cropped_image_np[:, :, 0])
              filename = (
                  f"{image_id}_{class_id}_{str(nuclei_id).zfill(4)}.png"
              )
          else:
              cropped_image_np = image_np
              cropped_label_np = label_map
  
              filename = f"{image_id}.png"
  
          cropped_image = Image.fromarray(cropped_image_np, "RGB")
          cropped_label = Image.fromarray(
              cropped_label_np.astype(np.uint8), None
          )
  
          image_file = os.path.join(images_dir, filename)
          label_file = os.path.join(labels_dir, filename)
  
          cropped_image.save(image_file)
          cropped_label.save(label_file)
  
          item = copy.deepcopy(d)
          item[nuclei_id_key] = nuclei_id
          item["image"] = image_file
          item["label"] = label_file
  
          dataset_json.append(item)
          if not crop_size:
              break
  
      return dataset_json
  
imports: import copy
  import logging
  import os
  import random
  import shutil
  import xml.etree.ElementTree
  from io import BytesIO
  from math import ceil
  import cv2
  import numpy
  import openslide
  import scipy
  from PIL import Image
  from tqdm import tqdm
  from monailabel.datastore.dsa import DSADatastore
  from monailabel.datastore.local import LocalDatastore
  from monailabel.interfaces.datastore import Datastore
  from monailabel.utils.others.generic import get_basename, get_basename_no_ext, is_openslide_supported
label_desc: Use image node_id 5 for calling a global function with example usage: split_consep_dataset(d, output_dir, nuclei_id_key, crop_size) and returns: dataset_json