Isolating a bundle#

A whole-brain tractogram holds every bundle at once. To keep one of them, select the streamlines that pass through regions the bundle passes through (include regions) and drop those that pass through regions it does not reach (exclude regions). lar tract-edit does this for TCK, TRK and VTK files.

Regions#

A region is either a sphere, written x,y,z,r (centre and radius in mm, in world coordinates, the ones the viewer shows at the cursor), or a mask image (.nii, .nii.gz, .mif), on any grid. A streamline passes through a region when at least one of its points is inside it.

An include and an exclude region#

For example, the left corticospinal tract runs from the motor cortex down through the brainstem. With a mask of the left precentral gyrus, a sphere in the left cerebral peduncle and a mask of the right hemisphere:

lar tract-edit tracks.tck left_cst.tck \
    --include lh_precentral.nii.gz \
    --include -12,-20,-14,6 \
    --exclude rh_hemisphere.nii.gz

A streamline is kept when it passes through every --include region and through no --exclude region. The command reports how many streamlines it read and wrote. Open the result over a T1 image to check it:

lar bv -v t1.nii.gz -t left_cst.tck

Refining the selection#

  • --ends-only tests only the two endpoints of each streamline, for bundles defined by where they start and end.

  • --include-ordered (repeated) asks for the regions to be passed in the given order.

  • --within (repeatable) keeps only the streamlines whose points all lie inside a region, such as a white-matter mask.

  • --min-length and --max-length drop streamlines that are too short or too long, in mm.

  • --mask cuts the kept streamlines to the parts inside a region, for example a brain mask.

  • --inverse keeps the streamlines the selection drops.

The same edit from Python:

from larmor.tractography import EditOptions, edit_files, load_region

options = EditOptions(
    include=[load_region("lh_precentral.nii.gz"), load_region("-12,-20,-14,6")],
    exclude=[load_region("rh_hemisphere.nii.gz")],
)
read, written = edit_files(["tracks.tck"], "left_cst.tck", options)

edit runs the same edit on a Tractogram in memory. Every option is listed in the command-line reference.