code: def path_length(streamlines, affine, aoi, fill_value=-1):
      """Compute the shortest path, along any streamline, between aoi and
      each voxel.
  
      Parameters
      ----------
      streamlines : seq of (N, 3) arrays
          A sequence of streamlines, path length is given in mm along the curve
          of the streamline.
      aoi : array, 3d
          A mask (binary array) of voxels from which to start computing distance.
      affine : array (4, 4)
          The mapping between voxel indices and the point space for seeds.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
      fill_value : float
          The value of voxel in the path length map that are not connected to the
          aoi.
  
      Returns
      -------
      plm : array
          Same shape as aoi. The minimum distance between every point and aoi
          along the path of a streamline.
  
      """
      aoi = np.asarray(aoi, dtype=bool)
  
      # path length map
      plm = np.empty(aoi.shape, dtype=float)
      plm[:] = np.inf
      lin_T, offset = _mapping_to_voxel(affine)
      for sl in streamlines:
          seg_ind = _to_voxel_coordinates(sl, lin_T, offset)
          i, j, k = seg_ind.T
          # Get where streamlines passes through aoi
          breaks = aoi[i, j, k]
          # Where streamline passes aoi, dist is zero
          i, j, k = seg_ind[breaks].T
          plm[i, j, k] = 0
  
          # If a streamline crosses aoi >1, re-start counting distance for each
          for seg in _as_segments(sl, breaks):
              i, j, k = _to_voxel_coordinates(seg[1:], lin_T, offset).T
              # Get the distance, in mm, between streamline points
              segment_length = np.sqrt(
                  ((seg[1:] - seg[:-1]) ** 2).sum(1)
              )
              dist = segment_length.cumsum()
              # Updates path length map with shorter distances
              minimum_at(plm, (i, j, k), dist)
      if fill_value != np.inf:
          plm = np.where(plm == np.inf, fill_value, plm)
      return plm
  
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 18 for calling a global function with example usage: path_length(streamlines, affine, aoi, fill_value) and returns: plm