code: def reduce_labels(label_volume):
      """Reduce an array of labels to the integers from 0 to n with smallest
      possible n.
  
      Examples
      --------
      >>> labels = np.array([[1, 3, 9],
      ...                    [1, 3, 8],
      ...                    [1, 3, 7]])
      >>> new_labels, lookup = reduce_labels(labels)
      >>> lookup
      array([1, 3, 7, 8, 9])
      >>> new_labels #doctest: +ELLIPSIS
      array([[0, 1, 4],
             [0, 1, 3],
             [0, 1, 2]]...)
      >>> (lookup[new_labels] == labels).all()
      True
  
      """
      lookup_table = np.unique(label_volume)
      label_volume = lookup_table.searchsorted(label_volume)
      return label_volume, lookup_table
  
imports: from collections import defaultdict, OrderedDict
  from functools import wraps
  from itertools import combinations, groupby
  from warnings import warn
  import numpy
  from nibabel.affines import apply_affine
  from scipy.spatial.distance import cdist
  from dipy.core.geometry import dist_to_corner
  from dipy.tracking import metrics
  from dipy.tracking.vox2track import _streamlines_in_mask
  from dipy.tracking._utils import _mapping_to_voxel, _to_voxel_coordinates
label_desc: Use image node_id 4 for calling a global function with example usage: reduce_labels(label_volume) and returns: label_volume,  lookup_table