code: def get_label_ccp(
      mask_index: MetaTensor, use_gpu: bool = True
  ) -> tuple[list[Any], int]:
      """
      Find all connected components and their bounding shape. Backend can be cuPy/cuCIM or Numpy
      depending on the hardware.
  
      Args:
          mask_index: a binary mask.
          use_gpu: a switch to use GPU/CUDA or not. If GPU is unavailable, CPU will be used
              regardless of this setting.
  
      """
      skimage, has_cucim = optional_import("cucim.skimage")
      shape_list = []
      if (
          mask_index.device.type == "cuda"
          and has_cp
          and has_cucim
          and use_gpu
      ):
          mask_cupy = ToCupy()(mask_index.short())
          labeled = skimage.measure.label(mask_cupy)
          vals = cp.unique(labeled[cp.nonzero(labeled)])
  
          for ncomp in vals:
              comp_idx = cp.argwhere(labeled == ncomp)
              comp_idx_min = cp.min(comp_idx, axis=0).tolist()
              comp_idx_max = cp.max(comp_idx, axis=0).tolist()
              bbox_shape = [
                  comp_idx_max[i] - comp_idx_min[i] + 1
                  for i in range(len(comp_idx_max))
              ]
              shape_list.append(bbox_shape)
          ncomponents = len(vals)
  
          del mask_cupy, labeled, vals, comp_idx, ncomp
          cp.get_default_memory_pool().free_all_blocks()
  
      elif has_measure:
          labeled, ncomponents = measure_np.label(
              mask_index.data.cpu().numpy(),
              background=-1,
              return_num=True,
          )
          for ncomp in range(1, ncomponents + 1):
              comp_idx = np.argwhere(labeled == ncomp)
              comp_idx_min = np.min(comp_idx, axis=0).tolist()
              comp_idx_max = np.max(comp_idx, axis=0).tolist()
              bbox_shape = [
                  comp_idx_max[i] - comp_idx_min[i] + 1
                  for i in range(len(comp_idx_max))
              ]
              shape_list.append(bbox_shape)
      else:
          raise RuntimeError(
              "Cannot find one of the following required dependencies: {cuPy+cuCIM} or {scikit-image}"
          )
  
      return shape_list, ncomponents
  
imports: from __future__ import annotations
  import logging
  import os
  import pickle
  import subprocess
  import sys
  from copy import deepcopy
  from numbers import Number
  from typing import Any, cast
  import numpy
  import torch
  from monai.auto3dseg import Algo
  from monai.bundle.config_parser import ConfigParser
  from monai.bundle.utils import ID_SEP_KEY
  from monai.config import PathLike
  from monai.data.meta_tensor import MetaTensor
  from monai.transforms import CropForeground, ToCupy
  from monai.utils import min_version, optional_import, run_cmd
label_desc: Use image node_id 3 for calling a global function with example usage: get_label_ccp(mask_index, use_gpu) and returns: shape_list,  ncomponents