code: def _get_centroids(self, label):
      centroids = []
      # loop over all segments
      areas = []
      for seg_class in torch.unique(label):
          c = {}
          # skip background
          if seg_class == 0:
              continue
  
          # get centre of mass (CoM)
          centre = []
          for indices in torch.where(label == seg_class):
              # most_indices = np.percentile(indices, 60).astype(int).tolist()
              # centre.append(most_indices)
              avg_indices = np.average(indices).astype(int).tolist()
              centre.append(avg_indices)
  
          if len(indices) < 1000:
              continue
  
          areas.append(len(indices))
          c[f"label_{int(seg_class)}"] = [
              int(seg_class),
              centre[-3],
              centre[-2],
              centre[-1],
          ]
          centroids.append(c)
  
      # Rules to discard centroids
      # 1/ Should we consider the distance between centroids?
      # 2/ Should we consider the area covered by the vertebra
  
      return centroids
  
imports: import copy
  import logging
  from typing import Dict, Hashable, Mapping
  import numpy
  import torch
  from monai.config import KeysCollection, NdarrayOrTensor
  from monai.transforms import CropForeground, GaussianSmooth, Randomizable, Resize, ScaleIntensity, SpatialCrop
  from monai.transforms.transform import MapTransform, Transform
label_desc: Use image node_id 2 for calling the VertebraLocalizationSegmentation obj's underlying member method code with example usage: obj._get_centroids(label) and returns: centroids