Parallel Transport Tractography#

Parallel Transport Tractography (PTT) [Aydogan2021]

Let’s start by importing the necessary modules.

from dipy.io.streamline import save_trk
from dipy.io.stateful_tractogram import Space, StatefulTractogram
from dipy.data import get_sphere
from dipy.direction import PTTDirectionGetter
from dipy.reconst.shm import CsaOdfModel
from dipy.core.gradients import gradient_table
from dipy.data import get_fnames
from dipy.io.gradients import read_bvals_bvecs
from dipy.io.image import load_nifti, load_nifti_data
from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel,
                                   auto_response_ssst)
from dipy.tracking import utils
from dipy.tracking.local_tracking import LocalTracking
from dipy.tracking.streamline import Streamlines
from dipy.tracking.stopping_criterion import 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')

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)
  0%|                                                                                                                            | 0/58788 [00:00<?, ?it/s]
  1%|▋                                                                                                               | 360/58788 [00:00<00:18, 3120.04it/s]
  2%|█▊                                                                                                              | 947/58788 [00:00<00:13, 4353.87it/s]
  2%|██▊                                                                                                            | 1458/58788 [00:00<00:12, 4602.02it/s]
  3%|███▊                                                                                                           | 2002/58788 [00:00<00:11, 4910.86it/s]
  4%|████▋                                                                                                          | 2499/58788 [00:00<00:11, 4926.75it/s]
  5%|█████▋                                                                                                         | 2994/58788 [00:00<00:11, 4930.11it/s]
  6%|██████▋                                                                                                        | 3564/58788 [00:00<00:10, 5176.02it/s]
  7%|███████▋                                                                                                       | 4083/58788 [00:00<00:10, 5176.03it/s]
  8%|████████▋                                                                                                      | 4602/58788 [00:00<00:10, 4937.15it/s]
  9%|█████████▋                                                                                                     | 5099/58788 [00:01<00:11, 4879.61it/s]
 10%|██████████▋                                                                                                    | 5630/58788 [00:01<00:10, 4992.85it/s]
 10%|███████████▌                                                                                                   | 6131/58788 [00:01<00:10, 4843.26it/s]
 11%|████████████▍                                                                                                  | 6618/58788 [00:01<00:11, 4691.91it/s]
 12%|█████████████▍                                                                                                 | 7104/58788 [00:01<00:10, 4731.31it/s]
 13%|██████████████▎                                                                                                | 7602/58788 [00:01<00:10, 4792.56it/s]
 14%|███████████████▎                                                                                               | 8139/58788 [00:01<00:10, 4950.14it/s]
 15%|████████████████▎                                                                                              | 8650/58788 [00:01<00:10, 4984.31it/s]
 16%|█████████████████▎                                                                                             | 9195/58788 [00:01<00:09, 5107.43it/s]
 17%|██████████████████▍                                                                                            | 9767/58788 [00:01<00:09, 5273.86it/s]
 18%|███████████████████▌                                                                                          | 10441/58788 [00:02<00:08, 5563.20it/s]
 19%|████████████████████▊                                                                                         | 11117/58788 [00:02<00:08, 5901.49it/s]
 20%|██████████████████████                                                                                        | 11758/58788 [00:02<00:07, 6033.28it/s]
 21%|███████████████████████▏                                                                                      | 12362/58788 [00:02<00:08, 5649.68it/s]
 22%|████████████████████████▏                                                                                     | 12932/58788 [00:02<00:08, 5491.90it/s]
 23%|█████████████████████████▎                                                                                    | 13526/58788 [00:02<00:08, 5604.68it/s]
 24%|██████████████████████████▌                                                                                   | 14184/58788 [00:02<00:07, 5866.63it/s]
 25%|███████████████████████████▋                                                                                  | 14793/58788 [00:02<00:07, 5921.85it/s]
 26%|████████████████████████████▊                                                                                 | 15416/58788 [00:02<00:07, 5998.69it/s]
 28%|██████████████████████████████▎                                                                               | 16184/58788 [00:03<00:06, 6488.08it/s]
 29%|███████████████████████████████▌                                                                              | 16835/58788 [00:03<00:06, 6111.21it/s]
 30%|████████████████████████████████▋                                                                             | 17457/58788 [00:03<00:06, 6129.58it/s]
 31%|█████████████████████████████████▊                                                                            | 18075/58788 [00:03<00:06, 5946.67it/s]
 32%|██████████████████████████████████▉                                                                           | 18674/58788 [00:03<00:07, 5608.14it/s]
 33%|████████████████████████████████████                                                                          | 19241/58788 [00:03<00:07, 5452.90it/s]
 34%|█████████████████████████████████████                                                                         | 19790/58788 [00:03<00:07, 5033.75it/s]
 35%|█████████████████████████████████████▉                                                                        | 20301/58788 [00:03<00:07, 4935.16it/s]
 35%|██████████████████████████████████████▉                                                                       | 20830/58788 [00:03<00:07, 5021.59it/s]
 36%|███████████████████████████████████████▉                                                                      | 21336/58788 [00:04<00:07, 4993.76it/s]
 37%|████████████████████████████████████████▉                                                                     | 21869/58788 [00:04<00:07, 5080.09it/s]
 38%|█████████████████████████████████████████▉                                                                    | 22417/58788 [00:04<00:07, 5182.22it/s]
 39%|██████████████████████████████████████████▉                                                                   | 22955/58788 [00:04<00:06, 5230.14it/s]
 40%|████████████████████████████████████████████▏                                                                 | 23592/58788 [00:04<00:06, 5554.84it/s]
 41%|█████████████████████████████████████████████▏                                                                | 24159/58788 [00:04<00:06, 5573.69it/s]
 42%|██████████████████████████████████████████████▎                                                               | 24718/58788 [00:04<00:06, 5562.59it/s]
 43%|███████████████████████████████████████████████▎                                                              | 25301/58788 [00:04<00:05, 5628.28it/s]
 44%|████████████████████████████████████████████████▋                                                             | 25996/58788 [00:04<00:05, 6002.67it/s]
 45%|█████████████████████████████████████████████████▊                                                            | 26597/58788 [00:04<00:05, 5852.86it/s]
 46%|██████████████████████████████████████████████████▊                                                           | 27184/58788 [00:05<00:05, 5645.38it/s]
 47%|███████████████████████████████████████████████████▉                                                          | 27764/58788 [00:05<00:05, 5676.35it/s]
 48%|█████████████████████████████████████████████████████                                                         | 28334/58788 [00:05<00:05, 5508.03it/s]
 49%|██████████████████████████████████████████████████████                                                        | 28887/58788 [00:05<00:05, 5349.55it/s]
 50%|███████████████████████████████████████████████████████                                                       | 29424/58788 [00:05<00:05, 5052.71it/s]
 51%|████████████████████████████████████████████████████████                                                      | 29938/58788 [00:05<00:05, 5065.83it/s]
 52%|████████████████████████████████████████████████████████▉                                                     | 30448/58788 [00:05<00:05, 5067.52it/s]
 53%|█████████████████████████████████████████████████████████▉                                                    | 30957/58788 [00:05<00:05, 4923.05it/s]
 54%|██████████████████████████████████████████████████████████▉                                                   | 31503/58788 [00:05<00:05, 5067.29it/s]
 54%|███████████████████████████████████████████████████████████▉                                                  | 32012/58788 [00:06<00:05, 4923.35it/s]
 55%|████████████████████████████████████████████████████████████▊                                                 | 32507/58788 [00:06<00:05, 4655.71it/s]
 56%|█████████████████████████████████████████████████████████████▊                                                | 33035/58788 [00:06<00:05, 4822.07it/s]
 57%|██████████████████████████████████████████████████████████████▊                                               | 33548/58788 [00:06<00:05, 4898.10it/s]
 58%|███████████████████████████████████████████████████████████████▋                                              | 34041/58788 [00:06<00:05, 4743.42it/s]
 59%|████████████████████████████████████████████████████████████████▌                                             | 34518/58788 [00:06<00:05, 4724.87it/s]
 60%|█████████████████████████████████████████████████████████████████▌                                            | 35049/58788 [00:06<00:04, 4878.86it/s]
 61%|██████████████████████████████████████████████████████████████████▋                                           | 35639/58788 [00:06<00:04, 5165.06it/s]
 62%|███████████████████████████████████████████████████████████████████▋                                          | 36191/58788 [00:06<00:04, 5260.16it/s]
 63%|████████████████████████████████████████████████████████████████████▉                                         | 36841/58788 [00:06<00:03, 5614.80it/s]
 64%|█████████████████████████████████████████████████████████████████████▉                                        | 37405/58788 [00:07<00:03, 5457.25it/s]
 65%|███████████████████████████████████████████████████████████████████████                                       | 37953/58788 [00:07<00:03, 5450.13it/s]
 66%|████████████████████████████████████████████████████████████████████████▏                                     | 38584/58788 [00:07<00:03, 5688.46it/s]
 67%|█████████████████████████████████████████████████████████████████████████▎                                    | 39155/58788 [00:07<00:03, 5679.86it/s]
 68%|██████████████████████████████████████████████████████████████████████████▍                                   | 39756/58788 [00:07<00:03, 5765.59it/s]
 69%|███████████████████████████████████████████████████████████████████████████▌                                  | 40399/58788 [00:07<00:03, 5945.09it/s]
 70%|████████████████████████████████████████████████████████████████████████████▋                                 | 40995/58788 [00:07<00:02, 5935.32it/s]
 71%|█████████████████████████████████████████████████████████████████████████████▊                                | 41589/58788 [00:07<00:02, 5754.14it/s]
 72%|██████████████████████████████████████████████████████████████████████████████▉                               | 42166/58788 [00:07<00:03, 5428.22it/s]
 73%|████████████████████████████████████████████████████████████████████████████████                              | 42765/58788 [00:08<00:02, 5577.69it/s]
 74%|█████████████████████████████████████████████████████████████████████████████████                             | 43327/58788 [00:08<00:02, 5578.22it/s]
 75%|██████████████████████████████████████████████████████████████████████████████████▎                           | 43976/58788 [00:08<00:02, 5830.07it/s]
 76%|███████████████████████████████████████████████████████████████████████████████████▍                          | 44562/58788 [00:08<00:02, 5659.85it/s]
 77%|████████████████████████████████████████████████████████████████████████████████████▍                         | 45131/58788 [00:08<00:02, 5375.40it/s]
 78%|█████████████████████████████████████████████████████████████████████████████████████▍                        | 45673/58788 [00:08<00:02, 5345.11it/s]
 79%|██████████████████████████████████████████████████████████████████████████████████████▌                       | 46241/58788 [00:08<00:02, 5428.46it/s]
 80%|███████████████████████████████████████████████████████████████████████████████████████▋                      | 46863/58788 [00:08<00:02, 5641.93it/s]
 81%|████████████████████████████████████████████████████████████████████████████████████████▋                     | 47430/58788 [00:08<00:02, 5477.75it/s]
 82%|█████████████████████████████████████████████████████████████████████████████████████████▉                    | 48060/58788 [00:08<00:01, 5702.83it/s]
 83%|███████████████████████████████████████████████████████████████████████████████████████████                   | 48660/58788 [00:09<00:01, 5775.99it/s]
 84%|████████████████████████████████████████████████████████████████████████████████████████████▏                 | 49240/58788 [00:09<00:01, 5607.96it/s]
 85%|█████████████████████████████████████████████████████████████████████████████████████████████▎                | 49844/58788 [00:09<00:01, 5720.71it/s]
 86%|██████████████████████████████████████████████████████████████████████████████████████████████▎               | 50418/58788 [00:09<00:01, 5237.41it/s]
 87%|███████████████████████████████████████████████████████████████████████████████████████████████▎              | 50951/58788 [00:09<00:01, 5235.77it/s]
 88%|████████████████████████████████████████████████████████████████████████████████████████████████▎             | 51481/58788 [00:09<00:01, 5096.53it/s]
 89%|█████████████████████████████████████████████████████████████████████████████████████████████████▍            | 52050/58788 [00:09<00:01, 5253.32it/s]
 89%|██████████████████████████████████████████████████████████████████████████████████████████████████▍           | 52615/58788 [00:09<00:01, 5357.34it/s]
 90%|███████████████████████████████████████████████████████████████████████████████████████████████████▍          | 53165/58788 [00:09<00:01, 5388.75it/s]
 91%|████████████████████████████████████████████████████████████████████████████████████████████████████▍         | 53707/58788 [00:10<00:00, 5387.91it/s]
 92%|█████████████████████████████████████████████████████████████████████████████████████████████████████▌        | 54251/58788 [00:10<00:00, 5392.77it/s]
 93%|██████████████████████████████████████████████████████████████████████████████████████████████████████▌       | 54843/58788 [00:10<00:00, 5536.71it/s]
 94%|███████████████████████████████████████████████████████████████████████████████████████████████████████▊      | 55455/58788 [00:10<00:00, 5698.12it/s]
 95%|████████████████████████████████████████████████████████████████████████████████████████████████████████▊     | 56026/58788 [00:10<00:00, 5526.87it/s]
 96%|█████████████████████████████████████████████████████████████████████████████████████████████████████████▊    | 56581/58788 [00:10<00:00, 5367.18it/s]
 97%|██████████████████████████████████████████████████████████████████████████████████████████████████████████▉   | 57120/58788 [00:10<00:00, 5362.66it/s]
 98%|███████████████████████████████████████████████████████████████████████████████████████████████████████████▉  | 57658/58788 [00:10<00:00, 5351.00it/s]
 99%|████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 58194/58788 [00:10<00:00, 5340.40it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████▉| 58729/58788 [00:10<00:00, 5177.42it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 58788/58788 [00:11<00:00, 5340.45it/s]

We use the GFA of the CSA model to build a stopping criterion.

csa_model = CsaOdfModel(gtab, sh_order=6)
gfa = csa_model.fit(data, mask=white_matter).gfa
stopping_criterion = ThresholdStoppingCriterion(gfa, .25)

Prepare the PTT direction getter using the fiber ODF (FOD) obtain with CSD. Start the local tractography using PTT direction getter.

sphere = get_sphere(name='repulsion724')
fod = csd_fit.odf(sphere)
pmf = fod.clip(min=0)
ptt_dg = PTTDirectionGetter.from_pmf(pmf, max_angle=15, probe_length=0.5,
                                     sphere=sphere)

# Parallel Transport Tractography
streamline_generator = LocalTracking(direction_getter=ptt_dg,
                                     stopping_criterion=stopping_criterion,
                                     seeds=seeds,
                                     affine=affine,
                                     step_size=0.2)
streamlines = Streamlines(streamline_generator)
sft = StatefulTractogram(streamlines, hardi_img, Space.RASMM)
save_trk(sft, "tractogram_ptt_dg_pmf.trk")

if has_fury:
    scene = window.Scene()
    scene.add(actor.line(streamlines, colormap.line_colors(streamlines)))
    window.record(scene, out_path='tractogram_ptt_dg_pmf.png',
                  size=(800, 800))
    if interactive:
        window.show(scene)
tracking ptt

Corpus Callosum using ptt direction getter from PMF

References#

[Aydogan2021]

Aydogan DB, Shi Y. Parallel Transport Tractography. IEEE Trans Med Imaging. 2021 Feb;40(2):635-647. doi: 10.1109/TMI.2020.3034038. Epub 2021 Feb 2. PMID: 33104507; PMCID: PMC7931442.

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

Gallery generated by Sphinx-Gallery