Using Various Stopping Criterion for Tractography

The stopping criterion determines if the tracking stops or continues at each tracking position. The tracking stops when it reaches an ending region (e.g. low FA, gray matter or corticospinal fluid regions) or exits the image boundaries. The tracking also stops if the direction getter has no direction to follow.

Each stopping criterion determines if the stopping is ‘valid’ or ‘invalid’. A streamline is ‘valid’ when the stopping criterion determines if the streamline stops in a position classified as ‘ENDPOINT’ or ‘OUTSIDEIMAGE’. A streamline is ‘invalid’ when it stops in a position classified as ‘TRACKPOINT’ or ‘INVALIDPOINT’. These conditions are described below. The ‘LocalTracking’ generator can be set to output all generated streamlines or only the ‘valid’ ones. See Girard et al. (2004) [Girard2014] and Smith et al.(2012) [Smith2012] for more details on these methods.

This example is an extension of the example_tracking_deterministic example. We begin by loading the data, creating a seeding mask from white matter voxels of the corpus callosum, fitting a Constrained Spherical Deconvolution (CSD) reconstruction model and creating the maximum deterministic direction getter.

import matplotlib.pyplot as plt
import numpy as np

from dipy.core.gradients import gradient_table
from dipy.data import get_fnames, default_sphere
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.streamline import save_trk
from dipy.io.stateful_tractogram import Space, StatefulTractogram
from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel,
                                   auto_response_ssst)
from dipy.reconst.dti import fractional_anisotropy, TensorModel
from dipy.tracking import utils
from dipy.tracking.local_tracking import LocalTracking
from dipy.tracking.streamline import Streamlines
from dipy.tracking.stopping_criterion import (ActStoppingCriterion,
                                              BinaryStoppingCriterion,
                                              ThresholdStoppingCriterion)
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')
_, _, f_pve_wm = get_fnames('stanford_pve_maps')

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)

white_matter = load_nifti_data(f_pve_wm)

seed_mask = (labels == 2)
seed_mask[white_matter < 0.5] = 0
seeds = utils.seeds_from_mask(seed_mask, affine, density=2)

response, ratio = auto_response_ssst(gtab, data, roi_radii=10, fa_thr=0.7)
csd_model = ConstrainedSphericalDeconvModel(gtab, response)
csd_fit = csd_model.fit(data, mask=white_matter)

dg = DeterministicMaximumDirectionGetter.from_shcoeff(csd_fit.shm_coeff,
                                                      max_angle=30.,
                                                      sphere=default_sphere)
  0%|          | 0/77848.12 [00:00<?, ?it/s]
  0%|          | 325/77848.12 [00:00<00:23, 3245.98it/s]
  1%|          | 726/77848.12 [00:00<00:20, 3692.20it/s]
  1%|1         | 1131/77848.12 [00:00<00:19, 3853.21it/s]
  2%|1         | 1533/77848.12 [00:00<00:19, 3913.37it/s]
  3%|2         | 1953/77848.12 [00:00<00:18, 4016.23it/s]
  3%|3         | 2379/77848.12 [00:00<00:18, 4097.47it/s]
  4%|3         | 2796/77848.12 [00:00<00:18, 4121.02it/s]
  4%|4         | 3235/77848.12 [00:00<00:17, 4205.35it/s]
  5%|4         | 3656/77848.12 [00:00<00:17, 4184.57it/s]
  5%|5         | 4111/77848.12 [00:01<00:17, 4293.67it/s]
  6%|5         | 4541/77848.12 [00:01<00:17, 4233.99it/s]
  6%|6         | 4986/77848.12 [00:01<00:16, 4298.53it/s]
  7%|6         | 5417/77848.12 [00:01<00:17, 4239.35it/s]
  8%|7         | 5868/77848.12 [00:01<00:16, 4318.35it/s]
  8%|8         | 6309/77848.12 [00:01<00:16, 4343.46it/s]
  9%|8         | 6744/77848.12 [00:01<00:16, 4323.03it/s]
  9%|9         | 7213/77848.12 [00:01<00:15, 4431.49it/s]
 10%|9         | 7657/77848.12 [00:01<00:16, 4354.23it/s]
 10%|#         | 8125/77848.12 [00:01<00:15, 4450.01it/s]
 11%|#1        | 8572/77848.12 [00:02<00:15, 4453.55it/s]
 12%|#1        | 9018/77848.12 [00:02<00:15, 4364.06it/s]
 12%|#2        | 9461/77848.12 [00:02<00:15, 4381.44it/s]
 13%|#2        | 9916/77848.12 [00:02<00:15, 4427.63it/s]
 13%|#3        | 10360/77848.12 [00:02<00:15, 4373.19it/s]
 14%|#3        | 10833/77848.12 [00:02<00:14, 4475.81it/s]
 14%|#4        | 11285/77848.12 [00:02<00:14, 4487.04it/s]
 15%|#5        | 11735/77848.12 [00:02<00:14, 4431.85it/s]
 16%|#5        | 12221/77848.12 [00:02<00:14, 4556.41it/s]
 16%|#6        | 12684/77848.12 [00:02<00:14, 4576.83it/s]
 17%|#6        | 13142/77848.12 [00:03<00:14, 4560.46it/s]
 17%|#7        | 13599/77848.12 [00:03<00:14, 4554.72it/s]
 18%|#8        | 14069/77848.12 [00:03<00:13, 4596.78it/s]
 19%|#8        | 14534/77848.12 [00:03<00:13, 4611.96it/s]
 19%|#9        | 14996/77848.12 [00:03<00:13, 4510.06it/s]
 20%|#9        | 15473/77848.12 [00:03<00:13, 4584.14it/s]
 20%|##        | 15936/77848.12 [00:03<00:13, 4596.07it/s]
 21%|##1       | 16396/77848.12 [00:03<00:13, 4580.06it/s]
 22%|##1       | 16855/77848.12 [00:03<00:13, 4499.52it/s]
 22%|##2       | 17324/77848.12 [00:03<00:13, 4552.76it/s]
 23%|##2       | 17780/77848.12 [00:04<00:13, 4542.67it/s]
 23%|##3       | 18245/77848.12 [00:04<00:13, 4573.53it/s]
 24%|##4       | 18703/77848.12 [00:04<00:12, 4553.52it/s]
 25%|##4       | 19180/77848.12 [00:04<00:12, 4615.20it/s]
 25%|##5       | 19644/77848.12 [00:04<00:12, 4621.00it/s]
 26%|##5       | 20113/77848.12 [00:04<00:12, 4638.97it/s]
 26%|##6       | 20583/77848.12 [00:04<00:12, 4655.61it/s]
 27%|##7       | 21060/77848.12 [00:04<00:12, 4687.25it/s]
 28%|##7       | 21529/77848.12 [00:04<00:12, 4675.84it/s]
 28%|##8       | 21997/77848.12 [00:04<00:12, 4623.24it/s]
 29%|##8       | 22470/77848.12 [00:05<00:11, 4652.59it/s]
 29%|##9       | 22940/77848.12 [00:05<00:11, 4662.91it/s]
 30%|###       | 23408/77848.12 [00:05<00:11, 4664.13it/s]
 31%|###       | 23875/77848.12 [00:05<00:11, 4650.07it/s]
 31%|###1      | 24342/77848.12 [00:05<00:11, 4653.19it/s]
 32%|###1      | 24831/77848.12 [00:05<00:11, 4721.92it/s]
 33%|###2      | 25305/77848.12 [00:05<00:11, 4723.24it/s]
 33%|###3      | 25778/77848.12 [00:05<00:11, 4666.97it/s]
 34%|###3      | 26245/77848.12 [00:05<00:11, 4641.95it/s]
 34%|###4      | 26745/77848.12 [00:05<00:10, 4747.80it/s]
 35%|###4      | 27223/77848.12 [00:06<00:10, 4755.81it/s]
 36%|###5      | 27699/77848.12 [00:06<00:10, 4701.84it/s]
 36%|###6      | 28170/77848.12 [00:06<00:10, 4619.17it/s]
 37%|###6      | 28658/77848.12 [00:06<00:10, 4692.34it/s]
 37%|###7      | 29128/77848.12 [00:06<00:10, 4687.25it/s]
 38%|###8      | 29598/77848.12 [00:06<00:10, 4655.03it/s]
 39%|###8      | 30072/77848.12 [00:06<00:10, 4678.40it/s]
 39%|###9      | 30541/77848.12 [00:06<00:10, 4619.81it/s]
 40%|###9      | 31031/77848.12 [00:06<00:09, 4702.10it/s]
 40%|####      | 31502/77848.12 [00:06<00:09, 4683.06it/s]
 41%|####1     | 31978/77848.12 [00:07<00:09, 4705.31it/s]
 42%|####1     | 32452/77848.12 [00:07<00:09, 4713.94it/s]
 42%|####2     | 32924/77848.12 [00:07<00:09, 4711.49it/s]
 43%|####2     | 33401/77848.12 [00:07<00:09, 4727.45it/s]
 44%|####3     | 33886/77848.12 [00:07<00:09, 4762.33it/s]
 44%|####4     | 34363/77848.12 [00:07<00:09, 4724.47it/s]
 45%|####4     | 34836/77848.12 [00:07<00:09, 4689.43it/s]
 45%|####5     | 35327/77848.12 [00:07<00:08, 4754.09it/s]
 46%|####5     | 35803/77848.12 [00:07<00:08, 4754.70it/s]
 47%|####6     | 36284/77848.12 [00:07<00:08, 4769.82it/s]
 47%|####7     | 36766/77848.12 [00:08<00:08, 4782.35it/s]
 48%|####7     | 37245/77848.12 [00:08<00:08, 4722.54it/s]
 48%|####8     | 37727/77848.12 [00:08<00:08, 4750.36it/s]
 49%|####9     | 38203/77848.12 [00:08<00:08, 4726.40it/s]
 50%|####9     | 38676/77848.12 [00:08<00:08, 4718.84it/s]
 50%|#####     | 39152/77848.12 [00:08<00:08, 4729.84it/s]
 51%|#####     | 39626/77848.12 [00:08<00:08, 4719.58it/s]
 52%|#####1    | 40099/77848.12 [00:08<00:08, 4696.89it/s]
 52%|#####2    | 40569/77848.12 [00:08<00:07, 4672.38it/s]
 53%|#####2    | 41037/77848.12 [00:09<00:07, 4614.61it/s]
 53%|#####3    | 41499/77848.12 [00:09<00:07, 4560.06it/s]
 54%|#####3    | 41965/77848.12 [00:09<00:07, 4589.34it/s]
 54%|#####4    | 42425/77848.12 [00:09<00:07, 4574.41it/s]
 55%|#####5    | 42883/77848.12 [00:09<00:07, 4557.72it/s]
 56%|#####5    | 43339/77848.12 [00:09<00:07, 4543.94it/s]
 56%|#####6    | 43794/77848.12 [00:09<00:07, 4524.76it/s]
 57%|#####6    | 44247/77848.12 [00:09<00:07, 4512.48it/s]
 57%|#####7    | 44703/77848.12 [00:09<00:07, 4526.25it/s]
 58%|#####8    | 45156/77848.12 [00:09<00:07, 4457.77it/s]
 59%|#####8    | 45617/77848.12 [00:10<00:07, 4501.76it/s]
 59%|#####9    | 46068/77848.12 [00:10<00:07, 4470.32it/s]
 60%|#####9    | 46533/77848.12 [00:10<00:06, 4523.11it/s]
 60%|######    | 46986/77848.12 [00:10<00:06, 4498.08it/s]
 61%|######    | 47456/77848.12 [00:10<00:06, 4554.54it/s]
 62%|######1   | 47931/77848.12 [00:10<00:06, 4611.27it/s]
 62%|######2   | 48393/77848.12 [00:10<00:06, 4523.17it/s]
 63%|######2   | 48859/77848.12 [00:10<00:06, 4562.14it/s]
 63%|######3   | 49316/77848.12 [00:10<00:06, 4539.83it/s]
 64%|######3   | 49771/77848.12 [00:10<00:06, 4525.10it/s]
 65%|######4   | 50236/77848.12 [00:11<00:06, 4561.63it/s]
 65%|######5   | 50693/77848.12 [00:11<00:05, 4563.44it/s]
 66%|######5   | 51150/77848.12 [00:11<00:05, 4547.43it/s]
 66%|######6   | 51612/77848.12 [00:11<00:05, 4568.91it/s]
 67%|######6   | 52070/77848.12 [00:11<00:05, 4570.15it/s]
 67%|######7   | 52529/77848.12 [00:11<00:05, 4574.12it/s]
 68%|######8   | 52987/77848.12 [00:11<00:05, 4556.89it/s]
 69%|######8   | 53474/77848.12 [00:11<00:05, 4649.89it/s]
 69%|######9   | 53952/77848.12 [00:11<00:05, 4687.50it/s]
 70%|######9   | 54421/77848.12 [00:11<00:05, 4660.40it/s]
 71%|#######   | 54888/77848.12 [00:12<00:04, 4637.54it/s]
 71%|#######1  | 55383/77848.12 [00:12<00:04, 4730.22it/s]
 72%|#######1  | 55869/77848.12 [00:12<00:04, 4768.24it/s]
 72%|#######2  | 56346/77848.12 [00:12<00:04, 4746.90it/s]
 73%|#######3  | 56834/77848.12 [00:12<00:04, 4784.42it/s]
 74%|#######3  | 57313/77848.12 [00:12<00:04, 4725.18it/s]
 74%|#######4  | 57820/77848.12 [00:12<00:04, 4826.20it/s]
 75%|#######4  | 58303/77848.12 [00:12<00:04, 4797.40it/s]
 76%|#######5  | 58783/77848.12 [00:12<00:03, 4782.74it/s]
 76%|#######6  | 59262/77848.12 [00:12<00:03, 4751.74it/s]
 77%|#######6  | 59738/77848.12 [00:13<00:03, 4717.42it/s]
 77%|#######7  | 60254/77848.12 [00:13<00:03, 4846.62it/s]
 78%|#######8  | 60739/77848.12 [00:13<00:03, 4797.40it/s]
 79%|#######8  | 61220/77848.12 [00:13<00:03, 4798.83it/s]
 79%|#######9  | 61703/77848.12 [00:13<00:03, 4808.04it/s]
 80%|#######9  | 62187/77848.12 [00:13<00:03, 4816.53it/s]
 81%|########  | 62691/77848.12 [00:13<00:03, 4882.43it/s]
 81%|########1 | 63180/77848.12 [00:13<00:03, 4867.85it/s]
 82%|########1 | 63667/77848.12 [00:13<00:02, 4839.43it/s]
 82%|########2 | 64152/77848.12 [00:13<00:02, 4822.92it/s]
 83%|########3 | 64643/77848.12 [00:14<00:02, 4846.41it/s]
 84%|########3 | 65145/77848.12 [00:14<00:02, 4896.20it/s]
 84%|########4 | 65635/77848.12 [00:14<00:02, 4857.18it/s]
 85%|########4 | 66121/77848.12 [00:14<00:02, 4850.13it/s]
 86%|########5 | 66607/77848.12 [00:14<00:02, 4738.72it/s]
 86%|########6 | 67132/77848.12 [00:14<00:02, 4887.16it/s]
 87%|########6 | 67622/77848.12 [00:14<00:02, 4886.15it/s]
 87%|########7 | 68112/77848.12 [00:14<00:02, 4838.24it/s]
 88%|########8 | 68597/77848.12 [00:14<00:01, 4818.12it/s]
 89%|########8 | 69080/77848.12 [00:14<00:01, 4767.38it/s]
 89%|########9 | 69589/77848.12 [00:15<00:01, 4861.54it/s]
 90%|######### | 70076/77848.12 [00:15<00:01, 4795.74it/s]
 91%|######### | 70556/77848.12 [00:15<00:01, 4764.53it/s]
 91%|#########1| 71033/77848.12 [00:15<00:01, 4713.25it/s]
 92%|#########1| 71513/77848.12 [00:15<00:01, 4736.71it/s]
 92%|#########2| 71991/77848.12 [00:15<00:01, 4746.26it/s]
 93%|#########3| 72466/77848.12 [00:15<00:01, 4699.35it/s]
 94%|#########3| 72937/77848.12 [00:15<00:01, 4699.17it/s]
 94%|#########4| 73408/77848.12 [00:15<00:00, 4656.86it/s]
 95%|#########4| 73907/77848.12 [00:16<00:00, 4754.39it/s]
 96%|#########5| 74383/77848.12 [00:16<00:00, 4738.87it/s]
 96%|#########6| 74858/77848.12 [00:16<00:00, 4719.80it/s]
 97%|#########6| 75331/77848.12 [00:16<00:00, 4649.85it/s]
 97%|#########7| 75820/77848.12 [00:16<00:00, 4718.59it/s]
 98%|#########8| 76293/77848.12 [00:16<00:00, 4702.99it/s]
 99%|#########8| 76764/77848.12 [00:16<00:00, 4683.79it/s]
 99%|#########9| 77233/77848.12 [00:16<00:00, 4614.60it/s]
100%|#########9| 77749/77848.12 [00:16<00:00, 4772.10it/s]
78227it [00:16, 4760.73it/s]
78704it [00:17, 4734.53it/s]
79178it [00:17, 4664.64it/s]
79717it [00:17, 4876.65it/s]
80206it [00:17, 4774.87it/s]
80685it [00:17, 4776.96it/s]
81164it [00:17, 4657.13it/s]
81686it [00:17, 4816.42it/s]
82169it [00:17, 4734.83it/s]
82644it [00:17, 4717.91it/s]
83117it [00:17, 4633.63it/s]
83607it [00:18, 4710.05it/s]
84080it [00:18, 4711.70it/s]
84552it [00:18, 4647.17it/s]
85018it [00:18, 4617.27it/s]
85484it [00:18, 4628.43it/s]
85948it [00:18, 4611.56it/s]
86410it [00:18, 4536.33it/s]
86889it [00:18, 4609.83it/s]
87351it [00:18, 4598.11it/s]
87812it [00:18, 4491.33it/s]
88288it [00:19, 4569.18it/s]
88746it [00:19, 4477.15it/s]
89203it [00:19, 4501.97it/s]
89670it [00:19, 4549.66it/s]
90126it [00:19, 4491.57it/s]
90600it [00:19, 4562.16it/s]
91057it [00:19, 4489.16it/s]
91521it [00:19, 4532.81it/s]
91975it [00:19, 4452.89it/s]
92421it [00:20, 4395.42it/s]
92861it [00:20, 4386.49it/s]
93300it [00:20, 4287.92it/s]
93743it [00:20, 4326.46it/s]
94177it [00:20, 4232.91it/s]
94616it [00:20, 4278.53it/s]
95045it [00:20, 4224.65it/s]
95468it [00:20, 4212.28it/s]
95890it [00:20, 4167.48it/s]
96307it [00:20, 4099.62it/s]
96718it [00:21, 4044.62it/s]
96989it [00:21, 4586.61it/s]

Threshold Stopping Criterion

A scalar map can be used to define where the tracking stops. The threshold stopping criterion uses a scalar map to stop the tracking whenever the interpolated scalar value is lower than a fixed threshold. Here, we show an example using the fractional anisotropy (FA) map of the DTI model. The threshold stopping criterion uses a trilinear interpolation at the tracking position.

Parameters

  • metric_map: numpy array [:, :, :]

  • threshold: float

Stopping States

  • ‘ENDPOINT’: stops at a position where metric_map < threshold; the streamline

reached the target stopping area. - ‘OUTSIDEIMAGE’: stops at a position outside of metric_map; the streamline reached an area outside the image where no direction data is available. - ‘TRACKPOINT’: stops at a position because no direction is available; the streamline is stopping where metric_map >= threshold, but there is no valid direction to follow. - ‘INVALIDPOINT’: N/A.

tensor_model = TensorModel(gtab)
tenfit = tensor_model.fit(data, mask=labels > 0)
FA = fractional_anisotropy(tenfit.evals)

threshold_criterion = ThresholdStoppingCriterion(FA, .2)

fig = plt.figure()
mask_fa = FA.copy()
mask_fa[mask_fa < 0.2] = 0
plt.xticks([])
plt.yticks([])
plt.imshow(mask_fa[:, :, data.shape[2] // 2].T, cmap='gray', origin='lower',
           interpolation='nearest')
fig.tight_layout()
fig.savefig('threshold_fa.png')
tracking stopping criterion
examples_built/13_fiber_tracking/threshold_fa.png

Thresholded fractional anisotropy map.

streamline_generator = LocalTracking(dg,
                                     threshold_criterion,
                                     seeds,
                                     affine,
                                     step_size=.5,
                                     return_all=True)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_probabilistic_thresh_all.trk")

if has_fury:
    scene = window.Scene()
    scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
    window.record(scene, out_path='tractogram_deterministic_thresh_all.png',
                  size=(800, 800))
    if interactive:
        window.show(scene)
tracking stopping criterion
examples_built/13_fiber_tracking/tractogram_deterministic_thresh_all.png

Corpus Callosum using deterministic tractography with a thresholded fractional anisotropy mask.

Binary Stopping Criterion

A binary mask can be used to define where the tracking stops. The binary stopping criterion stops the tracking whenever the tracking position is outside the mask. Here, we show how to obtain the binary stopping criterion from the white matter mask defined above. The binary stopping criterion uses a nearest-neighborhood interpolation at the tracking position.

Parameters

  • mask: numpy array [:, :, :]

Stopping States

  • ‘ENDPOINT’: stops at a position where mask = 0; the streamline

reached the target stopping area. - ‘OUTSIDEIMAGE’: stops at a position outside of metric_map; the streamline reached an area outside the image where no direction data is available. - ‘TRACKPOINT’: stops at a position because no direction is available; the streamline is stopping where mask > 0, but there is no valid direction to follow. - ‘INVALIDPOINT’: N/A.

binary_criterion = BinaryStoppingCriterion(white_matter == 1)

fig = plt.figure()
plt.xticks([])
plt.yticks([])
fig.tight_layout()
plt.imshow(white_matter[:, :, data.shape[2] // 2].T, cmap='gray',
           origin='lower', interpolation='nearest')

fig.savefig('white_matter_mask.png')
tracking stopping criterion
examples_built/13_fiber_tracking/white_matter_mask.png

White matter binary mask.

streamline_generator = LocalTracking(dg,
                                     binary_criterion,
                                     seeds,
                                     affine,
                                     step_size=.5,
                                     return_all=True)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_deterministic_binary_all.trk")

if has_fury:
    scene = window.Scene()
    scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
    window.record(scene, out_path='tractogram_deterministic_binary_all.png',
                  size=(800, 800))
    if interactive:
        window.show(scene)
tracking stopping criterion
examples_built/13_fiber_tracking/tractogram_deterministic_binary_all.png

Corpus Callosum using deterministic tractography with a binary white matter mask.

ACT Stopping Criterion

Anatomically-constrained tractography (ACT) [Smith2012] uses information from anatomical images to determine when the tractography stops. The include_map defines when the streamline reached a ‘valid’ stopping region (e.g. gray matter partial volume estimation (PVE) map) and the exclude_map defines when the streamline reached an ‘invalid’ stopping region (e.g. corticospinal fluid PVE map). The background of the anatomical image should be added to the include_map to keep streamlines exiting the brain (e.g. through the brain stem). The ACT stopping criterion uses a trilinear interpolation at the tracking position.

Parameters

  • include_map: numpy array [:, :, :],

  • exclude_map: numpy array [:, :, :],

Stopping States

  • ‘ENDPOINT’: stops at a position where include_map > 0.5; the streamline

reached the target stopping area. - ‘OUTSIDEIMAGE’: stops at a position outside of include_map or exclude_map; the streamline reached an area outside the image where no direction data is available. - ‘TRACKPOINT’: stops at a position because no direction is available; the streamline is stopping where include_map < 0.5 and exclude_map < 0.5, but there is no valid direction to follow. - ‘INVALIDPOINT’: exclude_map > 0.5; the streamline reach a position which is anatomically not plausible.

f_pve_csf, f_pve_gm, f_pve_wm = get_fnames('stanford_pve_maps')
pve_csf_data = load_nifti_data(f_pve_csf)
pve_gm_data = load_nifti_data(f_pve_gm)
pve_wm_data = load_nifti_data(f_pve_wm)

background = np.ones(pve_gm_data.shape)
background[(pve_gm_data + pve_wm_data + pve_csf_data) > 0] = 0

include_map = pve_gm_data
include_map[background > 0] = 1
exclude_map = pve_csf_data

act_criterion = ActStoppingCriterion(include_map, exclude_map)

fig = plt.figure()
plt.subplot(121)
plt.xticks([])
plt.yticks([])
plt.imshow(include_map[:, :, data.shape[2] // 2].T, cmap='gray',
           origin='lower', interpolation='nearest')

plt.subplot(122)
plt.xticks([])
plt.yticks([])
plt.imshow(exclude_map[:, :, data.shape[2] // 2].T, cmap='gray',
           origin='lower', interpolation='nearest')

fig.tight_layout()
fig.savefig('act_maps.png')
tracking stopping criterion
examples_built/13_fiber_tracking/act_maps.png

Include (left) and exclude (right) maps for ACT.

streamline_generator = LocalTracking(dg,
                                     act_criterion,
                                     seeds,
                                     affine,
                                     step_size=.5,
                                     return_all=True)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_deterministic_act_all.trk")

if has_fury:
    scene = window.Scene()
    scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
    window.record(scene, out_path='tractogram_deterministic_act_all.png',
                  size=(800, 800))
    if interactive:
        window.show(scene)
tracking stopping criterion
examples_built/13_fiber_tracking/tractogram_deterministic_act_all.png

Corpus Callosum using deterministic tractography with ACT stopping criterion.

streamline_generator = LocalTracking(dg,
                                     act_criterion,
                                     seeds,
                                     affine,
                                     step_size=.5,
                                     return_all=False)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_deterministic_act_valid.trk")

if has_fury:
    scene = window.Scene()
    scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
    window.record(scene, out_path='tractogram_deterministic_act_valid.png',
                  size=(800, 800))
    if interactive:
        window.show(scene)
tracking stopping criterion
examples_built/13_fiber_tracking/tractogram_deterministic_act_valid.png

Corpus Callosum using deterministic tractography with ACT stopping criterion. Streamlines ending in gray matter region only.

The threshold and binary stopping criterion use respectively a scalar map and a binary mask to stop the tracking. The ACT stopping criterion use partial volume fraction (PVE) maps from an anatomical image to stop the tracking. Additionally, the ACT stopping criterion determines if the tracking stopped in expected regions (e.g. gray matter) and allows the user to get only streamlines stopping in those regions.

Notes

Currently,the proposed method that cuts streamlines going through subcortical gray matter regions is not implemented. The backtracking technique for streamlines reaching INVALIDPOINT is not implemented either [Smith2012].

References

[Smith2012] (1,2,3)

Smith, R. E., Tournier, J.-D., Calamante, F., & Connelly, A. Anatomically-constrained tractography: Improved diffusion MRI streamlines tractography through effective use of anatomical information. NeuroImage, 63(3), 1924-1938, 2012.

[Girard2014]

Girard, G., Whittingstall, K., Deriche, R., & Descoteaux, M. Towards quantitative connectivity analysis: reducing tractography biases. NeuroImage, 98, 266-278, 2014.

Total running time of the script: ( 1 minutes 8.901 seconds)

Gallery generated by Sphinx-Gallery