Note
Click here to download the full example code
Deterministic maximum direction getter is the deterministic version of the probabilistic direction getter. It can be used with the same local models and has the same parameters. Deterministic maximum fiber tracking follows the trajectory of the most probable pathway within the tracking constraint (e.g. max angle). In other words, it follows the direction with the highest probability from a distribution, as opposed to the probabilistic direction getter which draws the direction from the distribution. Therefore, the maximum deterministic direction getter is equivalent to the probabilistic direction getter returning always the maximum value of the distribution.
Deterministic maximum fiber tracking is an alternative to EuDX deterministic tractography and unlike EuDX does not follow the peaks of the local models but uses the entire orientation distributions.
This example is an extension of the example_tracking_probabilistic example. We begin by loading the data, fitting a Constrained Spherical Deconvolution (CSD) reconstruction model for the tractography and fitting the constant solid angle (CSA) reconstruction model to define the tracking mask (stopping criterion).
from dipy.core.gradients import gradient_table
from dipy.data import default_sphere, get_fnames
from dipy.direction import DeterministicMaximumDirectionGetter
from dipy.io.gradients import read_bvals_bvecs
from dipy.io.image import load_nifti, load_nifti_data
from dipy.io.stateful_tractogram import Space, StatefulTractogram
from dipy.io.streamline import save_trk
from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel,
auto_response_ssst)
from dipy.reconst.shm import CsaOdfModel
from dipy.tracking import utils
from dipy.tracking.local_tracking import LocalTracking
from dipy.tracking.stopping_criterion import ThresholdStoppingCriterion
from dipy.tracking.streamline import Streamlines
from dipy.viz import window, actor, colormap, has_fury
# Enables/disables interactive visualization
interactive = False
hardi_fname, hardi_bval_fname, hardi_bvec_fname = get_fnames('stanford_hardi')
label_fname = get_fnames('stanford_labels')
data, affine, hardi_img = load_nifti(hardi_fname, return_img=True)
labels = load_nifti_data(label_fname)
bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname)
gtab = gradient_table(bvals, bvecs)
seed_mask = labels == 2
white_matter = (labels == 1) | (labels == 2)
seeds = utils.seeds_from_mask(seed_mask, affine, density=1)
response, ratio = auto_response_ssst(gtab, data, roi_radii=10, fa_thr=0.7)
csd_model = ConstrainedSphericalDeconvModel(gtab, response, sh_order=6)
csd_fit = csd_model.fit(data, mask=white_matter)
csa_model = CsaOdfModel(gtab, sh_order=6)
gfa = csa_model.fit(data, mask=white_matter).gfa
stopping_criterion = ThresholdStoppingCriterion(gfa, .25)
0%| | 0/58788 [00:00<?, ?it/s]
1%|1 | 697/58788 [00:00<00:08, 6963.38it/s]
3%|2 | 1591/58788 [00:00<00:07, 8094.80it/s]
4%|4 | 2510/58788 [00:00<00:06, 8592.90it/s]
6%|5 | 3389/58788 [00:00<00:06, 8669.02it/s]
7%|7 | 4277/58788 [00:00<00:06, 8738.89it/s]
9%|8 | 5162/58788 [00:00<00:06, 8774.84it/s]
10%|# | 6108/58788 [00:00<00:05, 8997.57it/s]
12%|#2 | 7058/58788 [00:00<00:05, 9156.74it/s]
14%|#3 | 8020/58788 [00:00<00:05, 9300.11it/s]
15%|#5 | 8964/58788 [00:01<00:05, 9342.42it/s]
17%|#6 | 9926/58788 [00:01<00:05, 9427.14it/s]
19%|#8 | 10895/58788 [00:01<00:05, 9505.37it/s]
20%|## | 11846/58788 [00:01<00:05, 9354.26it/s]
22%|##1 | 12782/58788 [00:01<00:04, 9291.52it/s]
23%|##3 | 13712/58788 [00:01<00:04, 9287.30it/s]
25%|##4 | 14642/58788 [00:01<00:04, 9249.31it/s]
26%|##6 | 15568/58788 [00:01<00:04, 9206.28it/s]
28%|##8 | 16534/58788 [00:01<00:04, 9340.75it/s]
30%|##9 | 17490/58788 [00:01<00:04, 9405.83it/s]
31%|###1 | 18436/58788 [00:02<00:04, 9419.98it/s]
33%|###2 | 19390/58788 [00:02<00:04, 9455.33it/s]
35%|###4 | 20336/58788 [00:02<00:04, 9393.55it/s]
36%|###6 | 21276/58788 [00:02<00:04, 9360.07it/s]
38%|###7 | 22236/58788 [00:02<00:03, 9430.80it/s]
39%|###9 | 23189/58788 [00:02<00:03, 9456.86it/s]
41%|####1 | 24153/58788 [00:02<00:03, 9509.35it/s]
43%|####2 | 25123/58788 [00:02<00:03, 9566.02it/s]
44%|####4 | 26080/58788 [00:02<00:03, 9537.54it/s]
46%|####5 | 27034/58788 [00:02<00:03, 9483.68it/s]
48%|####7 | 27983/58788 [00:03<00:03, 9449.15it/s]
49%|####9 | 28928/58788 [00:03<00:03, 9382.20it/s]
51%|##### | 29867/58788 [00:03<00:03, 9273.31it/s]
52%|#####2 | 30795/58788 [00:03<00:03, 9163.49it/s]
54%|#####3 | 31712/58788 [00:03<00:02, 9067.07it/s]
55%|#####5 | 32619/58788 [00:03<00:02, 9035.14it/s]
57%|#####7 | 33539/58788 [00:03<00:02, 9081.63it/s]
59%|#####8 | 34448/58788 [00:03<00:02, 9036.69it/s]
60%|###### | 35394/58788 [00:03<00:02, 9161.20it/s]
62%|######1 | 36352/58788 [00:03<00:02, 9282.82it/s]
63%|######3 | 37316/58788 [00:04<00:02, 9389.12it/s]
65%|######5 | 38268/58788 [00:04<00:02, 9427.54it/s]
67%|######6 | 39248/58788 [00:04<00:02, 9537.20it/s]
68%|######8 | 40204/58788 [00:04<00:01, 9543.86it/s]
70%|####### | 41159/58788 [00:04<00:01, 9543.84it/s]
72%|#######1 | 42133/58788 [00:04<00:01, 9600.98it/s]
73%|#######3 | 43094/58788 [00:04<00:01, 9563.46it/s]
75%|#######4 | 44053/58788 [00:04<00:01, 9568.79it/s]
77%|#######6 | 45010/58788 [00:04<00:01, 9554.89it/s]
78%|#######8 | 45966/58788 [00:04<00:01, 9503.66it/s]
80%|#######9 | 46931/58788 [00:05<00:01, 9545.33it/s]
81%|########1 | 47898/58788 [00:05<00:01, 9581.52it/s]
83%|########3 | 48857/58788 [00:05<00:01, 9540.02it/s]
85%|########4 | 49823/58788 [00:05<00:00, 9574.91it/s]
86%|########6 | 50801/58788 [00:05<00:00, 9636.03it/s]
88%|########8 | 51765/58788 [00:05<00:00, 9552.28it/s]
90%|########9 | 52721/58788 [00:05<00:00, 9471.09it/s]
91%|#########1| 53669/58788 [00:05<00:00, 9433.02it/s]
93%|#########2| 54613/58788 [00:05<00:00, 9322.32it/s]
95%|#########4| 55560/58788 [00:05<00:00, 9365.25it/s]
96%|#########6| 56497/58788 [00:06<00:00, 9272.91it/s]
98%|#########7| 57425/58788 [00:06<00:00, 9220.19it/s]
99%|#########9| 58348/58788 [00:06<00:00, 9098.55it/s]
100%|##########| 58788/58788 [00:06<00:00, 9280.43it/s]
The Fiber Orientation Distribution (FOD) of the CSD model estimates the distribution of small fiber bundles within each voxel. This distribution can be used for deterministic fiber tracking. As for probabilistic tracking, there are many ways to provide those distributions to the deterministic maximum direction getter. Here, the spherical harmonic representation of the FOD is used.
detmax_dg = DeterministicMaximumDirectionGetter.from_shcoeff(
csd_fit.shm_coeff, max_angle=30., sphere=default_sphere)
streamline_generator = LocalTracking(detmax_dg, stopping_criterion, seeds,
affine, step_size=.5)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_deterministic_dg.trk")
if has_fury:
scene = window.Scene()
scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
window.record(scene, out_path='tractogram_deterministic_dg.png',
size=(800, 800))
if interactive:
window.show(scene)
Total running time of the script: ( 0 minutes 13.862 seconds)