Fiber to bundle coherence measures#

This demo presents the fiber to bundle coherence (FBC) quantitative measure of the alignment of each fiber with the surrounding fiber bundles [Meesters2016]. These measures are useful in ‘cleaning’ the results of tractography algorithms, since low FBCs indicate which fibers are isolated and poorly aligned with their neighbors, as shown in the figure below.

_static/images/examples/fbc_illustration.png

On the left this figure illustrates (in 2D) the contribution of two fiber points to the kernel density estimator. The kernel density estimator is the sum over all such locally aligned kernels. The local fiber to bundle coherence, shown on the right, color-coded for each fiber, is obtained by evaluating the kernel density estimator along the fibers. One spurious fiber is present which is isolated and badly aligned with the other fibers, and can be identified by a low LFBC value in the region where it deviates from the bundle. Figure adapted from [Portegies2015].#

Here we implement FBC measures based on kernel density estimation in the non-flat 5D position-orientation domain. First we compute the kernel density estimator induced by the full lifted output (defined in the space of positions and orientations) of the tractography. Then, the Local FBC (LFBC) is the result of evaluating the estimator along each element of the lifted fiber. A whole fiber measure, the relative FBC (RFBC), is calculated by the minimum of the moving average LFBC along the fiber. Details of the computation of FBC can be found in [Portegies2015].

The FBC measures are evaluated on the Stanford HARDI dataset (150 orientations, b=2000 \(s/mm^2\)) which is one of the standard example datasets in DIPY.

import numpy as np

from dipy.core.gradients import gradient_table
from dipy.data import get_fnames, default_sphere
from dipy.denoise.enhancement_kernel import EnhancementKernel
from dipy.direction import peaks_from_model, ProbabilisticDirectionGetter
from dipy.io.image import load_nifti_data, load_nifti
from dipy.io.gradients import read_bvals_bvecs
from dipy.reconst.shm import CsaOdfModel
from dipy.reconst.csdeconv import (
  auto_response_ssst, ConstrainedSphericalDeconvModel)
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.tracking.fbcmeasures import FBCMeasures
from dipy.viz import window, actor

# Enables/disables interactive visualization
interactive = False
# Fix seed
rng = np.random.default_rng(1)

# Read data
hardi_fname, hardi_bval_fname, hardi_bvec_fname = get_fnames('stanford_hardi')
label_fname = get_fnames('stanford_labels')
t1_fname = get_fnames('stanford_t1')

data, affine = load_nifti(hardi_fname)
labels = load_nifti_data(label_fname)
t1_data = load_nifti_data(t1_fname)
bvals, bvecs = read_bvals_bvecs(hardi_bval_fname, hardi_bvec_fname)
gtab = gradient_table(bvals, bvecs)

# Select a relevant part of the data (left hemisphere)
# Coordinates given in x bounds, y bounds, z bounds
dshape = data.shape[:-1]
xa, xb, ya, yb, za, zb = [15, 42, 10, 65, 18, 65]
data_small = data[xa:xb, ya:yb, za:zb]
selectionmask = np.zeros(dshape, 'bool')
selectionmask[xa:xb, ya:yb, za:zb] = True

The data is first fitted to the Constant Solid Angle (CDA) ODF Model. CSA is a good choice to estimate general fractional anisotropy (GFA), which the stopping criterion can use to restrict fiber tracking to those areas where the ODF shows significant restricted diffusion, thus creating a region-of-interest in which the computations are done.

# Perform CSA
csa_model = CsaOdfModel(gtab, sh_order_max=6)
csa_peaks = peaks_from_model(csa_model, data, default_sphere,
                             relative_peak_threshold=.6,
                             min_separation_angle=45,
                             mask=selectionmask)

# Stopping Criterion
stopping_criterion = ThresholdStoppingCriterion(csa_peaks.gfa, 0.25)

In order to perform probabilistic fiber tracking we first fit the data to the Constrained Spherical Deconvolution (CSD) model in DIPY. This model represents each voxel in the data set as a collection of small white matter fibers with different orientations. The density of fibers along each orientation is known as the Fiber Orientation Distribution (FOD), used in the fiber tracking.

# Perform CSD on the original data
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_small)
csd_fit_shm = np.lib.pad(csd_fit.shm_coeff, ((xa, dshape[0]-xb),
                                             (ya, dshape[1]-yb),
                                             (za, dshape[2]-zb),
                                             (0, 0)), 'constant')

# Probabilistic direction getting for fiber tracking
prob_dg = ProbabilisticDirectionGetter.from_shcoeff(csd_fit_shm,
                                                    max_angle=30.,
                                                    sphere=default_sphere)
  0%|                                                                                                                                                  | 0/69795 [00:00<?, ?it/s]
  1%|▊                                                                                                                                     | 450/69795 [00:00<00:16, 4114.72it/s]
  1%|█▋                                                                                                                                    | 895/69795 [00:00<00:16, 4087.54it/s]
  2%|██▍                                                                                                                                  | 1304/69795 [00:00<00:17, 3929.10it/s]
  2%|███▎                                                                                                                                 | 1730/69795 [00:00<00:17, 3915.53it/s]
  3%|████                                                                                                                                 | 2141/69795 [00:00<00:17, 3946.81it/s]
  4%|████▉                                                                                                                                | 2567/69795 [00:00<00:16, 4041.04it/s]
  4%|█████▊                                                                                                                               | 3076/69795 [00:00<00:15, 4246.76it/s]
  5%|██████▋                                                                                                                              | 3511/69795 [00:00<00:15, 4159.50it/s]
  6%|███████▌                                                                                                                             | 3965/69795 [00:00<00:15, 4156.31it/s]
  6%|████████▍                                                                                                                            | 4416/69795 [00:01<00:15, 4147.29it/s]
  7%|█████████▎                                                                                                                           | 4879/69795 [00:01<00:15, 4173.76it/s]
  8%|██████████▏                                                                                                                          | 5354/69795 [00:01<00:15, 4225.42it/s]
  8%|███████████                                                                                                                          | 5819/69795 [00:01<00:15, 4233.33it/s]
  9%|███████████▉                                                                                                                         | 6266/69795 [00:01<00:15, 4188.95it/s]
 10%|████████████▊                                                                                                                        | 6720/69795 [00:01<00:15, 4174.83it/s]
 10%|█████████████▋                                                                                                                       | 7186/69795 [00:01<00:14, 4202.09it/s]
 11%|██████████████▌                                                                                                                      | 7635/69795 [00:01<00:14, 4172.95it/s]
 12%|███████████████▍                                                                                                                     | 8124/69795 [00:01<00:14, 4263.32it/s]
 12%|████████████████▎                                                                                                                    | 8581/69795 [00:02<00:14, 4237.66it/s]
 13%|█████████████████▏                                                                                                                   | 9036/69795 [00:02<00:14, 4213.90it/s]
 14%|██████████████████                                                                                                                   | 9501/69795 [00:02<00:14, 4225.54it/s]
 14%|██████████████████▉                                                                                                                  | 9966/69795 [00:02<00:14, 4233.33it/s]
 15%|███████████████████▊                                                                                                                | 10449/69795 [00:02<00:13, 4287.74it/s]
 16%|████████████████████▋                                                                                                               | 10909/69795 [00:02<00:13, 4260.88it/s]
 16%|█████████████████████▍                                                                                                              | 11362/69795 [00:02<00:13, 4227.21it/s]
 17%|██████████████████████▎                                                                                                             | 11818/69795 [00:02<00:13, 4209.75it/s]
 18%|███████████████████████▏                                                                                                            | 12279/69795 [00:02<00:13, 4211.68it/s]
 18%|████████████████████████                                                                                                            | 12729/69795 [00:03<00:13, 4182.41it/s]
 19%|████████████████████████▉                                                                                                           | 13191/69795 [00:03<00:13, 4194.51it/s]
 20%|█████████████████████████▊                                                                                                          | 13651/69795 [00:03<00:13, 4197.86it/s]
 20%|██████████████████████████▋                                                                                                         | 14112/69795 [00:03<00:13, 4203.31it/s]
 21%|███████████████████████████▌                                                                                                        | 14569/69795 [00:03<00:13, 4195.75it/s]
 22%|████████████████████████████▍                                                                                                       | 15017/69795 [00:03<00:13, 4165.07it/s]
 22%|█████████████████████████████▎                                                                                                      | 15476/69795 [00:03<00:13, 4175.35it/s]
 23%|██████████████████████████████▏                                                                                                     | 15965/69795 [00:03<00:12, 4264.42it/s]
 24%|███████████████████████████████                                                                                                     | 16432/69795 [00:03<00:12, 4265.59it/s]
 24%|███████████████████████████████▉                                                                                                    | 16910/69795 [00:04<00:12, 4297.26it/s]
 25%|████████████████████████████████▊                                                                                                   | 17348/69795 [00:04<00:12, 4209.30it/s]
 26%|█████████████████████████████████▋                                                                                                  | 17804/69795 [00:04<00:12, 4197.17it/s]
 26%|██████████████████████████████████▌                                                                                                 | 18274/69795 [00:04<00:12, 4227.02it/s]
 27%|███████████████████████████████████▍                                                                                                | 18723/69795 [00:04<00:12, 4190.49it/s]
 28%|████████████████████████████████████▎                                                                                               | 19205/69795 [00:04<00:11, 4253.51it/s]
 28%|█████████████████████████████████████▏                                                                                              | 19681/69795 [00:04<00:11, 4284.79it/s]
 29%|██████████████████████████████████████▏                                                                                             | 20163/69795 [00:04<00:11, 4321.40it/s]
 30%|███████████████████████████████████████                                                                                             | 20636/69795 [00:04<00:11, 4321.96it/s]
 30%|███████████████████████████████████████▉                                                                                            | 21140/69795 [00:05<00:11, 4407.72it/s]
 31%|████████████████████████████████████████▊                                                                                           | 21608/69795 [00:05<00:11, 4369.45it/s]
 32%|█████████████████████████████████████████▊                                                                                          | 22103/69795 [00:05<00:10, 4416.32it/s]
 32%|██████████████████████████████████████████▋                                                                                         | 22598/69795 [00:05<00:10, 4449.13it/s]
 33%|███████████████████████████████████████████▋                                                                                        | 23092/69795 [00:05<00:10, 4468.91it/s]
 34%|████████████████████████████████████████████▌                                                                                       | 23571/69795 [00:05<00:10, 4438.29it/s]
 34%|█████████████████████████████████████████████▍                                                                                      | 24015/69795 [00:05<00:10, 4328.00it/s]
 35%|██████████████████████████████████████████████▏                                                                                     | 24448/69795 [00:05<00:10, 4217.30it/s]
 36%|███████████████████████████████████████████████                                                                                     | 24870/69795 [00:05<00:10, 4110.03it/s]
 36%|███████████████████████████████████████████████▊                                                                                    | 25298/69795 [00:06<00:10, 4050.51it/s]
 37%|████████████████████████████████████████████████▋                                                                                   | 25728/69795 [00:06<00:10, 4015.83it/s]
 38%|█████████████████████████████████████████████████▌                                                                                  | 26180/69795 [00:06<00:10, 4050.84it/s]
 38%|██████████████████████████████████████████████████▍                                                                                 | 26648/69795 [00:06<00:10, 4119.26it/s]
 39%|███████████████████████████████████████████████████▏                                                                                | 27097/69795 [00:06<00:10, 4114.95it/s]
 39%|████████████████████████████████████████████████████                                                                                | 27527/69795 [00:06<00:10, 4135.75it/s]
 40%|████████████████████████████████████████████████████▊                                                                               | 27941/69795 [00:06<00:10, 4130.32it/s]
 41%|█████████████████████████████████████████████████████▋                                                                              | 28394/69795 [00:06<00:10, 4134.02it/s]
 41%|██████████████████████████████████████████████████████▌                                                                             | 28862/69795 [00:06<00:09, 4179.06it/s]
 42%|███████████████████████████████████████████████████████▍                                                                            | 29315/69795 [00:06<00:09, 4167.69it/s]
 43%|████████████████████████████████████████████████████████▏                                                                           | 29736/69795 [00:07<00:09, 4071.29it/s]
 43%|█████████████████████████████████████████████████████████                                                                           | 30192/69795 [00:07<00:09, 4100.74it/s]
 44%|██████████████████████████████████████████████████████████                                                                          | 30681/69795 [00:07<00:09, 4212.20it/s]
 45%|██████████████████████████████████████████████████████████▉                                                                         | 31157/69795 [00:07<00:09, 4254.34it/s]
 45%|███████████████████████████████████████████████████████████▊                                                                        | 31625/69795 [00:07<00:08, 4261.75it/s]
 46%|████████████████████████████████████████████████████████████▋                                                                       | 32086/69795 [00:07<00:08, 4246.57it/s]
 47%|█████████████████████████████████████████████████████████████▋                                                                      | 32590/69795 [00:07<00:08, 4356.31it/s]
 47%|██████████████████████████████████████████████████████████████▌                                                                     | 33110/69795 [00:07<00:08, 4475.82it/s]
 48%|███████████████████████████████████████████████████████████████▌                                                                    | 33597/69795 [00:07<00:08, 4468.84it/s]
 49%|████████████████████████████████████████████████████████████████▍                                                                   | 34089/69795 [00:08<00:07, 4477.58it/s]
 50%|█████████████████████████████████████████████████████████████████▍                                                                  | 34576/69795 [00:08<00:07, 4470.14it/s]
 50%|██████████████████████████████████████████████████████████████████▍                                                                 | 35096/69795 [00:08<00:07, 4555.08it/s]
 51%|███████████████████████████████████████████████████████████████████▎                                                                | 35613/69795 [00:08<00:07, 4606.90it/s]
 52%|████████████████████████████████████████████████████████████████████▎                                                               | 36100/69795 [00:08<00:07, 4560.56it/s]
 52%|█████████████████████████████████████████████████████████████████████▏                                                              | 36583/69795 [00:08<00:07, 4513.32it/s]
 53%|██████████████████████████████████████████████████████████████████████                                                              | 37064/69795 [00:08<00:07, 4481.09it/s]
 54%|███████████████████████████████████████████████████████████████████████                                                             | 37572/69795 [00:08<00:07, 4531.58it/s]
 55%|████████████████████████████████████████████████████████████████████████                                                            | 38092/69795 [00:08<00:06, 4598.39it/s]
 55%|████████████████████████████████████████████████████████████████████████▉                                                           | 38570/69795 [00:09<00:06, 4530.30it/s]
 56%|█████████████████████████████████████████████████████████████████████████▊                                                          | 39038/69795 [00:09<00:06, 4454.84it/s]
 57%|██████████████████████████████████████████████████████████████████████████▋                                                         | 39509/69795 [00:09<00:06, 4409.95it/s]
 57%|███████████████████████████████████████████████████████████████████████████▋                                                        | 39991/69795 [00:09<00:06, 4408.95it/s]
 58%|████████████████████████████████████████████████████████████████████████████▌                                                       | 40497/69795 [00:09<00:06, 4474.52it/s]
 59%|█████████████████████████████████████████████████████████████████████████████▌                                                      | 40989/69795 [00:09<00:06, 4476.96it/s]
 59%|██████████████████████████████████████████████████████████████████████████████▍                                                     | 41460/69795 [00:09<00:06, 4429.04it/s]
 60%|███████████████████████████████████████████████████████████████████████████████▎                                                    | 41952/69795 [00:09<00:06, 4450.43it/s]
 61%|████████████████████████████████████████████████████████████████████████████████▏                                                   | 42416/69795 [00:09<00:06, 4387.95it/s]
 62%|█████████████████████████████████████████████████████████████████████████████████▏                                                  | 42939/69795 [00:10<00:05, 4505.93it/s]
 62%|██████████████████████████████████████████████████████████████████████████████████▏                                                 | 43454/69795 [00:10<00:05, 4566.89it/s]
 63%|███████████████████████████████████████████████████████████████████████████████████                                                 | 43943/69795 [00:10<00:05, 4537.93it/s]
 64%|████████████████████████████████████████████████████████████████████████████████████                                                | 44440/69795 [00:10<00:05, 4539.76it/s]
 64%|████████████████████████████████████████████████████████████████████████████████████▉                                               | 44894/69795 [00:10<00:05, 4423.09it/s]
 65%|█████████████████████████████████████████████████████████████████████████████████████▊                                              | 45400/69795 [00:10<00:05, 4479.94it/s]
 66%|██████████████████████████████████████████████████████████████████████████████████████▊                                             | 45918/69795 [00:10<00:05, 4558.79it/s]
 67%|███████████████████████████████████████████████████████████████████████████████████████▊                                            | 46440/69795 [00:10<00:05, 4625.72it/s]
 67%|████████████████████████████████████████████████████████████████████████████████████████▊                                           | 46951/69795 [00:10<00:04, 4639.14it/s]
 68%|█████████████████████████████████████████████████████████████████████████████████████████▋                                          | 47425/69795 [00:11<00:04, 4547.49it/s]
 69%|██████████████████████████████████████████████████████████████████████████████████████████▋                                         | 47924/69795 [00:11<00:04, 4552.03it/s]
 69%|███████████████████████████████████████████████████████████████████████████████████████████▌                                        | 48442/69795 [00:11<00:04, 4607.22it/s]
 70%|████████████████████████████████████████████████████████████████████████████████████████████▌                                       | 48975/69795 [00:11<00:04, 4687.00it/s]
 71%|█████████████████████████████████████████████████████████████████████████████████████████████▌                                      | 49480/69795 [00:11<00:04, 4666.02it/s]
 72%|██████████████████████████████████████████████████████████████████████████████████████████████▍                                     | 49947/69795 [00:11<00:04, 4542.64it/s]
 72%|███████████████████████████████████████████████████████████████████████████████████████████████▎                                    | 50406/69795 [00:11<00:04, 4441.08it/s]
 73%|████████████████████████████████████████████████████████████████████████████████████████████████▎                                   | 50902/69795 [00:11<00:04, 4470.82it/s]
 74%|█████████████████████████████████████████████████████████████████████████████████████████████████▏                                  | 51408/69795 [00:11<00:04, 4517.74it/s]
 74%|██████████████████████████████████████████████████████████████████████████████████████████████████▏                                 | 51925/69795 [00:12<00:03, 4580.19it/s]
 75%|███████████████████████████████████████████████████████████████████████████████████████████████████                                 | 52390/69795 [00:12<00:03, 4481.80it/s]
 76%|███████████████████████████████████████████████████████████████████████████████████████████████████▉                                | 52867/69795 [00:12<00:03, 4445.55it/s]
 76%|████████████████████████████████████████████████████████████████████████████████████████████████████▉                               | 53369/69795 [00:12<00:03, 4488.82it/s]
 77%|█████████████████████████████████████████████████████████████████████████████████████████████████████▊                              | 53863/69795 [00:12<00:03, 4496.70it/s]
 78%|██████████████████████████████████████████████████████████████████████████████████████████████████████▊                             | 54335/69795 [00:12<00:03, 4510.92it/s]
 79%|███████████████████████████████████████████████████████████████████████████████████████████████████████▋                            | 54804/69795 [00:12<00:03, 4376.51it/s]
 79%|████████████████████████████████████████████████████████████████████████████████████████████████████████▍                           | 55243/69795 [00:12<00:03, 4268.04it/s]
 80%|█████████████████████████████████████████████████████████████████████████████████████████████████████████▎                          | 55671/69795 [00:12<00:03, 4161.70it/s]
 80%|██████████████████████████████████████████████████████████████████████████████████████████████████████████                          | 56109/69795 [00:12<00:03, 4114.67it/s]
 81%|██████████████████████████████████████████████████████████████████████████████████████████████████████████▉                         | 56531/69795 [00:13<00:03, 4037.86it/s]
 82%|███████████████████████████████████████████████████████████████████████████████████████████████████████████▊                        | 57038/69795 [00:13<00:03, 4217.01it/s]
 82%|████████████████████████████████████████████████████████████████████████████████████████████████████████████▊                       | 57515/69795 [00:13<00:02, 4259.83it/s]
 83%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                      | 57971/69795 [00:13<00:02, 4232.62it/s]
 84%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████▌                     | 58452/69795 [00:13<00:02, 4282.11it/s]
 84%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████▍                    | 58925/69795 [00:13<00:02, 4295.72it/s]
 85%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎                   | 59410/69795 [00:13<00:02, 4337.12it/s]
 86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎                  | 59925/69795 [00:13<00:02, 4448.20it/s]
 87%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                 | 60377/69795 [00:13<00:02, 4353.51it/s]
 87%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████                 | 60823/69795 [00:14<00:02, 4271.12it/s]
 88%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉                | 61300/69795 [00:14<00:01, 4297.74it/s]
 89%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊               | 61773/69795 [00:14<00:01, 4305.75it/s]
 89%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊              | 62261/69795 [00:14<00:01, 4352.57it/s]
 90%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋             | 62760/69795 [00:14<00:01, 4415.44it/s]
 91%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌            | 63219/69795 [00:14<00:01, 4345.57it/s]
 91%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍           | 63693/69795 [00:14<00:01, 4345.30it/s]
 92%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍          | 64180/69795 [00:14<00:01, 4377.57it/s]
 93%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎         | 64656/69795 [00:14<00:01, 4370.51it/s]
 93%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏        | 65144/69795 [00:15<00:01, 4397.87it/s]
 94%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████        | 65595/69795 [00:15<00:00, 4315.57it/s]
 95%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉       | 66065/69795 [00:15<00:00, 4310.37it/s]
 95%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊      | 66556/69795 [00:15<00:00, 4363.97it/s]
 96%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊     | 67058/69795 [00:15<00:00, 4431.70it/s]
 97%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊    | 67562/69795 [00:15<00:00, 4480.79it/s]
 97%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋   | 68016/69795 [00:15<00:00, 4384.01it/s]
 98%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍  | 68460/69795 [00:15<00:00, 4287.50it/s]
 99%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 68945/69795 [00:15<00:00, 4331.66it/s]
 99%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎| 69437/69795 [00:16<00:00, 4381.90it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 69795/69795 [00:16<00:00, 4324.13it/s]

The optic radiation is reconstructed by tracking fibers from the calcarine sulcus (visual cortex V1) to the lateral geniculate nucleus (LGN). We seed from the calcarine sulcus by selecting a region-of-interest (ROI) cube of dimensions 3x3x3 voxels.

# Set a seed region region for tractography.
mask = np.zeros(data.shape[:-1], 'bool')
rad = 3
mask[26-rad:26+rad, 29-rad:29+rad, 31-rad:31+rad] = True
seeds = utils.seeds_from_mask(mask, affine, density=[4, 4, 4])

Local Tracking is used for probabilistic tractography which takes the direction getter along with the stopping criterion and seeds as input.

# Perform tracking using Local Tracking
streamlines_generator = LocalTracking(prob_dg, stopping_criterion, seeds,
                                      affine, step_size=.5)

# Compute streamlines.
streamlines = Streamlines(streamlines_generator)

In order to select only the fibers that enter into the LGN, another ROI is created from a cube of size 5x5x5 voxels. The near_roi command is used to find the fibers that traverse through this ROI.

# Set a mask for the lateral geniculate nucleus (LGN)
mask_lgn = np.zeros(data.shape[:-1], 'bool')
rad = 5
mask_lgn[35-rad:35+rad, 42-rad:42+rad, 28-rad:28+rad] = True

# Select all the fibers that enter the LGN and discard all others
filtered_fibers2 = utils.near_roi(streamlines, affine, mask_lgn, tol=1.8)

sfil = []
for i in range(len(streamlines)):
    if filtered_fibers2[i]:
        sfil.append(streamlines[i])
streamlines = Streamlines(sfil)

Inspired by [Rodrigues2010], a lookup-table is created, containing rotated versions of the fiber propagation kernel \(P_t\) [DuitsAndFranken2011] rotated over a discrete set of orientations. See the Crossing-preserving contextual enhancement example for more details regarding the kernel. In order to ensure rotationally invariant processing, the discrete orientations are required to be equally distributed over a sphere. By default, a sphere with 100 directions is obtained from electrostatic repulsion in DIPY.

# Compute lookup table
D33 = 1.0
D44 = 0.02
t = 1
k = EnhancementKernel(D33, D44, t)

The FBC measures are now computed, taking the tractography results and the lookup tables as input.

# Apply FBC measures
fbc = FBCMeasures(streamlines, k)

After calculating the FBC measures, a threshold can be chosen on the relative FBC (RFBC) in order to remove spurious fibers. Recall that the relative FBC (RFBC) is calculated by the minimum of the moving average LFBC along the fiber. In this example we show the results for threshold 0 (i.e. all fibers are included) and 0.2 (removing the 20 percent most spurious fibers).

# Calculate LFBC for original fibers
fbc_sl_orig, clrs_orig, rfbc_orig = \
  fbc.get_points_rfbc_thresholded(0, emphasis=0.01)

# Apply a threshold on the RFBC to remove spurious fibers
fbc_sl_thres, clrs_thres, rfbc_thres = \
  fbc.get_points_rfbc_thresholded(0.125, emphasis=0.01)

The results of FBC measures are visualized, showing the original fibers colored by LFBC (see optic_radiation_before_cleaning), and the fibers after the cleaning procedure via RFBC thresholding (see optic_radiation_after_cleaning).

# Create scene
scene = window.Scene()

# Original lines colored by LFBC
lineactor = actor.line(fbc_sl_orig, np.vstack(clrs_orig), linewidth=0.2)
scene.add(lineactor)

# Horizontal (axial) slice of T1 data
vol_actor1 = actor.slicer(t1_data, affine=affine)
vol_actor1.display(z=20)
scene.add(vol_actor1)

# Vertical (sagittal) slice of T1 data
vol_actor2 = actor.slicer(t1_data, affine=affine)
vol_actor2.display(x=35)
scene.add(vol_actor2)

# Show original fibers
scene.set_camera(position=(-264, 285, 155),
                 focal_point=(0, -14, 9),
                 view_up=(0, 0, 1))
window.record(scene, n_frames=1, out_path='OR_before.png', size=(900, 900))
if interactive:
    window.show(scene)

# Show thresholded fibers
scene.rm(lineactor)
scene.add(actor.line(fbc_sl_thres, np.vstack(clrs_thres), linewidth=0.2))
window.record(scene, n_frames=1, out_path='OR_after.png', size=(900, 900))
if interactive:
    window.show(scene)
  • fiber to bundle coherence
  • fiber to bundle coherence

The optic radiation obtained through probabilistic tractography colored by local fiber to bundle coherence.

The tractography result is cleaned (shown in bottom) by removing fibers with a relative FBC (RFBC) lower than the threshold \(\tau = 0.2\).

Acknowledgments#

The techniques are developed in close collaboration with Pauly Ossenblok of the Academic Center of Epileptology Kempenhaeghe & Maastricht UMC+.

References#

[Meesters2016]

S. Meesters, G. Sanguinetti, E. Garyfallidis, J. Portegies, P. Ossenblok, R. Duits. (2016) Cleaning output of tractography via fiber to bundle coherence, a new open source implementation. Human Brain Mapping Conference 2016.

[Portegies2015] (1,2)

J. Portegies, R. Fick, G. Sanguinetti, S. Meesters, G.Girard, and R. Duits. (2015) Improving Fiber Alignment in HARDI by Combining Contextual PDE flow with Constrained Spherical Deconvolution. PLoS One.

[DuitsAndFranken2011]

R. Duits and E. Franken (2011) Left-invariant diffusions on the space of positions and orientations and their application to crossing-preserving smoothing of HARDI images. International Journal of Computer Vision, 92:231-264.

[Rodrigues2010]

P. Rodrigues, R. Duits, B. Romeny, A. Vilanova (2010). Accelerated Diffusion Operators for Enhancing DW-MRI. Eurographics Workshop on Visual Computing for Biology and Medicine. The Eurographics Association.

Total running time of the script: (2 minutes 26.232 seconds)

Gallery generated by Sphinx-Gallery