code: def create_label_size_map(data):
      """
      This function creates the maps of label size. For each connected
      component of a label with value :value:, the binary segmentation is
      replaced by the size of the considered element
      :param data: segmentation
      :param value: value of the label to consider
      :return: count_data
      """
      labelled_data, _ = ndimage.label(data)
      components, count = np.unique(labelled_data, return_counts=True)
      count_data = np.copy(labelled_data)
      for label, size in zip(components, count):
          if label == 0:
              continue
          count_data[labelled_data == label] = size
      return count_data
  
file_path: NiftyNet/niftynet/contrib/segmentation_selective_sampler/sampler_selective.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from scipy import ndimage
  from scipy.signal import fftconvolve
  from niftynet.engine.image_window import N_SPATIAL
  from niftynet.engine.sampler_uniform_v2 import UniformSampler
label_desc: Use image node_id 1 for calling a global function with example usage: create_label_size_map(data) and returns: count_data