code: def target(streamlines, affine, target_mask, include=True):
      """Filter streamlines based on whether or not they pass through an ROI.
  
      Parameters
      ----------
      streamlines : iterable
          A sequence of streamlines. Each streamline should be a (N, 3) array,
          where N is the length of the streamline.
      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.
      target_mask : array-like
          A mask used as a target. Non-zero values are considered to be within
          the target region.
      include : bool, default True
          If True, streamlines passing through `target_mask` are kept. If False,
          the streamlines not passing through `target_mask` are kept.
  
      Returns
      -------
      streamlines : generator
          A sequence of streamlines that pass through `target_mask`.
  
      Raises
      ------
      ValueError
          When the points of the streamlines lie outside of the `target_mask`.
  
      See Also
      --------
      density_map
  
      """
      target_mask = np.array(target_mask, dtype=bool, copy=True)
      lin_T, offset = _mapping_to_voxel(affine)
      yield
      # End of initialization
  
      for sl in streamlines:
          try:
              ind = _to_voxel_coordinates(sl, lin_T, offset)
              i, j, k = ind.T
              state = target_mask[i, j, k]
          except IndexError:
              raise ValueError(
                  "streamlines points are outside of target_mask"
              )
          if state.any() == include:
              yield sl
  
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 9 for calling a global function with example usage: target(streamlines, affine, target_mask, include) without return types