An introduction to the Deterministic Maximum Direction Getter#

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 An introduction to the Probabilistic Direction Getter 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_max=6)
csd_fit = csd_model.fit(data, mask=white_matter)

csa_model = CsaOdfModel(gtab, sh_order_max=6)
gfa = csa_model.fit(data, mask=white_matter).gfa
stopping_criterion = ThresholdStoppingCriterion(gfa, .25)
  0%|                                                                                                                                                  | 0/58788 [00:00<?, ?it/s]
  1%|█                                                                                                                                     | 453/58788 [00:00<00:13, 4486.15it/s]
  2%|██▋                                                                                                                                  | 1214/58788 [00:00<00:09, 6235.69it/s]
  3%|████▌                                                                                                                                | 2019/58788 [00:00<00:08, 6773.16it/s]
  5%|██████▍                                                                                                                              | 2842/58788 [00:00<00:07, 7076.97it/s]
  6%|████████▍                                                                                                                            | 3740/58788 [00:00<00:07, 7491.89it/s]
  8%|██████████▍                                                                                                                          | 4637/58788 [00:00<00:07, 7735.33it/s]
  9%|████████████▍                                                                                                                        | 5498/58788 [00:00<00:06, 7780.36it/s]
 11%|██████████████▌                                                                                                                      | 6414/58788 [00:00<00:06, 7962.46it/s]
 12%|████████████████▌                                                                                                                    | 7346/58788 [00:00<00:06, 8141.00it/s]
 14%|██████████████████▋                                                                                                                  | 8235/58788 [00:01<00:06, 8141.81it/s]
 16%|████████████████████▋                                                                                                                | 9149/58788 [00:01<00:06, 8207.71it/s]
 17%|██████████████████████▋                                                                                                             | 10081/58788 [00:01<00:05, 8302.43it/s]
 19%|████████████████████████▋                                                                                                           | 10997/58788 [00:01<00:05, 8324.31it/s]
 20%|██████████████████████████▋                                                                                                         | 11896/58788 [00:01<00:05, 8292.58it/s]
 22%|████████████████████████████▊                                                                                                       | 12817/58788 [00:01<00:05, 8331.18it/s]
 23%|██████████████████████████████▊                                                                                                     | 13738/58788 [00:01<00:05, 8357.97it/s]
 25%|████████████████████████████████▉                                                                                                   | 14680/58788 [00:01<00:05, 8423.92it/s]
 27%|██████████████████████████████████▉                                                                                                 | 15581/58788 [00:01<00:05, 8375.23it/s]
 28%|█████████████████████████████████████▏                                                                                              | 16547/58788 [00:02<00:04, 8515.41it/s]
 30%|███████████████████████████████████████▎                                                                                            | 17496/58788 [00:02<00:04, 8563.56it/s]
 31%|█████████████████████████████████████████▏                                                                                          | 18353/58788 [00:02<00:04, 8345.60it/s]
 33%|███████████████████████████████████████████                                                                                         | 19196/58788 [00:02<00:04, 8154.06it/s]
 34%|█████████████████████████████████████████████▏                                                                                      | 20124/58788 [00:02<00:04, 8253.21it/s]
 36%|███████████████████████████████████████████████▎                                                                                    | 21051/58788 [00:02<00:04, 8319.87it/s]
 37%|█████████████████████████████████████████████████▍                                                                                  | 21996/58788 [00:02<00:04, 8415.90it/s]
 39%|███████████████████████████████████████████████████▎                                                                                | 22859/58788 [00:02<00:04, 8381.52it/s]
 40%|█████████████████████████████████████████████████████▎                                                                              | 23758/58788 [00:02<00:04, 8210.47it/s]
 42%|███████████████████████████████████████████████████████▎                                                                            | 24652/58788 [00:03<00:04, 8199.53it/s]
 43%|█████████████████████████████████████████████████████████▍                                                                          | 25553/58788 [00:03<00:04, 8211.50it/s]
 45%|███████████████████████████████████████████████████████████▍                                                                        | 26482/58788 [00:03<00:03, 8296.12it/s]
 46%|█████████████████████████████████████████████████████████████▎                                                                      | 27318/58788 [00:03<00:03, 8100.43it/s]
 48%|███████████████████████████████████████████████████████████████▏                                                                    | 28129/58788 [00:03<00:03, 7894.77it/s]
 49%|████████████████████████████████████████████████████████████████▉                                                                   | 28919/58788 [00:03<00:03, 7693.43it/s]
 51%|██████████████████████████████████████████████████████████████████▋                                                                 | 29689/58788 [00:03<00:04, 7189.40it/s]
 52%|████████████████████████████████████████████████████████████████████▎                                                               | 30413/58788 [00:03<00:03, 7138.69it/s]
 53%|██████████████████████████████████████████████████████████████████████                                                              | 31180/58788 [00:03<00:03, 7285.41it/s]
 54%|███████████████████████████████████████████████████████████████████████▉                                                            | 32023/58788 [00:04<00:03, 7416.57it/s]
 56%|█████████████████████████████████████████████████████████████████████████▉                                                          | 32911/58788 [00:04<00:03, 7630.52it/s]
 57%|███████████████████████████████████████████████████████████████████████████▊                                                        | 33775/58788 [00:04<00:03, 7711.57it/s]
 59%|█████████████████████████████████████████████████████████████████████████████▉                                                      | 34708/58788 [00:04<00:03, 7957.63it/s]
 61%|███████████████████████████████████████████████████████████████████████████████▉                                                    | 35608/58788 [00:04<00:02, 8039.25it/s]
 62%|██████████████████████████████████████████████████████████████████████████████████                                                  | 36525/58788 [00:04<00:02, 8142.86it/s]
 64%|████████████████████████████████████████████████████████████████████████████████████▏                                               | 37497/58788 [00:04<00:02, 8366.86it/s]
 65%|██████████████████████████████████████████████████████████████████████████████████████▎                                             | 38453/58788 [00:04<00:02, 8479.01it/s]
 67%|████████████████████████████████████████████████████████████████████████████████████████▌                                           | 39442/58788 [00:04<00:02, 8646.88it/s]
 69%|██████████████████████████████████████████████████████████████████████████████████████████▊                                         | 40433/58788 [00:05<00:02, 8771.23it/s]
 70%|████████████████████████████████████████████████████████████████████████████████████████████▉                                       | 41375/58788 [00:05<00:01, 8724.41it/s]
 72%|███████████████████████████████████████████████████████████████████████████████████████████████                                     | 42342/58788 [00:05<00:01, 8758.88it/s]
 74%|█████████████████████████████████████████████████████████████████████████████████████████████████▎                                  | 43322/58788 [00:05<00:01, 8818.92it/s]
 75%|███████████████████████████████████████████████████████████████████████████████████████████████████▎                                | 44257/58788 [00:05<00:01, 8737.67it/s]
 77%|█████████████████████████████████████████████████████████████████████████████████████████████████████▎                              | 45131/58788 [00:05<00:01, 8514.37it/s]
 78%|███████████████████████████████████████████████████████████████████████████████████████████████████████▏                            | 45983/58788 [00:05<00:01, 7955.96it/s]
 80%|█████████████████████████████████████████████████████████████████████████████████████████████████████████▎                          | 46913/58788 [00:05<00:01, 8114.60it/s]
 81%|███████████████████████████████████████████████████████████████████████████████████████████████████████████▏                        | 47729/58788 [00:05<00:01, 7916.96it/s]
 83%|████████████████████████████████████████████████████████████████████████████████████████████████████████████▉                       | 48524/58788 [00:06<00:01, 7731.19it/s]
 84%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████▊                     | 49359/58788 [00:06<00:01, 7701.40it/s]
 85%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                   | 50202/58788 [00:06<00:01, 7704.53it/s]
 87%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊                 | 51108/58788 [00:06<00:00, 7877.30it/s]
 88%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋               | 51948/58788 [00:06<00:00, 7817.77it/s]
 90%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋             | 52833/58788 [00:06<00:00, 7900.24it/s]
 91%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋           | 53760/58788 [00:06<00:00, 8072.02it/s]
 93%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉         | 54725/58788 [00:06<00:00, 8296.66it/s]
 95%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████       | 55675/58788 [00:06<00:00, 8406.34it/s]
 96%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████     | 56612/58788 [00:07<00:00, 8456.39it/s]
 98%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  | 57510/58788 [00:07<00:00, 8388.14it/s]
 99%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏| 58407/58788 [00:07<00:00, 8331.07it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 58788/58788 [00:07<00:00, 8056.57it/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, sh_to_pmf=True)
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)
tracking deterministic

Corpus Callosum using deterministic maximum direction getter

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

Gallery generated by Sphinx-Gallery