code: def _remove_small_regions(input_data, index, affine, min_size):
      """Remove small regions in volume from input_data of specified min_size.
  
      min_size should be specified in mm^3 (region size in volume).
  
      Parameters
      ----------
      input_data : numpy.ndarray
          Values inside the regions defined by labels contained in input_data
          are summed together to get the size and compare with given min_size.
          For example, see scipy.ndimage.label.
  
      index : numpy.ndarray
          A sequence of label numbers of the regions to be measured corresponding
          to input_data. For example, sequence can be generated using
          np.arange(n_labels + 1).
  
      affine : numpy.ndarray
          Affine of input_data is used to convert size in voxels to size in
          volume of region in mm^3.
  
      min_size : float in mm^3
          Size of regions in input_data which falls below the specified min_size
          of volume in mm^3 will be discarded.
  
      Returns
      -------
      out : numpy.ndarray
          Data returned will have regions removed specified by min_size
          Otherwise, if criterion is not met then same input data will be
          returned.
  
      """
      # with return_counts argument is introduced from numpy 1.9.0.
      # _, region_sizes = np.unique(input_data, return_counts=True)
  
      # For now, to count the region sizes, we use return_inverse from
      # np.unique and then use np.bincount to count the region sizes.
  
      _, region_indices = np.unique(input_data, return_inverse=True)
      region_sizes = np.bincount(region_indices)
      size_in_vox = min_size / np.abs(np.linalg.det(affine[:3, :3]))
      labels_kept = region_sizes > size_in_vox
      if not np.all(labels_kept):
          # Put to zero the indices not kept
          rejected_labels_mask = np.in1d(
              input_data, np.where(np.logical_not(labels_kept))[0]
          ).reshape(input_data.shape)
          # Avoid modifying the input:
          input_data = input_data.copy()
          input_data[rejected_labels_mask] = 0
          # Reorder the indices to avoid gaps
          input_data = np.searchsorted(
              np.unique(input_data), input_data
          )
      return input_data
  
imports: import collections.abc
  import numbers
  import numpy
  from joblib import Memory
  from scipy.ndimage import label
  from scipy.stats import scoreatpercentile
  from nilearn.maskers import NiftiMapsMasker
  from ..None import masking
  from .._utils import check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.ndimage import peak_local_max
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import check_same_fov
  from .._utils.segmentation import random_walker
  from ..image import new_img_like, resample_img
  from ..image.image import concat_imgs, smooth_array, threshold_img
label_desc: Use image node_id 2 for calling a global function with example usage: _remove_small_regions(input_data, index, affine, min_size) and returns: input_data