diff --git a/doc/examples/tracking_bootstrap_peaks.py b/doc/examples/tracking_bootstrap_peaks.py index 9c61ea7503..4f5aee0a2f 100644 --- a/doc/examples/tracking_bootstrap_peaks.py +++ b/doc/examples/tracking_bootstrap_peaks.py @@ -5,52 +5,44 @@ 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). +probabilistic tracking, as described in Berman et al. (2008) [Berman2008]_ a +nd the closest peak direction getter (a type of deterministic tracking). (Amirbekian, PhD thesis, 2016) -Let's load the necessary modules for executing this tutorial. +This example is an extension of the :ref:`example_tracking_introduction_eudx` +example. Let's start by loading the necessary modules for executing this +tutorial. """ +# Enables/disables interactive visualization +interactive = False + 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. -""" +from dipy.tracking import utils +from dipy.tracking.local import (ThresholdTissueClassifier, LocalTracking) +from dipy.viz import window, actor, colormap, has_fury 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 +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 +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 +classifier. """ from dipy.reconst.shm import CsaOdfModel @@ -64,6 +56,7 @@ """ Example #1: Bootstrap direction getter with CSD Model +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from dipy.direction import BootDirectionGetter @@ -76,26 +69,29 @@ 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)) +save_trk("tractogram_bootstrap_dg.trk", streamlines, affine, labels.shape) + +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_bootstrap_dg.png', size=(800, 800)) + if interactive: + window.show(r) """ -.. figure:: bootstrap_dg_CSD.png +.. figure:: tractogram_bootstrap_dg.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. +same set of streamlines. """ -save_trk("bootstrap_dg_CSD.trk", streamlines, affine, labels.shape) - """ Example #2: Closest peak direction getter with CSD Model +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from dipy.direction import ClosestPeakDirectionGetter @@ -107,12 +103,18 @@ 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)) +save_trk("closest_peak_dg_CSD.trk", streamlines, affine, labels.shape) + +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_closest_peak_dg.png', + size=(800, 800)) + if interactive: + window.show(r) """ -.. figure:: closest_peak_dg_CSD.png +.. figure:: tractogram_closest_peak_dg.png :align: center **Corpus Callosum Closest Peak Deterministic Direction Getter** @@ -120,13 +122,12 @@ 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) """ +References +---------- .. [Berman2008] Berman, J. et al., Probabilistic streamline q-ball tractography using the residual bootstrap, NeuroImage, vol 39, no 1, 2008 diff --git a/doc/examples/deterministic_fiber_tracking.py b/doc/examples/tracking_deterministic.py similarity index 70% rename from doc/examples/deterministic_fiber_tracking.py rename to doc/examples/tracking_deterministic.py index 6a0d9e3eb0..71c2675425 100644 --- a/doc/examples/deterministic_fiber_tracking.py +++ b/doc/examples/tracking_deterministic.py @@ -17,16 +17,22 @@ 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 -:ref:`example_probabilistic_fiber_tracking` example. We begin by loading the -data and fitting a Constrained Spherical Deconvolution (CSD) reconstruction -model. +This example is an extension of the :ref:`example_tracking_probabilistic` +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 (tissue classifier). """ +# Enables/disables interactive visualization +interactive = False + from dipy.data import read_stanford_labels from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel +from dipy.reconst.shm import CsaOdfModel from dipy.tracking import utils from dipy.tracking.local import (ThresholdTissueClassifier, LocalTracking) +from dipy.viz import window, actor, colormap, has_fury hardi_img, gtab, labels_img = read_stanford_labels() data = hardi_img.get_data() @@ -40,19 +46,9 @@ csd_model = ConstrainedSphericalDeconvModel(gtab, None, sh_order=6) csd_fit = csd_model.fit(data, mask=white_matter) -""" -We use the fractional anisotropy (FA) of the DTI model to build a tissue -classifier. -""" - -import dipy.reconst.dti as dti -from dipy.reconst.dti import fractional_anisotropy - -tensor_model = dti.TensorModel(gtab) -tenfit = tensor_model.fit(data, mask=white_matter) - -FA = fractional_anisotropy(tenfit.evals) -classifier = ThresholdTissueClassifier(FA, .2) +csa_model = CsaOdfModel(gtab, sh_order=6) +gfa = csa_model.fit(data, mask=white_matter).gfa +classifier = ThresholdTissueClassifier(gfa, .25) """ The Fiber Orientation Distribution (FOD) of the CSD model estimates the @@ -74,5 +70,24 @@ streamline_generator = LocalTracking(detmax_dg, classifier, seeds, affine, step_size=.5) streamlines = Streamlines(streamline_generator) -save_trk("deterministic_maximum_shm_coeff.trk", streamlines, affine, +save_trk("'tractogram_deterministic_dg.trk", streamlines, affine, labels.shape) + +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_deterministic_dg.png', + size=(800, 800)) + if interactive: + window.show(r) + +""" +.. figure:: tractogram_deterministic_dg.png + :align: center + + **Corpus Callosum using deterministic maximum direction getter** +""" +""" +.. include:: ../links_names.inc + +""" diff --git a/doc/examples/tracking_eudx_odf.py b/doc/examples/tracking_eudx_odf.py deleted file mode 100644 index 33e0b46d44..0000000000 --- a/doc/examples/tracking_eudx_odf.py +++ /dev/null @@ -1,119 +0,0 @@ -""" - -============================================= -Deterministic Tracking with EuDX on ODF Peaks -============================================= - -.. NOTE:: - DIPY has updated tools for fiber tracking. Our new machinery for fiber - tracking is featured in the example titled Introduction to Basic Tracking. - The tools demonstrated in this example are no longer actively being - maintained and will likely be deprecated at some point. - -In this example we do deterministic fiber tracking on fields of ODF peaks. EuDX -[Garyfallidis12]_ will be used for this. - -This example requires importing example `reconst_csa.py` in order to run. EuDX -was primarily made with cpu efficiency in mind. The main idea can be used with -any model that is a child of OdfModel. - -""" - -from reconst_csa import csapeaks, sphere -import numpy as np - -""" -This time we will not use FA as input to EuDX but we will use GFA -(generalized FA), which is more suited for ODF functions. Tracking will stop -when GFA is less than 0.2. -""" - -from dipy.tracking.eudx import EuDX -from dipy.tracking.streamline import Streamlines - -eu = EuDX(csapeaks.gfa, - csapeaks.peak_indices[..., 0], - seeds=10000, - odf_vertices=sphere.vertices, - a_low=0.2) - -csa_streamlines = Streamlines(eu) - -""" -Now that we have our streamlines in memory we can save the results on the disk. -For this purpose we can use the TrackVis format (``*.trk``). First, we need to -import the ``save_trk`` function. -""" - -from dipy.io.streamline import save_trk - -""" -Save the streamlines. -""" - -csa_sl_fname = 'csa_streamline.trk' - -save_trk(csa_sl_fname, csa_streamlines, - affine=np.eye(4), - vox_size=np.array([2., 2., 2.]), - shape=csapeaks.gfa.shape[:3]) - -""" -Visualize the streamlines with `dipy.viz` module (python vtk is required). -""" - -from dipy.viz import window, actor, colormap as cmap - -# Enables/disables interactive visualization -interactive = False - -ren = window.Renderer() - -ren.add(actor.line(csa_streamlines, cmap.line_colors(csa_streamlines))) - -print('Saving illustration as tensor_tracks.png') - -window.record(ren, out_path='csa_tracking.png', size=(600, 600)) -if interactive: - window.show(ren) - -""" -.. figure:: csa_tracking.png - :align: center - - Deterministic streamlines with EuDX on ODF peaks field modulated by GFA. - -It is also possible to use EuDX with multiple ODF peaks, which is very helpful -when tracking in crossing areas. -""" - -eu = EuDX(csapeaks.peak_values, - csapeaks.peak_indices, - seeds=10000, - odf_vertices=sphere.vertices, - ang_thr=20., - a_low=0.6) - -csa_streamlines_mult_peaks = Streamlines(eu) - -window.clear(ren) - -ren.add(actor.line(csa_streamlines_mult_peaks, - cmap.line_colors(csa_streamlines_mult_peaks))) - -print('Saving illustration as csa_tracking_mpeaks.png') - -window.record(ren, out_path='csa_tracking_mpeaks.png', size=(600, 600)) -if interactive: - window.show(ren) - -""" -.. figure:: csa_tracking_mpeaks.png - :align: center - - Deterministic streamlines with EuDX on multiple ODF peaks. - -.. [Garyfallidis12] Garyfallidis E., "Towards an accurate brain tractography", PhD thesis, University of Cambridge, 2012. - -.. include:: ../links_names.inc -""" diff --git a/doc/examples/tracking_eudx_tensor.py b/doc/examples/tracking_eudx_tensor.py deleted file mode 100644 index af37533e55..0000000000 --- a/doc/examples/tracking_eudx_tensor.py +++ /dev/null @@ -1,152 +0,0 @@ -""" - -================================================= -Deterministic Tracking with EuDX on Tensor Fields -================================================= - -In this example we do deterministic fiber tracking on Tensor fields with EuDX -[Garyfallidis12]_. - -This example requires to import example `reconst_dti.py` to run. EuDX was -primarily made with cpu efficiency in mind. Therefore, it should be useful to -give you a quick overview of your reconstruction results with the help of -tracking. - -""" - -import os -import numpy as np -import nibabel as nib - -if not os.path.exists('tensor_fa.nii.gz'): - import reconst_dti - -""" -EuDX will use the directions (eigen vectors) of the Tensors to propagate -streamlines from voxel to voxel and fractional anisotropy to stop tracking. -""" - -fa_img = nib.load('tensor_fa.nii.gz') -FA = fa_img.get_data() -evecs_img = nib.load('tensor_evecs.nii.gz') -evecs = evecs_img.get_data() - -""" -In the background of the image the fitting will not be accurate because there all -measured signal is mostly noise and possibly we will find FA values with nans -(not a number). We can easily remove these in the following way. -""" - -FA[np.isnan(FA)] = 0 - -""" -EuDX takes as input discretized voxel directions on a unit sphere. Therefore, -it is necessary to discretize the eigen vectors before feeding them in EuDX. - -For the discretization procedure we use an evenly distributed sphere of 724 -points which we can access using the get_sphere function. -""" - -from dipy.data import get_sphere - -sphere = get_sphere('symmetric724') - -""" -We use quantize_evecs (evecs here stands for eigen vectors) to apply the -discretization. -""" - -from dipy.reconst.dti import quantize_evecs - -peak_indices = quantize_evecs(evecs, sphere.vertices) - -""" -EuDX is the fiber tracking algorithm that we use in this example. -The most important parameters are the first one which represents the -magnitude of the peak of a scalar anisotropic function, the -second which represents the indices of the discretized directions of -the peaks and odf_vertices are the vertices of the input sphere. -""" - -from dipy.tracking.eudx import EuDX -from dipy.tracking.streamline import Streamlines - -eu = EuDX(FA.astype('f8'), peak_indices, seeds=50000, - odf_vertices=sphere.vertices, a_low=0.2) - -tensor_streamlines = Streamlines(eu) - -""" -We can now save the results in the disk. For this purpose we can use the -TrackVis format (``*.trk``). First, we need to import ``save_trk`` function. -""" - -from dipy.io.streamline import save_trk - -""" -Save the streamlines. -""" - -ten_sl_fname = 'tensor_streamlines.trk' - -save_trk(ten_sl_fname, tensor_streamlines, - affine=np.eye(4), - vox_size=fa_img.header.get_zooms()[:3], - shape=FA.shape) - -""" -If you don't want to use Trackvis to visualize the file you can use our -lightweight `dipy.viz` module. -""" - -try: - from dipy.viz import window, actor -except ImportError: - raise ImportError('Python fury module is not installed') - import sys - sys.exit() - -""" -Create a scene. -""" - -ren = window.Renderer() - -""" -Every streamline will be coloured according to its orientation -""" - -from dipy.viz import colormap as cmap - -""" -`actor.line` creates a streamline actor for streamline visualization -and `ren.add` adds this actor to the scene -""" - -ren.add(actor.streamtube(tensor_streamlines, - cmap.line_colors(tensor_streamlines))) - -print('Saving illustration as tensor_tracks.png') - -ren.SetBackground(1, 1, 1) -window.record(ren, out_path='tensor_tracks.png', size=(600, 600)) -# Enables/disables interactive visualization -interactive = False -if interactive: - window.show(ren) - -""" -.. figure:: tensor_tracks.png - :align: center - - Deterministic streamlines with EuDX on a Tensor Field. - -References ----------- - -.. [Garyfallidis12] Garyfallidis E., "Towards an accurate brain tractography", - PhD thesis, University of Cambridge, 2012. - -.. include:: ../links_names.inc - -""" diff --git a/doc/examples/introduction_to_basic_tracking.py b/doc/examples/tracking_introduction_eudx.py similarity index 51% rename from doc/examples/introduction_to_basic_tracking.py rename to doc/examples/tracking_introduction_eudx.py index dc6cf4b253..a2301315bb 100644 --- a/doc/examples/introduction_to_basic_tracking.py +++ b/doc/examples/tracking_introduction_eudx.py @@ -27,6 +27,9 @@ to your computer. """ +# Enables/disables interactive visualization +interactive = False + from dipy.data import read_stanford_labels hardi_img, gtab, labels_img = read_stanford_labels() @@ -49,7 +52,8 @@ Orientation Distribution Function (ODF) at each voxel. The ODF is the distribution of water diffusion as a function of direction. The peaks of an ODF are good estimates for the orientation of tract segments at a point in the -image. +image. Here, we use ``peaks_from_model`` to fit the data and calculated the +fiber directions in all voxels of the white matter. """ from dipy.reconst.shm import CsaOdfModel @@ -62,18 +66,69 @@ min_separation_angle=45, mask=white_matter) +""" +For quality assurance we can also visualize a slice from the direction field +which we will use as the basis to perform the tracking. The visualization will +be done using the ``fury`` python package +""" + +from dipy.viz import window, actor, has_fury + +if has_fury: + ren = window.Renderer() + ren.add(actor.peak_slicer(csa_peaks.peak_dirs, + csa_peaks.peak_values, + colors=None)) + + window.record(ren, out_path='csa_direction_field.png', size=(900, 900)) + + if interactive: + window.show(ren, size=(800, 800)) + +""" +.. figure:: csa_direction_field.png + :align: center + + **Direction Field (peaks)** +""" + """ 2. Next we need some way of restricting the fiber tracking to areas with good directionality information. We've already created the white matter mask, but we can go a step further and restrict fiber tracking to those areas where the ODF shows significant restricted diffusion by thresholding on -the general fractional anisotropy (GFA). +the generalized fractional anisotropy (GFA). """ from dipy.tracking.local import ThresholdTissueClassifier classifier = ThresholdTissueClassifier(csa_peaks.gfa, .25) +""" +Again, for quality assurance we can also visualize a slice the GFA and the +resulting tracking mask. +""" + +import matplotlib.pyplot as plt + +sli = csa_peaks.gfa.shape[2] // 2 +plt.figure('GFA') +plt.subplot(1, 2, 1).set_axis_off() +plt.imshow(csa_peaks.gfa[:, :, sli].T, cmap='gray', origin='lower') + +plt.subplot(1, 2, 2).set_axis_off() +plt.imshow((csa_peaks.gfa[:, :, sli] > 0.25).T, cmap='gray', origin='lower') + +plt.savefig('gfa_tracking_mask.png') + +""" +.. figure:: gfa_tracking_mask.png + :align: center + + An example of tracking mask derived from the generalized fractional + anisotropy (GFA). +""" + """ 3. Before we can begin tracking is to specify where to "seed" (begin) the fiber tracking. Generally, the seeds chosen will depend on the pathways one is @@ -86,140 +141,73 @@ from dipy.tracking import utils import numpy as np -seed_mask = labels == 2 +seed_mask = (labels == 2) seeds = utils.seeds_from_mask(seed_mask, density=[2, 2, 2], affine=np.eye(4)) """ -Finally, we can bring it all together using ``LocalTracking``. We will then -display the resulting streamlines using the ``dipy.viz`` package. +Finally, we can bring it all together using ``LocalTracking``, performing Using +the EuDX algorithm [Garyfallidis12]_. ``EuDX`` [Garyfallidis12]_ is a fast +algorithm that we use here to generate streamlines. This algorithm is what is +used here and the default option when providing the output of peaks directly +in LocalTracking. """ from dipy.tracking.local import LocalTracking -from dipy.viz import window, actor, colormap as cmap, have_fury from dipy.tracking.streamline import Streamlines -# Enables/disables interactive visualization -interactive = False - # Initialization of LocalTracking. The computation happens in the next step. streamlines_generator = LocalTracking(csa_peaks, classifier, seeds, affine=np.eye(4), step_size=.5) - # Generate streamlines object streamlines = Streamlines(streamlines_generator) -# Prepare the display objects. -color = cmap.line_colors(streamlines) +""" +We will then display the resulting streamlines using the ``fury`` +python package. +""" + +from dipy.viz import colormap -if have_fury: - streamlines_actor = actor.line(streamlines, cmap.line_colors(streamlines)) +if has_fury: + # Prepare the display objects. + color = colormap.line_colors(streamlines) + + streamlines_actor = actor.line(streamlines, + colormap.line_colors(streamlines)) # Create the 3D display. r = window.Renderer() r.add(streamlines_actor) # Save still images for this static example. Or for interactivity use - window.record(r, n_frames=1, out_path='deterministic.png', size=(800, 800)) + window.record(r, out_path='tractogram_EuDX.png', size=(800, 800)) if interactive: window.show(r) """ -.. figure:: deterministic.png +.. figure:: tractogram_EuDX.png :align: center - **Corpus Callosum Deterministic** + **Corpus Callosum using EuDx** -We've created a deterministic set of streamlines, so called because if you -repeat the fiber tracking (keeping all the 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. +We've created a deterministic set of streamlines using the EuDX algorithm. This +is so called deterministic because if you repeat the fiber tracking (keeping +all the 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. """ from dipy.io.streamline import save_trk -save_trk("CSA_detr.trk", streamlines, affine, - shape=labels.shape, - vox_size=labels_img.header.get_zooms()) -""" -Next let's try some probabilistic fiber tracking. For this, we'll be using the -Constrained Spherical Deconvolution (CSD) Model. 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). In order to perform probabilistic -fiber tracking, we pick a fiber from the FOD at random at each new location -along the streamline. Note: one could use this model to perform deterministic -fiber tracking by always tracking along the directions that have the most -fibers. - -Let's begin probabilistic fiber tracking by fitting the data to the CSD model. -""" - -from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel, - auto_response) - -response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7) -csd_model = ConstrainedSphericalDeconvModel(gtab, response, sh_order=6) -csd_fit = csd_model.fit(data, mask=white_matter) - -""" -Next we'll need to make a ``ProbabilisticDirectionGetter``. Because the CSD -model represents the FOD using the spherical harmonic basis, we can use the -``from_shcoeff`` method to create the direction getter. This direction getter -will randomly sample directions from the FOD each time the tracking algorithm -needs to take another step. -""" - -from dipy.direction import ProbabilisticDirectionGetter - -prob_dg = ProbabilisticDirectionGetter.from_shcoeff(csd_fit.shm_coeff, - max_angle=30., - sphere=default_sphere) - -""" -As with deterministic tracking, we'll need to use a tissue classifier to -restrict the tracking to the white matter of the brain. One might be tempted -to use the GFA of the CSD FODs to build a tissue classifier, however the GFA -values of these FODs don't classify gray matter and white matter well. We will -therefore use the GFA from the CSA model which we fit for the first section of -this example. Alternatively, one could fit a ``TensorModel`` to the data and use -the fractional anisotropy (FA) to build a tissue classifier. -""" - -classifier = ThresholdTissueClassifier(csa_peaks.gfa, .25) +save_trk("tractogram_EuDX.trk", streamlines, affine, shape=labels.shape, + vox_size=labels_img.header.get_zooms()) """ -Next we can pass this direction getter, along with the ``classifier`` and -``seeds``, to ``LocalTracking`` to get a probabilistic model of the corpus -callosum. -""" - -streamlines_generator = LocalTracking(prob_dg, classifier, seeds, - affine=np.eye(4), step_size=.5, - max_cross=1) - -# Generate streamlines object. -streamlines = Streamlines(streamlines_generator) +References +---------- +.. [Garyfallidis12] Garyfallidis E., "Towards an accurate brain tractography", +PhD thesis, University of Cambridge, 2012. -if have_fury: - streamlines_actor = actor.line(streamlines, cmap.line_colors(streamlines)) - - # Create the 3D display. - r = window.Renderer() - r.add(streamlines_actor) +.. include:: ../links_names.inc - # Save still images for this static example. - window.record(r, n_frames=1, out_path='probabilistic.png', size=(800, 800)) - if interactive: - window.show(r) - -""" -.. figure:: probabilistic.png - :align: center - - Corpus callosum probabilistic tracking. """ - -save_trk("CSD_prob.trk", streamlines, affine, - shape=labels.shape, - vox_size=labels_img.header.get_zooms()) diff --git a/doc/examples/particle_filtering_fiber_tracking.py b/doc/examples/tracking_pft.py similarity index 80% rename from doc/examples/particle_filtering_fiber_tracking.py rename to doc/examples/tracking_pft.py index 8a775e466e..19807670e7 100644 --- a/doc/examples/particle_filtering_fiber_tracking.py +++ b/doc/examples/tracking_pft.py @@ -16,12 +16,15 @@ PFT finds an alternative streamline segment whenever the tissue classifier returns a position classified as 'INVALIDPOINT'. -This example is an extension of the -:ref:`probabilistic_fiber_tracking` example. We begin by loading the +This example is an extension of :ref:`example_tracking_probabilistic` and +:ref:`example_tracking_tissue_classifier` examples. We begin by loading the data, fitting a Constrained Spherical Deconvolution (CSD) reconstruction -model and creating the probabilistic direction getter. +model, creating the probabilistic direction getter and defining the seeds. """ +# Enables/disables interactive visualization +interactive = False + import numpy as np from dipy.data import (read_stanford_labels, default_sphere, @@ -33,10 +36,7 @@ from dipy.tracking.local import LocalTracking, ParticleFilteringTracking from dipy.tracking.streamline import Streamlines from dipy.tracking import utils -from dipy.viz import window, actor, colormap as cmap - - -renderer = window.Renderer() +from dipy.viz import window, actor, colormap, has_fury img_pve_csf, img_pve_gm, img_pve_wm = read_stanford_pve_maps() hardi_img, gtab, labels_img = read_stanford_labels() @@ -54,6 +54,9 @@ max_angle=20., sphere=default_sphere) +seed_mask = (labels == 2) +seed_mask[img_pve_wm.get_data() < 0.5] = 0 +seeds = utils.seeds_from_mask(seed_mask, density=2, affine=affine) """ CMC/ACT Tissue Classifiers @@ -70,7 +73,7 @@ from dipy.tracking.local import CmcTissueClassifier -voxel_size = np.average(img_pve_wm.get_header()['pixdim'][1:4]) +voxel_size = np.average(img_pve_wm.header['pixdim'][1:4]) step_size = 0.2 cmc_classifier = CmcTissueClassifier.from_pve(img_pve_wm.get_data(), @@ -79,11 +82,6 @@ step_size=step_size, average_voxel_size=voxel_size) -# seeds are place in voxel of the corpus callosum containing only white matter -seed_mask = labels == 2 -seed_mask[img_pve_wm.get_data() < 0.5] = 0 -seeds = utils.seeds_from_mask(seed_mask, density=2, affine=affine) - # Particle Filtering Tractography pft_streamline_generator = ParticleFilteringTracking(dg, cmc_classifier, @@ -96,19 +94,22 @@ pft_front_tracking_dist=1, particle_count=15, return_all=False) - streamlines = Streamlines(pft_streamline_generator) -save_trk("pft_streamline.trk", streamlines, affine, shape) +save_trk("tractogram_pft.trk", streamlines, affine, shape) -renderer.clear() -renderer.add(actor.line(streamlines, cmap.line_colors(streamlines))) -window.record(renderer, out_path='pft_streamlines.png', size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_pft.png', + size=(800, 800)) + if interactive: + window.show(r) """ -.. figure:: pft_streamlines.png +.. figure:: tractogram_pft.png :align: center - **Particle Filtering Tractography** + **Corpus Callosum using particle filtering tractography** """ # Local Probabilistic Tractography @@ -121,18 +122,21 @@ maxlen=1000, return_all=False) streamlines = Streamlines(prob_streamline_generator) -save_trk("probabilistic_streamlines.trk", streamlines, affine, shape) +save_trk("tractogram_probabilistic_cmc.trk", streamlines, affine, shape) -renderer.clear() -renderer.add(actor.line(streamlines, cmap.line_colors(streamlines))) -window.record(renderer, out_path='probabilistic_streamlines.png', - size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_probabilistic_cmc.png', + size=(800, 800)) + if interactive: + window.show(r) """ -.. figure:: probabilistic_streamlines.png +.. figure:: tractogram_probabilistic_cmc.png :align: center - **Probabilistic Tractography** + **Corpus Callosum using probabilistic tractography** """ """ @@ -146,4 +150,6 @@ Anatomically-constrained tractography: Improved diffusion MRI streamlines tractography through effective use of anatomical information. NeuroImage, 63(3), 1924-1938, 2012. + +.. include:: ../links_names.inc """ diff --git a/doc/examples/probabilistic_fiber_tracking.py b/doc/examples/tracking_probabilistic.py similarity index 68% rename from doc/examples/probabilistic_fiber_tracking.py rename to doc/examples/tracking_probabilistic.py index 6f62158424..d0587edb7b 100644 --- a/doc/examples/probabilistic_fiber_tracking.py +++ b/doc/examples/tracking_probabilistic.py @@ -14,23 +14,27 @@ tracking directions are restricted to discrete numbers of well distributed points on a sphere. -This example is an extension of the :ref:`intro_basic_tracking` example. We'll -begin by repeating a few steps from that example, loading the data and fitting -a Constrained Spherical Deconvolution (CSD) model. +This example is an extension of the :ref:`example_tracking_introduction_eudx` +example. We'll begin by repeating a few steps from that example, loading the +data and fitting a Constrained Spherical Deconvolution (CSD) model. """ +# Enables/disables interactive visualization +interactive = False + from dipy.data import read_stanford_labels from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel from dipy.tracking import utils from dipy.tracking.local import (ThresholdTissueClassifier, LocalTracking) from dipy.tracking.streamline import Streamlines +from dipy.viz import window, actor, colormap, has_fury 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 +seed_mask = (labels == 2) white_matter = (labels == 1) | (labels == 2) seeds = utils.seeds_from_mask(seed_mask, density=1, affine=affine) @@ -69,8 +73,22 @@ streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5) streamlines = Streamlines(streamline_generator) -save_trk("probabilistic_small_sphere.trk", streamlines, affine, labels.shape) +save_trk("tractogram_probabilistic_dg_pmf.trk", streamlines, affine, + labels.shape) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_probabilistic_dg_pmf.png', + size=(800, 800)) + if interactive: + window.show(r) +""" +.. figure:: tractogram_probabilistic_dg_pmf.png + :align: center + + **Corpus Callosum using probabilistic direction getter from PMF** +""" """ One disadvantage of using a discrete PMF to represent possible tracking directions is that it tends to take up a lot of memory (RAM). The size of the @@ -79,9 +97,9 @@ the data is ``(81, 106, 76)`` and ``small_sphere`` has 181 directions so the FOD is ``(81, 106, 76, 181)``. One way to avoid sampling the PMF and holding it in memory is to build the direction getter directly from the spherical harmonic -representation of the FOD. By using this approach, we can also use a larger -sphere, like ``default_sphere`` which has 362 directions on the hemisphere, -without having to worry about memory limitations. +(SH) representation of the FOD. By using this approach, we can also use a +larger sphere, like ``default_sphere`` which has 362 directions on the +hemisphere, without having to worry about memory limitations. """ from dipy.data import default_sphere @@ -92,8 +110,22 @@ streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5) streamlines = Streamlines(streamline_generator) -save_trk("probabilistic_shm_coeff.trk", streamlines, affine, labels.shape) +save_trk("tractogram_probabilistic_dg_sh.trk", streamlines, affine, + labels.shape) + +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_probabilistic_dg_sh.png', + size=(800, 800)) + if interactive: + window.show(r) +""" +.. figure:: tractogram_probabilistic_dg_sh.png + :align: center + **Corpus Callosum using probabilistic direction getter from SH** +""" """ Not all model fits have the ``shm_coeff`` attribute because not all models use this basis to represent the data internally. However we can fit the ODF of any @@ -105,10 +137,30 @@ peaks = peaks_from_model(csd_model, data, default_sphere, .5, 25, mask=white_matter, return_sh=True, parallel=True) fod_coeff = peaks.shm_coeff + prob_dg = ProbabilisticDirectionGetter.from_shcoeff(fod_coeff, max_angle=30., sphere=default_sphere) streamline_generator = LocalTracking(prob_dg, classifier, seeds, affine, step_size=.5) streamlines = Streamlines(streamline_generator) -save_trk("probabilistic_peaks_from_model.trk", streamlines, affine, +save_trk("tractogram_probabilistic_dg_sh_pfm.trk", streamlines, affine, labels.shape) + +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_probabilistic_dg_sh_pfm.png', + size=(800, 800)) + if interactive: + window.show(r) +""" +.. figure:: tractogram_probabilistic_dg_sh_pfm.png + :align: center + + **Corpus Callosum using probabilistic direction getter from SH ( + peaks_from_model)** +""" +""" +.. include:: ../links_names.inc + +""" diff --git a/doc/examples/tracking_quick_start.py b/doc/examples/tracking_quick_start.py deleted file mode 100644 index 11d3e68a5d..0000000000 --- a/doc/examples/tracking_quick_start.py +++ /dev/null @@ -1,203 +0,0 @@ -""" -==================== -Tracking Quick Start -==================== - -This example shows how to perform fast fiber tracking using DIPY_ -[Garyfallidis12]_. - -We will use Constrained Spherical Deconvolution (CSD) [Tournier07]_ for local -reconstruction and then generate deterministic streamlines using the fiber -directions (peaks) from CSD and fractional anisotropic (FA) from DTI as a -stopping criteria for the tracking. - -Let's load the necessary modules. -""" - -import numpy as np -from dipy.tracking.local import LocalTracking, ThresholdTissueClassifier -from dipy.tracking.utils import random_seeds_from_mask -from dipy.reconst.dti import TensorModel -from dipy.reconst.csdeconv import (ConstrainedSphericalDeconvModel, - auto_response) -from dipy.direction import peaks_from_model -from dipy.data import fetch_stanford_hardi, read_stanford_hardi, get_sphere -from dipy.segment.mask import median_otsu -from dipy.viz import actor, window -from dipy.io.image import save_nifti -from nibabel.streamlines import save as save_trk -from nibabel.streamlines import Tractogram -from dipy.tracking.streamline import Streamlines - -""" -Enables/disables interactive visualization -""" - -interactive = False - -""" -Load one of the available datasets with 150 gradients on the sphere and 10 b0s -""" - -fetch_stanford_hardi() -img, gtab = read_stanford_hardi() - -data = img.get_data() - -""" -Create a brain mask. This dataset is a bit difficult to segment with the -default ``median_otsu`` parameters (see :ref:`example_brain_extraction_dwi`) -therefore we use here more advanced options. -""" - -maskdata, mask = median_otsu(data, vol_idx=range(10, 50), median_radius=3, - numpass=1, autocrop=False, dilate=2) - -""" -For the Constrained Spherical Deconvolution we need to estimate the response -function (see :ref:`example_reconst_csd`) and create a model. -""" - -response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7) - -csd_model = ConstrainedSphericalDeconvModel(gtab, response) - -""" -Next, we use ``peaks_from_model`` to fit the data and calculated the fiber -directions in all voxels. -""" - -sphere = get_sphere('symmetric724') - -csd_peaks = peaks_from_model(model=csd_model, - data=data, - sphere=sphere, - mask=mask, - relative_peak_threshold=.5, - min_separation_angle=25, - parallel=True) - -""" -For the tracking part, we will use the fiber directions from the ``csd_model`` -but stop tracking in areas where fractional anisotropy is low (< 0.1). -To derive the FA, used here as a stopping criterion, we would need to fit a -tensor model first. Here, we fit the tensor using weighted least squares (WLS). -""" - -tensor_model = TensorModel(gtab, fit_method='WLS') -tensor_fit = tensor_model.fit(data, mask) - -fa = tensor_fit.fa - -""" -In this simple example we can use FA to stop tracking. Here we stop tracking -when FA < 0.1. -""" - -tissue_classifier = ThresholdTissueClassifier(fa, 0.1) - -""" -Now, we need to set starting points for propagating each track. We call those -seeds. Using ``random_seeds_from_mask`` we can select a specific number of -seeds (``seeds_count``) in each voxel where the mask ``fa > 0.3`` is true. -""" - -seeds = random_seeds_from_mask(fa > 0.3, seeds_count=1) - -""" -For quality assurance we can also visualize a slice from the direction field -which we will use as the basis to perform the tracking. -""" - -ren = window.Renderer() -ren.add(actor.peak_slicer(csd_peaks.peak_dirs, - csd_peaks.peak_values, - colors=None)) - -if interactive: - window.show(ren, size=(900, 900)) -else: - window.record(ren, out_path='csd_direction_field.png', size=(900, 900)) - -""" -.. figure:: csd_direction_field.png - :align: center - - **Direction Field (peaks)** - -``EuDX`` [Garyfallidis12]_ is a fast algorithm that we use here to generate -streamlines. This algorithm is what is used here and the default option -when providing the output of peaks directly in LocalTracking. -""" - -streamline_generator = LocalTracking(csd_peaks, tissue_classifier, - seeds, affine=np.eye(4), - step_size=0.5) - -streamlines = Streamlines(streamline_generator) - -""" -The total number of streamlines is shown below. -""" - -print(len(streamlines)) - -""" -To increase the number of streamlines you can change the parameter -``seeds_count`` in ``random_seeds_from_mask``. - -We can visualize the streamlines using ``actor.line`` or ``actor.streamtube``. -""" - -ren.clear() -ren.add(actor.line(streamlines)) - -if interactive: - window.show(ren, size=(900, 900)) -else: - print('Saving illustration as det_streamlines.png') - window.record(ren, out_path='det_streamlines.png', size=(900, 900)) - -""" -.. figure:: det_streamlines.png - :align: center - - **Deterministic streamlines using EuDX (new framework)** - -To learn more about this process you could start playing with the number of -seed points or, even better, specify seeds to be in specific regions of interest -in the brain. - -Save the resulting streamlines in a Trackvis (.trk) format and FA as -Nifti (.nii.gz). -""" - -save_trk(Tractogram(streamlines, affine_to_rasmm=img.affine), - 'det_streamlines.trk') - -save_nifti('fa_map.nii.gz', fa, img.affine) - -""" -In Windows if you get a runtime error about frozen executable please start -your script by adding your code above in a ``main`` function and use:: - - if __name__ == '__main__': - import multiprocessing - multiprocessing.freeze_support() - main() - -References ----------- - -.. [Garyfallidis12] Garyfallidis E., "Towards an accurate brain tractography", - PhD thesis, University of Cambridge, 2012. - -.. [Tournier07] J-D. Tournier, F. Calamante and A. Connelly, "Robust - determination of the fibre orientation distribution in diffusion MRI: - Non-negativity constrained super-resolved spherical deconvolution", - Neuroimage, vol. 35, no. 4, pp. 1459-1472, 2007. - - -.. include:: ../links_names.inc - -""" diff --git a/doc/examples/sfm_tracking.py b/doc/examples/tracking_sfm.py similarity index 84% rename from doc/examples/sfm_tracking.py rename to doc/examples/tracking_sfm.py index 1321ce2e50..bb258c1447 100644 --- a/doc/examples/sfm_tracking.py +++ b/doc/examples/tracking_sfm.py @@ -9,7 +9,10 @@ Model (SFM), described in [Rokem2015]_. This model reconstructs the diffusion signal as a combination of the signals from different fascicles (see also :ref:`sfm-reconst`). - +""" +# Enables/disables interactive visualization +interactive = False +""" To begin, we read the Stanford HARDI data set into memory: """ @@ -63,8 +66,7 @@ relative_peak_threshold=.5, min_separation_angle=25, mask=white_matter, - parallel=True - ) + parallel=True) """ A ThresholdTissueClassifier object is used to segment the data to track only @@ -107,17 +109,14 @@ subject's T1-weighted anatomy: """ -from dipy.viz import window, actor, colormap as cmap +from dipy.viz import window, actor, colormap, has_fury from dipy.data import read_stanford_t1 from dipy.tracking.utils import move_streamlines from numpy.linalg import inv t1 = read_stanford_t1() t1_data = t1.get_data() t1_aff = t1.affine -color = cmap.line_colors(streamlines) - -# Enables/disables interactive visualization -interactive = False +color = colormap.line_colors(streamlines) """ To speed up visualization, we will select a random sub-set of streamlines to @@ -129,27 +128,28 @@ from dipy.tracking.streamline import select_random_set_of_streamlines plot_streamlines = select_random_set_of_streamlines(streamlines, 900) -streamlines_actor = actor.streamtube( - list(move_streamlines(plot_streamlines, inv(t1_aff))), - cmap.line_colors(streamlines), linewidth=0.1) +if has_fury: + streamlines_actor = actor.streamtube( + list(move_streamlines(plot_streamlines, inv(t1_aff))), + colormap.line_colors(streamlines), linewidth=0.1) -vol_actor = actor.slicer(t1_data) + vol_actor = actor.slicer(t1_data) -vol_actor.display(40, None, None) -vol_actor2 = vol_actor.copy() -vol_actor2.display(None, None, 35) + vol_actor.display(40, None, None) + vol_actor2 = vol_actor.copy() + vol_actor2.display(None, None, 35) -ren = window.Renderer() -ren.add(streamlines_actor) -ren.add(vol_actor) -ren.add(vol_actor2) + ren = window.Renderer() + ren.add(streamlines_actor) + ren.add(vol_actor) + ren.add(vol_actor2) -window.record(ren, out_path='sfm_streamlines.png', size=(800, 800)) -if interactive: - window.show(ren) + window.record(ren, out_path='tractogram_sfm.png', size=(800, 800)) + if interactive: + window.show(ren) """ -.. figure:: sfm_streamlines.png +.. figure:: tractogram_sfm.png :align: center **Sparse Fascicle Model tracks** @@ -159,7 +159,7 @@ """ from dipy.io.trackvis import save_trk -save_trk("sfm_detr.trk", streamlines, affine, labels.shape) +save_trk("tractogram_sfm_detr.trk", streamlines, affine, labels.shape) """ References @@ -170,4 +170,6 @@ the accuracy of diffusion MRI models in white matter. PLoS ONE 10(4): e0123272. doi:10.1371/journal.pone.0123272 +.. include:: ../links_names.inc + """ diff --git a/doc/examples/tracking_tissue_classifier.py b/doc/examples/tracking_tissue_classifier.py index ca4eee1ef4..2f91918ca1 100644 --- a/doc/examples/tracking_tissue_classifier.py +++ b/doc/examples/tracking_tissue_classifier.py @@ -14,15 +14,19 @@ 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. +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 -:ref:`example_deterministic_fiber_tracking` example. We begin by loading the +:ref:`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. """ +# Enables/disables interactive visualization +interactive = False + import numpy as np from dipy.data import (read_stanford_labels, @@ -35,12 +39,7 @@ from dipy.tracking.local import LocalTracking from dipy.tracking.streamline import Streamlines from dipy.tracking import utils -from dipy.viz import window, actor, colormap as cmap, have_fury - -# Enables/disables interactive visualization -interactive = False - -ren = window.Renderer() +from dipy.viz import window, actor, colormap, has_fury hardi_img, gtab, labels_img = read_stanford_labels() _, _, img_pve_wm = read_stanford_pve_maps() @@ -49,8 +48,8 @@ affine = hardi_img.affine white_matter = img_pve_wm.get_data() -seed_mask = np.logical_and(labels == 2, white_matter == 1) - +seed_mask = (labels == 2) +seed_mask[img_pve_wm.get_data() < 0.5] = 0 seeds = utils.seeds_from_mask(seed_mask, density=2, affine=affine) response, ratio = auto_response(gtab, data, roi_radius=10, fa_thr=0.7) @@ -116,34 +115,33 @@ **Thresholded fractional anisotropy map.** """ -all_streamline_threshold_tc_generator = LocalTracking(dg, - threshold_classifier, - seeds, - affine, - step_size=.5, - return_all=True) -streamlines = Streamlines(all_streamline_threshold_tc_generator) -save_trk("all_streamlines_threshold_classifier.trk", +streamline_generator = LocalTracking(dg, + threshold_classifier, + seeds, + affine, + step_size=.5, + return_all=True) +streamlines = Streamlines(streamline_generator) +save_trk("tractogram_probabilistic_thresh_all.trk", streamlines, affine, labels.shape) -if have_fury: - window.clear(ren) - ren.add(actor.line(streamlines, cmap.line_colors(streamlines))) - window.record(ren, out_path='all_streamlines_threshold_classifier.png', - size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_deterministic_thresh_all.png', + size=(800, 800)) if interactive: - window.show(ren) + window.show(r) """ -.. figure:: all_streamlines_threshold_classifier.png +.. figure:: tractogram_deterministic_thresh_all.png :align: center - **Deterministic tractography using a thresholded fractional anisotropy.** + **Corpus Callosum using deterministic tractography with a thresholded + fractional anisotropy mask.** """ - - """ Binary Tissue Classifier ======================== @@ -189,31 +187,32 @@ **White matter binary mask.** """ -all_streamline_binary_tc_generator = LocalTracking(dg, - binary_classifier, - seeds, - affine, - step_size=.5, - return_all=True) -streamlines = Streamlines(all_streamline_binary_tc_generator) -save_trk("all_streamlines_binary_classifier.trk", +streamline_generator = LocalTracking(dg, + binary_classifier, + seeds, + affine, + step_size=.5, + return_all=True) +streamlines = Streamlines(streamline_generator) +save_trk("tractogram_deterministic_binary_all.trk", streamlines, affine, labels.shape) -if have_fury: - window.clear(ren) - ren.add(actor.line(streamlines, cmap.line_colors(streamlines))) - window.record(ren, out_path='all_streamlines_binary_classifier.png', - size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_deterministic_binary_all.png', + size=(800, 800)) if interactive: - window.show(ren) + window.show(r) """ -.. figure:: all_streamlines_binary_classifier.png +.. figure:: tractogram_deterministic_binary_all.png :align: center - **Deterministic tractography using a binary white matter mask.** + **Corpus Callosum using deterministic tractography with a binary white + matter mask.** """ """ @@ -286,59 +285,60 @@ **Include (left) and exclude (right) maps for ACT.** """ -all_streamline_act_tc_generator = LocalTracking(dg, - act_classifier, - seeds, - affine, - step_size=.5, - return_all=True) -streamlines = Streamlines(all_streamline_act_tc_generator) -save_trk("all_streamlines_act_classifier.trk", +streamline_generator = LocalTracking(dg, + act_classifier, + seeds, + affine, + step_size=.5, + return_all=True) +streamlines = Streamlines(streamline_generator) +save_trk("tractogram_deterministic_act_all.trk", streamlines, affine, labels.shape) -if have_fury: - window.clear(ren) - ren.add(actor.line(streamlines, cmap.line_colors(streamlines))) - window.record(ren, out_path='all_streamlines_act_classifier.png', - size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_deterministic_act_all.png', + size=(800, 800)) if interactive: - window.show(ren) + window.show(r) """ -.. figure:: all_streamlines_act_classifier.png +.. figure:: tractogram_deterministic_act_all.png :align: center - **Deterministic tractography using ACT stopping criterion.** + **Corpus Callosum using deterministic tractography with ACT stopping + criterion.** """ -valid_streamline_act_tc_generator = LocalTracking(dg, - act_classifier, - seeds, - affine, - step_size=.5, - return_all=False) -streamlines = Streamlines(valid_streamline_act_tc_generator) -save_trk("valid_streamlines_act_classifier.trk", +streamline_generator = LocalTracking(dg, + act_classifier, + seeds, + affine, + step_size=.5, + return_all=False) +streamlines = Streamlines(streamline_generator) +save_trk("tractogram_deterministic_act_valid.trk", streamlines, affine, labels.shape) -if have_fury: - window.clear(ren) - ren.add(actor.line(streamlines, cmap.line_colors(streamlines))) - window.record(ren, out_path='valid_streamlines_act_classifier.png', - size=(600, 600)) +if has_fury: + r = window.Renderer() + r.add(actor.line(streamlines, colormap.line_colors(streamlines))) + window.record(r, out_path='tractogram_deterministic_act_valid.png', + size=(800, 800)) if interactive: - window.show(ren) + window.show(r) """ -.. figure:: valid_streamlines_act_classifier.png +.. figure:: tractogram_deterministic_act_valid.png :align: center - **Deterministic tractography using a anatomically-constrained tractography - stopping criterion. Streamlines ending in gray matter region only.** + **Corpus Callosum using deterministic tractography with ACT stopping + criterion. Streamlines ending in gray matter region only.** """ """ @@ -351,9 +351,10 @@ Notes ------ -Currently in ACT 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. +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 @@ -363,4 +364,10 @@ 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. + +.. include:: ../links_names.inc """ diff --git a/doc/examples/valid_examples.txt b/doc/examples/valid_examples.txt index 98b323b20d..f1fee7defb 100644 --- a/doc/examples/valid_examples.txt +++ b/doc/examples/valid_examples.txt @@ -1,5 +1,4 @@ quick_start.py - tracking_quick_start.py brain_extraction_dwi.py reconst_csa_parallel.py reconst_csa.py @@ -25,9 +24,6 @@ segment_clustering_metrics.py snr_in_cc.py streamline_formats.py -# tracking_eudx_odf.py -# tracking_eudx_tensor.py - sfm_tracking.py sfm_reconst.py gradients_spheres.py simulate_multi_tensor.py @@ -43,17 +39,18 @@ denoise_gibbs.py fiber_to_bundle_coherence.py # denoise_ascm.py - introduction_to_basic_tracking.py - probabilistic_fiber_tracking.py - deterministic_fiber_tracking.py - particle_filtering_fiber_tracking.py + tracking_introduction_eudx.py + tracking_deterministic.py + tracking_probabilistic.py + tracking_bootstrap_peaks.py + tracking_tissue_classifier.py + tracking_pft.py + tracking_sfm.py affine_registration_3d.py syn_registration_2d.py syn_registration_3d.py tissue_classification.py bundle_registration.py - tracking_tissue_classifier.py - tracking_bootstrap_peaks.py # piesno.py viz_advanced.py viz_slice.py diff --git a/doc/examples_index.rst b/doc/examples_index.rst index e16255db0a..c3d1728fb3 100644 --- a/doc/examples_index.rst +++ b/doc/examples_index.rst @@ -18,7 +18,7 @@ Quick Start ----------- - :ref:`example_quick_start` -- :ref:`example_tracking_quick_start` +- :ref:`example_introduction_eudx` ------------- Preprocessing @@ -146,13 +146,13 @@ Contextual enhancement Fiber tracking -------------- -- :ref:`example_introduction_to_basic_tracking` -- :ref:`example_probabilistic_fiber_tracking` -- :ref:`example_deterministic_fiber_tracking` +- :ref:`example_tracking_introduction_eudx` +- :ref:`example_tracking_deterministic` +- :ref:`example_tracking_probabilistic` - :ref:`example_tracking_bootstrap_peaks` - :ref:`example_tracking_tissue_classifier` -- :ref:`example_particle_filtering_fiber_tracking` -- :ref:`example_sfm_tracking` +- :ref:`example_tracking_pft` +- :ref:`example_tracking_sfm` ------------------------- Fiber tracking evaluation