code: def orient_by_rois(
      streamlines,
      affine,
      roi1,
      roi2,
      in_place=False,
      as_generator=False,
  ):
      """Orient a set of streamlines according to a pair of ROIs
  
      Parameters
      ----------
      streamlines : list or generator
          List or generator of 2d arrays of 3d coordinates. Each array contains
          the xyz coordinates of a single streamline.
      affine : array_like (4, 4)
          The mapping from voxel coordinates to streamline points.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
      roi1, roi2 : ndarray
          Binary masks designating the location of the regions of interest, or
          coordinate arrays (n-by-3 array with ROI coordinate in each row).
      in_place : bool
          Whether to make the change in-place in the original list
          (and return a reference to the list), or to make a copy of the list
          and return this copy, with the relevant streamlines reoriented.
          Default: False.
      as_generator : bool
          Whether to return a generator as output. Default: False
  
      Returns
      -------
      streamlines : list or generator
          The same 3D arrays as a list or generator, but reoriented with respect
          to the ROIs
  
      Examples
      --------
      >>> streamlines = [np.array([[0, 0., 0],
      ...                          [1, 0., 0.],
      ...                          [2, 0., 0.]]),
      ...                np.array([[2, 0., 0.],
      ...                          [1, 0., 0],
      ...                          [0, 0,  0.]])]
      >>> roi1 = np.zeros((4, 4, 4), dtype=bool)
      >>> roi2 = np.zeros_like(roi1)
      >>> roi1[0, 0, 0] = True
      >>> roi2[1, 0, 0] = True
      >>> orient_by_rois(streamlines, np.eye(4), roi1, roi2)
      [array([[ 0.,  0.,  0.],
             [ 1.,  0.,  0.],
             [ 2.,  0.,  0.]]), array([[ 0.,  0.,  0.],
             [ 1.,  0.,  0.],
             [ 2.,  0.,  0.]])]
  
      """
      # If we don't already have coordinates on our hands:
      if len(roi1.shape) == 3:
          roi1 = np.asarray(np.where(roi1.astype(bool))).T
      if len(roi2.shape) == 3:
          roi2 = np.asarray(np.where(roi2.astype(bool))).T
  
      roi1 = apply_affine(affine, roi1)
      roi2 = apply_affine(affine, roi2)
  
      if as_generator:
          if in_place:
              w_s = "Cannot return a generator when in_place is set to True"
              raise ValueError(w_s)
          return _orient_by_roi_generator(streamlines, roi1, roi2)
  
      # If it's a generator on input, we may as well generate it
      # here and now:
      if isinstance(streamlines, types.GeneratorType):
          out = Streamlines(streamlines)
  
      elif in_place:
          out = streamlines
      else:
          # Make a copy, so you don't change the output in place:
          out = deepcopy(streamlines)
  
      return _orient_by_roi_list(out, roi1, roi2)
  
imports: from copy import deepcopy
  from warnings import warn
  import types
  from scipy.spatial.distance import cdist
  import numpy
  from nibabel.affines import apply_affine
  from nibabel.streamlines import ArraySequence
  from dipy.tracking.streamlinespeed import length, set_number_of_points
  from dipy.tracking.distances import bundles_distances_mdf
  import dipy.tracking.utils
  from dipy.core.geometry import dist_to_corner
  from dipy.core.interpolation import interpolate_vector_3d, interpolate_scalar_3d
label_desc: Use image node_id 11 for calling a global function with example usage: orient_by_rois(streamlines, affine, roi1, roi2, in_place, as_generator) and returns: _orient_by_roi_list, _orient_by_roi_generator