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

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

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
    • Reconstruction of the diffusion signal with the correlation tensor model
    • DSI Deconvolution vs DSI
    • Calculate SHORE scalar maps
    • Continuous and analytical diffusion signal modelling with 3D-SHORE
    • Reconstruct with Generalized Q-Sampling Imaging
    • Reconstruct with Constant Solid Angle (Q-Ball)
    • Reconstruction with the Sparse Fascicle Model
    • Calculate DSI-based scalar maps
    • Reconstruction of the diffusion signal with the kurtosis tensor model
    • Reconstruct with Q-space Trajectory Imaging (QTI)
    • K-fold cross-validation for model comparison
    • Reconstruction of the diffusion signal with the Tensor model
    • Crossing invariant fiber response function with FORECAST model
    • Local reconstruction using the Histological ResDNN
    • Reconstruction of the diffusion signal with the WMTI model
    • Using the RESTORE algorithm for robust tensor fitting
    • Signal Reconstruction Using Spherical Harmonics
    • Using the free water elimination model to remove DTI free water contamination
    • Reconstruction with Constrained Spherical Deconvolution
    • Intravoxel incoherent motion
    • Reconstruction with Multi-Shell Multi-Tissue CSD
    • Continuous and analytical diffusion signal modelling with MAP-MRI
    • Mean signal diffusion kurtosis imaging (MSDKI)
    • Reconstruction with Robust and Unbiased Model-BAsed Spherical Deconvolution
    • 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
    • An introduction to the Deterministic Maximum Direction Getter
    • Parallel Transport Tractography
    • Tracking with Robust Unbiased Model-BAsed Spherical Deconvolution (RUMBA-SD)
    • Bootstrap and Closest Peak Direction Getters Example
    • Tracking with the Sparse Fascicle Model
    • Introduction to Basic Tracking
    • An introduction to the Probabilistic Direction Getter
    • Particle Filtering 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
    • Streamline length and size reduction
    • Calculation of Outliers with Cluster Confidence Index
    • Calculate Path Length Map
    • Connectivity Matrices, ROI Intersections and Density Maps
  • Registration
    • Groupwise Bundle Registration
    • Direct Bundle Registration
    • Symmetric Diffeomorphic Registration in 3D
    • Symmetric Diffeomorphic Registration in 2D
    • Diffeomorphic Registration with binary and fuzzy images
    • 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
    • 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 vs DSI
    • DKI MultiTensor Simulation
    • MultiTensor Simulation
  • Multiprocessing
    • Parallel reconstruction using Q-Ball
    • Parallel reconstruction using CSD
  • 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
  • DIPY

Note

Go to the end to download the full example code

Fast Streamline Search#

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

First import the necessary modules.

import numpy as np

from dipy.data import (get_target_tractogram_hcp, get_two_hcp842_bundles,
                       fetch_bundle_atlas_hcp842, fetch_target_tractogram_hcp)
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, 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, out_path='AF_L_model_bundle.png',
                  size=(600, 600))
fast streamline search

Model Arcuate Fasciculus Left bundle

Search for all similar streamlines [StOnge2022]

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, 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(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, 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, 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, out_path='AF_L_model_bundle_reached.png',
                  size=(600, 600))
fast streamline search

Arcuate Fasciculus Left model reached (green) in radius

References#

[StOnge2022] (1,2)

St-Onge E. et al. Fast Streamline Search: An Exact Technique for Diffusion MRI Tractography. Neuroinformatics, 2022.

Total running time of the script: (0 minutes 41.102 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
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 during Summer 2015, 2016, 2018
Copyright 2008-2023, DIPY developers. Created using Grg Sphinx Theme and PyData Sphinx Theme.