-
Notifications
You must be signed in to change notification settings - Fork 429
/
tracking_bootstrap_peaks.py
135 lines (101 loc) · 4.29 KB
/
tracking_bootstrap_peaks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"""
=================================================
Bootstrap and Closest Peak Direction Getters Example
=================================================
This example shows how choices in direction-getter impact fiber
tracking results by demonstrating the bootstrap direction getter (a type of
probabilistic tracking, as described in [Berman2008]_) and the closest peak
direction getter (a type of deterministic tracking).
(Amirbekian, PhD thesis, 2016)
Let's load the necessary modules for executing this tutorial.
"""
from dipy.data import read_stanford_labels
from dipy.tracking import utils
from dipy.tracking.local import (ThresholdTissueClassifier, LocalTracking)
from dipy.io.streamline import save_trk
from dipy.viz import window, actor, colormap as cmap
renderer = window.Renderer()
"""
Now we import the CSD model
"""
from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel
"""
First we load our images and establish seeds. See the Introduction to Basic
Tracking tutorial for more background on these steps.
"""
hardi_img, gtab, labels_img = read_stanford_labels()
data = hardi_img.get_data()
labels = labels_img.get_data()
affine = hardi_img.affine
seed_mask = labels == 2
white_matter = (labels == 1) | (labels == 2)
seeds = utils.seeds_from_mask(seed_mask, density=1, affine=affine)
"""
Next, we fit the CSD model
"""
csd_model = ConstrainedSphericalDeconvModel(gtab, None, sh_order=6)
csd_fit = csd_model.fit(data, mask=white_matter)
"""
we use the CSA fit to calculate GFA, which will serve as our tissue
classifier
"""
from dipy.reconst.shm import CsaOdfModel
csa_model = CsaOdfModel(gtab, sh_order=6)
gfa = csa_model.fit(data, mask=white_matter).gfa
classifier = ThresholdTissueClassifier(gfa, .25)
"""
Next, we need to set up our two direction getters
"""
"""
Example #1: Bootstrap direction getter with CSD Model
"""
from dipy.direction import BootDirectionGetter
from dipy.tracking.streamline import Streamlines
from dipy.data import small_sphere
boot_dg_csd = BootDirectionGetter.from_data(data, csd_model, max_angle=30.,
sphere=small_sphere)
boot_streamline_generator = LocalTracking(boot_dg_csd, classifier, seeds,
affine, step_size=.5)
streamlines = Streamlines(boot_streamline_generator)
renderer.clear()
renderer.add(actor.line(streamlines, cmap.line_colors(streamlines)))
window.record(renderer, out_path='bootstrap_dg_CSD.png', size=(600, 600))
"""
.. figure:: bootstrap_dg_CSD.png
:align: center
**Corpus Callosum Bootstrap Probabilistic Direction Getter**
We have created a bootstrapped probabilistic set of streamlines. If you repeat
the fiber tracking (keeping all inputs the same) you will NOT get exactly the
same set of streamlines. We can save the streamlines as a Trackvis file so it
can be loaded into other software for visualization or further analysis.
"""
save_trk("bootstrap_dg_CSD.trk", streamlines, affine, labels.shape)
"""
Example #2: Closest peak direction getter with CSD Model
"""
from dipy.direction import ClosestPeakDirectionGetter
pmf = csd_fit.odf(small_sphere).clip(min=0)
peak_dg = ClosestPeakDirectionGetter.from_pmf(pmf, max_angle=30.,
sphere=small_sphere)
peak_streamline_generator = LocalTracking(peak_dg, classifier, seeds, affine,
step_size=.5)
streamlines = Streamlines(peak_streamline_generator)
renderer.clear()
renderer.add(actor.line(streamlines, cmap.line_colors(streamlines)))
window.record(renderer, out_path='closest_peak_dg_CSD.png', size=(600, 600))
"""
.. figure:: closest_peak_dg_CSD.png
:align: center
**Corpus Callosum Closest Peak Deterministic Direction Getter**
We have created a set of streamlines using the closest peak direction getter,
which is a type of deterministic tracking. If you repeat the fiber tracking
(keeping all inputs the same) you will get exactly the same set of streamlines.
We can save the streamlines as a Trackvis file so it can be loaded into other
software for visualization or further analysis.
"""
save_trk("closest_peak_dg_CSD.trk", streamlines, affine, labels.shape)
"""
.. [Berman2008] Berman, J. et al., Probabilistic streamline q-ball
tractography using the residual bootstrap, NeuroImage, vol 39, no 1, 2008
.. include:: ../links_names.inc
"""