code: def streamline_near_roi(streamline, roi_coords, tol, mode="any"):
      """Is a streamline near an ROI.
  
      Implements the inner loops of the :func:`near_roi` function.
  
      Parameters
      ----------
      streamline : array, shape (N, 3)
          A single streamline
      roi_coords : array, shape (M, 3)
          ROI coordinates transformed to the streamline coordinate frame.
      tol : float
          Distance (in the units of the streamlines, usually mm). If any
          coordinate in the streamline is within this distance from the center
          of any voxel in the ROI, this function returns True.
      mode : string
          One of {"any", "all", "either_end", "both_end"}, where return True
          if:
  
          "any" : any point is within tol from ROI.
  
          "all" : all points are within tol from ROI.
  
          "either_end" : either of the end-points is within tol from ROI
  
          "both_end" : both end points are within tol from ROI.
  
      Returns
      -------
      out : boolean
  
      """
      if not np.any(streamline):
          return False
      if len(roi_coords) == 0:
          return False
      if mode in ("any", "all"):
          s = streamline
      elif mode in ("either_end", "both_end"):
          # 'end' modes, use a streamline with 2 nodes:
          s = np.vstack([streamline[0], streamline[-1]])
      else:
          e_s = "For determining relationship to an array, you can use "
          e_s += "one of the following modes: 'any', 'all', 'both_end',"
          e_s += "'either_end', but you entered: %s." % mode
          raise ValueError(e_s)
  
      dist = cdist(s, roi_coords, "euclidean")
  
      if mode in ("any", "either_end"):
          return np.min(dist) <= tol
      else:
          return np.all(np.min(dist, -1) <= tol)
  
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 11 for calling a global function with example usage: streamline_near_roi(streamline, roi_coords, tol, mode) and returns: False, False, unknown, np