MRTrix Examples - vistalab/vistasoft GitHub Wiki

This page describes how to use MRTrix with vistasoft.

Vistasoft and MRtrix

In general, you can use the Vistasoft tools to run MrTrix. These matlab scripts were mostly written by Ariel Rokem, Bob Dougherty and Franco Pestilli. The vistasoft tools are only compatible with MRTrix version 0.2. MRTrix team develops the latest version (MRTrix 0.3) which has many further utilities, but vistasoft tools are not compatible with it yet.

Converting segmentation files into .mif format

White matter mask is useful to use in MrTrix analysis. Right now, we convert the white matter segmentation files into .mif format in order to use it in mrTrix.

In a first step, recommended method is use FreeSurfer for first-stage segmentation, and then use itkGray for manually correcting segmentation errors. See Anatomical_Methods for detail.

Hereafter, I will describe the method for converting itkGray segmentation file into mrTrix format.

In itkGray format, white matter is defined as

3: left white matter 4: right white matter

whereas we must define

1: white matter 0: other voxels

in mrTrix white matter mask.

mrtrix_itkclass_wmmask.m is a MATLAB function converting the segmentation file in [itkGray] (itkGray) format into this format.

You could simply run

classfile = 't1_class.nii.gz'; % Segmentation file in itkGray format

fname = 't1_class_binary'; % Filename for output file

mrtrix_itkclass_wmmask(classfile, fname)

You could check the quality of white matter mask in MRTrix viewer (type mrview in Linux terminal).

Converting mrDiffusion data format into mrTrix data format

We (mostly Ariel?) developed the tool for converting the data format in mrDiffusion into MrTrix. Hereafter, we will describe the set of function which helps to convert the mrDiffusion data into mrTrix format (.mif) file.

The conversion from mrDiffusion format to mrTrix format has following steps.

1. Coverting raw diffusion data (.nii.gz format) into .mif format

First step is to convert DWI data in nifti format in .mif format. To do that, run

dwRawFile = 'dwi_raw_preprocessed.nii.gz' % Raw diffusion data in nifti format, and has been already preprocessed in mrDiffusion tool

files.dwi = 'dwi.mif' % File name for dwi file in .mif format

mrtrix_mrconvert(dwRawFile, files.dwi)

in MATLAB window.

2. Converting bval/bvecs file into mrTrix format.

MRTrix stores both bval and bvec into single file (.b). To convert the .bvals and .bvecs file into .b format, we run mrtrix_bfileFromBvecs.m

bvals = 'dwi_raw_preprocessed.bvals' % Full path to bval file in mrDiffusion format

bvecs = 'dwi_raw_preprocessed.bvecs' % Full path to bvec file in mrDiffusion format

files.b = 'dwi.b' % File name for .b file

mrtrix_bfileFromBvecs(bvecs, bvals, files.b)

3. Converting brain mask file into .mif format.

Use the brain mask files generated in mrDiffiusion, and convert it into .mif format.

brainMaskFile = '/Subject1/dti96dirtrilin/bin/brainMask.nii.gz'; % Full path to brain mask file generated by mrDiffusion preprocessing pipelines

files.brainmask = 'dwi_brainmask.mif'

mrtrix_mrconvert(brainMaskFile, files.brainmask, false);

4. Computing tensor from raw DWI data.

Compute diffusion tensor from raw DWI data, and save it in .mif format.

files.dt = 'dwi_dt.mif' % File name of .mif file stroing diffusion tensor information

mrtrix_dwi2tensor(files.dwi, files.dt, files,b);

5. Computing fractional anisotropy.

files.fa = 'dwi_fa.mif' % File name of .mif storing FA map

mrtrix_tensor2FA(files.dt, files.fa, files.brainmask);

6. Computing eigenvector (PDD) map for MrTrix viewer.

Compute eigenvector (PDD) map in .mif format for MrTrix viewer.

files.ev = 'dwi_ev.mif' % File name of .mif storing eigenvector (PDD) map

mrtrix_tensor2vector(files.dt, files.ev, files.fa);

7. Calculate the fiber response function.

Calculate the fiber response function utilized by MrTrix for the spherical deconvolution analysis.

files.response = 'dwi_response.mif';

mrtrix_response(files.brainmask, files.fa, files.sf, files.dwi, files.response, files.b, [], [], [], lmax, true);

We need to specify the parameter named "Lmax" here. Lmax defines the number of set of spherical harmonics to fit CSD model. In vistasoft-MrTrix bridge, the default value of Lmax is 6.

8. Fit the spherical deconvolution (CSD) model to DWI data.

files.csd = 'dwi_csd.mif';

mrtrix_csdeconv(files.dwi, files,response, lmax, files.csd, files.b, files.brainmask);

After finishing this step, now you could run the fiber tractography using CSD model!

From Brian: Presumably we need to make a example data for doing this? Are there any wrapper function for doing all of this stuffs? Specifying the selection of Lmax for computing CSD.

Run Tractography

The documentation of MrTrix tractography is described in [this site] (http://www.brain.org.au/software/mrtrix/commands/streamtrack.html).

MRTrix provides three different tractography algorithms (DT_STREAM, SD_STREAM and SD_PROB).

We could run streamtrack from terminal, or also use several MATLAB functions we have (mrtrix_track.m, feTrack.m in LiFE).

There are several parameters we need to specify when we run MRTrix tractography.

  • seed and -mask identify the seed voxels and white-matter mask. For running whole-brain tractography, we typically use white-matter regions defined by segmentation procedure as both seed and mask. Then tractography algorithms chose the voxels in white matter mask as seed voxels for bidirectional tracking. The alternative procedure is using gray/white matter interface as seed voxels. In both cases, the white matter mask can be defined by nifti in binary format (1, white matter; 0, others), and then we could convert the nifti into .mif format using mrconvert (or mrtrix_mrconvert in MATLAB).

  • curvature defines the minimum radius of curvature in tractography. This is also constraining the angle in tractography, depending on the step size.

  • num defines the maximum number of streamlines produced by tractography.

The example command line for whole-brain tractography (used in terminal):

streamtrack SD_PROB dwi_csd.mif -mask t1_class.mif -seed t1_class.mif -curvature 1 S1_SDPROB_500000.tck -num 500000

This command line use CSD file as an input for CSD Probabilistic tractography, and use white-matter mask as both seed and mask for tracking (whole-brain tractography).

Convert .tck file into .pdb file

MrTrix produces .tck file for storing streamline information, which is not compatible with Quench or mrDiffusion.

In order to convert .tck file into .pdb file, please use mrtrix_tck2pdb.m

mrtrix_tck2pdb('S1_SDPROB_lmax8_500000.tck', 'S1_SDPROB_lmax8_500000.pdb')

.pdb format is compatible with Quench, mrDiffusion, AFQ and LiFE.