Skip to main content
Ctrl+K
DIPY

Site Navigation

    • Overview
    • Tutorials
    • Recipes
    • CLI / Workflows
    • API
    • CLI API
    • Latest

    • DIPY Workshop 2024
    • Past

    • DIPY Workshop 2023
    • DIPY Workshop 2022
    • DIPY Workshop 2021
    • DIPY Workshop 2020
    • DIPY Workshop 2019
    • News

    • Calendar
    • Newsletters
    • Blog
    • Youtube
    • Help

    • Live Chat (Gitter)
    • Github Discussions
    • Team
    • FAQ
    • Mission Statement
    • Releases
    • Cite
    • Glossary
Ctrl+K
  • GitHub
  • Twitter/X
  • YouTube
  • LinkedIn

Site Navigation

    • Overview
    • Tutorials
    • Recipes
    • CLI / Workflows
    • API
    • CLI API
    • Latest

    • DIPY Workshop 2024
    • Past

    • DIPY Workshop 2023
    • DIPY Workshop 2022
    • DIPY Workshop 2021
    • DIPY Workshop 2020
    • DIPY Workshop 2019
    • News

    • Calendar
    • Newsletters
    • Blog
    • Youtube
    • Help

    • Live Chat (Gitter)
    • Github Discussions
    • Team
    • FAQ
    • Mission Statement
    • Releases
    • Cite
    • Glossary
Ctrl+K
  • GitHub
  • Twitter/X
  • YouTube
  • LinkedIn

Section Navigation

  • Quick Start
    • Getting started with DIPY
    • Introduction to Basic Tracking
  • Preprocessing
    • Reslice diffusion datasets
    • Between-volumes Motion Correction on DWI datasets
    • Noise estimation using PIESNO
    • Denoise images using Non-Local Means (NLMEANS)
    • Brain segmentation with median_otsu
    • Patch2Self: Self-Supervised Denoising via Statistical Independence
    • Denoise images using Local PCA via empirical thresholds
    • Gradients and Spheres
    • Denoise images using Adaptive Soft Coefficient Matching (ASCM)
    • SNR estimation for Diffusion-Weighted Images
    • Denoise images using the Marcenko-Pastur PCA algorithm
    • Suppress Gibbs oscillations
  • Reconstruction
    • Applying positivity constraints to Q-space Trajectory Imaging (QTI+)
    • Reconstruct with Diffusion Spectrum Imaging (DSI)
    • Reconstruction of the diffusion signal with the correlation tensor model (CTI)
    • DSI Deconvolution (DSID) vs DSI
    • Calculate SHORE scalar maps
    • Reconstruct with Generalized Q-Sampling Imaging
    • Continuous and analytical diffusion signal modelling with 3D-SHORE
    • Reconstruct with Constant Solid Angle (Q-Ball)
    • Reconstruction with the Sparse Fascicle Model (SFM)
    • Calculate DSI-based scalar maps
    • Reconstruction of the diffusion signal with the kurtosis tensor model (DKI)
    • Reconstruct with Q-space Trajectory Imaging (QTI)
    • Reconstruction of the diffusion signal with DTI (single tensor) model
    • K-fold cross-validation for model comparison
    • Crossing invariant fiber response function with FORECAST model
    • Local reconstruction using the Histological ResDNN
    • Reconstruction of the diffusion signal with the WMTI model (DKI-MICRO)
    • Using the RESTORE algorithm for robust tensor fitting
    • Using the free water elimination model to remove DTI free water contamination
    • Signal Reconstruction Using Spherical Harmonics
    • Reconstruction with Multi-Shell Multi-Tissue CSD
    • Continuous and analytical diffusion signal modelling with MAP-MRI
    • Reconstruction with Constrained Spherical Deconvolution model (CSD)
    • Intravoxel incoherent motion (IVIM)
    • Reconstruction of Bingham Functions from ODFs
    • Mean signal diffusion kurtosis imaging (MSDKI)
    • Reconstruction with Robust and Unbiased Model-BAsed Spherical Deconvolution (RUMBA)
    • Estimating diffusion time dependent q-space indices using qt-dMRI
  • Contextual Enhancement
    • Crossing-preserving contextual enhancement
    • Fiber to bundle coherence measures
  • Fiber Tracking
    • Surface seeding for tractography
    • Parallel Transport Tractography
    • An introduction to the Deterministic Tractography
    • Bootstrap and Closest Peak Direction Getters Example
    • Tracking with Robust Unbiased Model-BAsed Spherical Deconvolution (RUMBA-SD)
    • Tracking with the Sparse Fascicle Model
    • Introduction to Basic Tracking
    • Particle Filtering Tractography
    • An introduction to the Probabilistic Tractography
    • Linear fascicle evaluation (LiFE)
    • Using Various Stopping Criterion for Tractography
  • Streamlines Analysis and Connectivity
    • BUAN Bundle Shape Similarity Score
    • BUAN Bundle Assignment Maps Creation
    • Extracting AFQ tract profiles from segmented bundles
    • Calculation of Outliers with Cluster Confidence Index
    • Streamline length and size reduction
    • Calculate Path Length Map
    • Connectivity Matrices, ROI Intersections and Density Maps
  • Registration
    • Groupwise Bundle Registration
    • Direct Bundle Registration
    • Diffeomorphic Registration with binary and fuzzy images
    • Symmetric Diffeomorphic Registration in 3D
    • Symmetric Diffeomorphic Registration in 2D
    • Nonrigid Bundle Registration with BundleWarp
    • Applying image-based deformations to streamlines
    • Affine Registration with Masks
    • Affine Registration in 3D
  • Segmentation
    • Brain segmentation with median_otsu
    • Tissue Classification using Diffusion MRI with DAM
    • Tractography Clustering with QuickBundles
    • Tissue Classification of a T1-weighted Structural Image
    • Tractography Clustering - Available Metrics
    • Fast Streamline Search
    • Enhancing QuickBundles with different metrics and features
    • Tractography Clustering - Available Features
    • Automatic Fiber Bundle Extraction with RecoBundles
  • Simulation
    • DSI Deconvolution (DSID) vs DSI
    • DKI MultiTensor Simulation
    • MultiTensor Simulation
  • Multiprocessing
    • Parallel reconstruction using Q-Ball
    • Parallel reconstruction using CSD
    • An introduction to the Fast Tracking Module
    • Tractography on the DiSCo Phantom
  • File Formats
    • Read/Write streamline files
  • Visualization
    • Visualization of ROI Surface Rendered with Streamlines
    • Visualize bundles and metrics on bundles
    • Simple volume slicing
    • Advanced interactive visualization
  • Workflows
    • Creating a new workflow.
    • Creating a new combined workflow
  • Examples
  • Segmentation
  • Fast...

Note

Go to the end to download the full example code

Fast Streamline Search#

This example explains how Fast Streamline Search [1] can be used to find all similar streamlines.

First import the necessary modules.

import numpy as np

from dipy.data import (
    fetch_bundle_atlas_hcp842,
    fetch_target_tractogram_hcp,
    get_target_tractogram_hcp,
    get_two_hcp842_bundles,
)
from dipy.io.streamline import load_trk
from dipy.segment.fss import FastStreamlineSearch, nearest_from_matrix_row
from dipy.viz import actor, window

Download and read data for this tutorial

fetch_bundle_atlas_hcp842()
fetch_target_tractogram_hcp()

hcp_file = get_target_tractogram_hcp()
streamlines = load_trk(hcp_file, "same", bbox_valid_check=False).streamlines

Visualize the atlas (ref) bundle and full brain tractogram

interactive = False

scene = window.Scene()
scene.SetBackground(1, 1, 1)
scene.add(actor.line(streamlines))
if interactive:
    window.show(scene)
else:
    window.record(scene=scene, out_path="tractograms_initial.png", size=(600, 600))
fast streamline search

Atlas bundle and source streamlines before registration.

Read Arcuate Fasciculus Left and Corticospinal Tract Left bundles from already fetched atlas data to use them as model bundle. Let’s visualize the Arcuate Fasciculus Left model bundle.

model_af_l_file, model_cst_l_file = get_two_hcp842_bundles()
sft_af_l = load_trk(model_af_l_file, "same", bbox_valid_check=False)
model_af_l = sft_af_l.streamlines

scene = window.Scene()
scene.SetBackground(1, 1, 1)
scene.add(actor.line(model_af_l, colors=(0, 1, 0)))
scene.set_camera(
    focal_point=(-18.17281532, -19.55606842, 6.92485857),
    position=(-360.11, -30.46, -40.44),
    view_up=(-0.03, 0.028, 0.89),
)
if interactive:
    window.show(scene)
else:
    window.record(scene=scene, out_path="AF_L_model_bundle.png", size=(600, 600))
fast streamline search

Model Arcuate Fasciculus Left bundle

Search for all similar streamlines [1]

Fast Streamline Search can do a radius search to find all streamlines that are similar to from one tractogram to another. It returns the distance matrix mapping between both tractograms. The same list of streamlines can be given to recover the self distance matrix.

here are the FastStreamlinesSearch class need the following initialization arguments:

  • ref_streamlines : reference streamlines, that will be searched in (tree)

  • max_radius : is the maximum distance that can be used with radius search

Then, the radius_search() method needs the following arguments:

  • radius : for each streamline search find all similar ones in the “ref_streamlines” that are within the given radius

Be cautious, a large radius might result in a dense distance computation, requiring a large amount of time and memory. Recommended range of the radius is from 1 to 10 mm.

radius = 7.0
fs_tree_af = FastStreamlineSearch(ref_streamlines=model_af_l, max_radius=radius)
coo_mdist_mtx = fs_tree_af.radius_search(streamlines, radius=radius)

Extract indices of streamlines with an similar ones in the reference

ids_s = np.unique(coo_mdist_mtx.row)
ids_ref = np.unique(coo_mdist_mtx.col)

recognized_af_l = streamlines[ids_s].copy()

let’s visualize streamlines similar to the Arcuate Fasciculus Left bundle

scene = window.Scene()
scene.SetBackground(1, 1, 1)
scene.add(actor.line(recognized_af_l, colors=(0, 0, 1)))
scene.set_camera(
    focal_point=(-18.17281532, -19.55606842, 6.92485857),
    position=(-360.11, -30.46, -40.44),
    view_up=(-0.03, 0.028, 0.89),
)
if interactive:
    window.show(scene)
else:
    window.record(scene=scene, out_path="AF_L_recognized_bundle.png", size=(600, 600))
fast streamline search

Recognized Arcuate Fasciculus Left bundle

Color the resulting AF by the nearest streamlines distance

nn_s, nn_ref, nn_dist = nearest_from_matrix_row(coo_mdist_mtx)

scene = window.Scene()
scene.SetBackground(1, 1, 1)
cmap = actor.colormap_lookup_table(scale_range=(nn_dist.min(), nn_dist.max()))
scene.add(actor.line(recognized_af_l, colors=nn_dist, lookup_colormap=cmap))
scene.add(actor.scalar_bar(lookup_table=cmap, title="distance to atlas (mm)"))
scene.set_camera(
    focal_point=(-18.17281532, -19.55606842, 6.92485857),
    position=(-360.11, -30.46, -40.44),
    view_up=(-0.03, 0.028, 0.89),
)
if interactive:
    window.show(scene)
else:
    window.record(
        scene=scene, out_path="AF_L_recognized_bundle_dist.png", size=(600, 600)
    )
fast streamline search

Recognized Arcuate Fasciculus Left bundle colored by distance to ref

Display the streamlines reference reached in green

# Default red color
ref_color = np.zeros((len(model_af_l), 3), dtype=float)
ref_color[:] = (1.0, 0.0, 0.0)

# Reached in green color
ref_color[ids_ref] = (0.0, 1.0, 0.0)

scene = window.Scene()
scene.SetBackground(1, 1, 1)
scene.add(actor.line(model_af_l, colors=ref_color))
scene.set_camera(
    focal_point=(-18.17281532, -19.55606842, 6.92485857),
    position=(-360.11, -30.46, -40.44),
    view_up=(-0.03, 0.028, 0.89),
)

if interactive:
    window.show(scene)
else:
    window.record(
        scene=scene, out_path="AF_L_model_bundle_reached.png", size=(600, 600)
    )
fast streamline search

Arcuate Fasciculus Left model reached (green) in radius

References#

[1] (1,2)

Etienne St-Onge, Eleftherios Garyfallidis, and D. Louis Collins. Fast Streamline Search: An Exact Technique for Diffusion MRI Tractography. Neuroinformatics, 20(4):1093–1104, 2022. URL: https://doi.org/10.1007/s12021-022-09590-7, doi:10.1007/s12021-022-09590-7.

Total running time of the script: (0 minutes 35.724 seconds)

Download Jupyter notebook: fast_streamline_search.ipynb

Download Python source code: fast_streamline_search.py

Gallery generated by Sphinx-Gallery

previous

Tractography Clustering - Available Metrics

next

Enhancing QuickBundles with different metrics and features

On this page
  • References

Never miss an update from us!

Don't worry! we are not going to spam you.

Subscribe
  • GitHub
  • Twitter/X
  • YouTube
  • LinkedIn
About
  • Developers
  • Support
  • Download
  • Get Started
  • Tutorials
  • Videos
Friends
  • Nipy Projects
  • FURY
  • Nibabel
  • Tortoise
Support
  • The department of Intelligent Systems Engineering of Indiana University
  • The National Institute of Biomedical Imaging and Bioengineering, NIH
  • The Gordon and Betty Moore Foundation and the Alfred P. Sloan Foundation, through the University of Washington eScience Institute Data Science Environment
  • Google supported DIPY through the Google Summer of Code Program (2015-2024)
Copyright 2008-2025,DIPY developers. Created using Grg Sphinx Theme and PyData Sphinx Theme.