In the last article I introduced Extended Streamline Tractography (XST). In this article I will talk talk about the best practices and supporting softwares when applying XST to real MR data.
- Preprocess DWI images
- Generate seeding coordinates from ROI mask
- Running XST
- Embedd diffusivity metrics onto the tractography model
The following are required to run the supporting scripts:
git clone https://github.com/sinkpoint/pynrrd.git python setup.py install
git clone https://github.com/sinkpoint/neuro-scripts.git
Then make sure to add the neuro-script repo dir to the path in
.bashrc. If you are on OSX then add it to
Preprocess DWI images
Diffusion weighted image (DWI) preprocessing involves a number of steps, including motion and eddy-current corrections, possibly reverse-phase encoding corrections, resampling, etc, that are outside the scope of this article. Here I’ll outline the XST specific steps. For for information on general DWI preprocessing, refer to the FSL EDDY and TOPUP documentations.
Truncate b=0 volumes
XST requires each DWI image to have only one b=0 volume. If there are more than one, you should either discard all but the last b=0, or average the volumes. A script is provided to perform this step:
b0avg.py -i raw_dwi.nhdr -o b0truncate_dwi.nhdr
If you prefer to average the b0s instead, you can do:
b0avg.py -i raw_dwi.nhdr -g -o b0avged_dwi.nhdr
Usually DWI images are given as a WxIxJxK array, where W is the weighted indices. Sometimes however they can be given as IxJxKxW as well. In these cases, you can specify the W dimension index by:
b0avg.py -i raw_dwi.nhdr -a 3 -g -o b0avged_dwi.nhdr
-a parameter specifies the W index, starting at 0.
Correct header orientation to RAS
The XST library expects the NRRD headers to be given in RAS (Right-anterior-superior) space.
You can use my PyNRRD library to correct any NRRD files to the correct RAS orientation. You can correct the header by writing a python script with:
import pynrrd as nrd reader = nrd.NrrdReader() header, binary = reader.load('file.nhdr') header.correctSpaceRas() # convert spacing to RAS, this is needed for xst, else geometry will be inverted. writer = NrrdWriter() writer.write(header, 'output.nhdr')
Generate seed points
A list of seed coordinates need to be generated from a ROI mask image.
You can do this with the
Here’s an example of performing uniform random seeding with 10 points per voxel.
seedTend2Points.py -i ROI.nrrd -r -n 10 -m myrois
The script will create a
xst folder, where .txt files will be created with the seeding coordinates
for each label.
Alternatively, you can generate points on a grid pattern with a set spacing in image space.
seedTend2Points.py -i ROI.nrrd -s 0.3 -m myrois
Embed data onto tract model
One of the interesting feature of tractography is the ability to embed measures onto the model. This has a number of potential uses, for example it allows one to visualize how fractional anisotropy changes along the model.
copyScalarsToVtk.py -i tracts.vtk -m fa.nii.gz -n FA -o tracts_w_fa.vtp
Note that the output file is in the vtk XML format (.vtp).
Here’s an example of the final output when loaded into 3D Slicer: