Preprocessing Diffusion Tensor Images with FSL

blue bar

There already is a large amount of information on the web and in the literature about methods for processing diffusion weighted MR acquisitions. These notes provide a brief introduction on how to preprocess DTI data, with emphasis on projects run in Academic Radiology. A similiar guide is also available from Chris Rorden, and from the Dartmouth Brain Imaging Center.

In order to follow this, you will need access to FSL installed under GNU/Linux or Cygwin. All required software is already installed on the Academic Radiology Linux server. If installing Cygwin for use with FSL, some local notes may be useful. After installing Cygwin, download and install the Windows version of FSL as described on the FSL web page.

You may also need a copy of Paul's DICOM to Analyze dtoa software complied for Cygwin.

The basic preprocessing steps are

  1. Export diffusion weighted images from the MR scanner.
  2. Convert the diffusion weighted images to Analyze.
  3. Calculate the diffusion directions and b values.
  4. Using FSL

If the DICOM images can be exported in step 1, above, and FSL is installed, then the remaining steps may be performed by my DICOM to Analyze conversion software, dtoa, by specifying the -diff -fdt command line options, which following conversion to Analyze, run batch files to perform eddy current correction and calculate mean diffusivity, FA maps, and isotropic diffusion weighted images using FSL. For example, if the source DICOM images are stored in /cdrom and the converted Analyze images are to be stored in /data/experiment1, then type

dtoa -c -ana -datefirst -diff -fdt /cdrom /data/experiment1

If the DICOM images or FSL are not available, or if another route for processing the images is required, the individual steps are described below.

1. Export Diffusion Weighted Images from the MR scanner

Preferably, export the images as DICOM, either over a network or onto a CD or other removeable media. Try to ensure the DICOM images are written to CD as soon as practiable after being exported from the scanner as DICOM network transfer through different manufacturers, or different modality, workstations may result in some of the private DICOM messages, such as those containing diffusion scan parameters, being removed from the DICOM header.

To export DICOM images to the hard disk on a Philips MR scanner (release 10 and above)

Image data from Philips scanners are often exported in Philips research PAR/REC format. Unfortunately, this format does not contain the diffusion directions used and they must be inferred as described below. As a check that these inferred directions are correct, it is useful to re-run the same DTI acquisition on one volunteer and export both the DICOM and PAR/REC files of the same diffusion images. This will allow the inferred directions to be compared against those found in the DICOM header.

2. Convert the Diffusion Weighted Images to Analyze.

If the images have been exported as DICOM, I suggest converting them to Analyze using my DICOM to Analyze software dtoa using the -diff flag as this extracts the diffusion directions and b values from the DICOM header and saves bvals and bvecs files in the appropriate coordinate frame for processing by FSL. A typical example would be (if running under Cygwin, with the DICOM images on a CD in E: and the converted Analyze images to be saved in D:\data\dti day 2)

dtoa -ana -delses -date -diff /cygdrive/e "/cygdrive/d/data/dti day 2"

This should work with diffusion weighted DICOM images from recent GE, Philips, and Siemens MR scanners although it has only been tested for certain acquisitions; in particular, be diligent checking the principle eigenvectors for sagittal and coronal slice orientations, and protocols that do not contain a b=0 acquisition.

Other software may be used to convert DICOM to Analyze or NIFTI format, and extract the diffusion directions. In particular, see MRIcro, FMRIB's DICOM to Analyze software, Jolinda's MRIConvert, CATNAP, and Diffusion weighted information in DICOM.

3. Calculate the Diffusion Directions and b values.

Software for processing diffusion tensor data, such as tractography, usually requires that the diffusion gradient directions be specified relative to the image, that is, relative to the image's horizontal, vertical, and through-plane axes. Depending on the MRI sequence used, the directions may be applied in othe coordinate frames, in particular relative to the frequency, phase-encoding, and through-slice axes, or relative to the physical x, y, and z axes of the magnet regardless of the slice orientation. Diffusion weighted images acquired using Philips MR scanners may have directions specified in any of the above three coordinate frames. Siemens product sequences appear to use diffusion directions relative to the magnet's physical x, y, and z axes, while GE diffusion directions are relative to frequency encoding, phase encoding, and slice selection axes. In order to perform tractography, the coordinate frame used for the particular acquisition must be known and the diffusion directions then transformed to be relative to the horizontal, vertical, and through-plane axes of the images. Unfortunately, this information is not clearly described in the DICOM header and a priori knowledge of the specific diffusion acquisition protocol is required.

Diffusion gradient directions on Philips MR scanners

Recent Philips DICOM images contain the vector of the diffusion weighting gradient as well as the b value. However, the DICOM files do not specify the coordinate frame used. This can either be determined from knowledge of the MRI acquisition protocol used or by comparing the diffusion vectors found in the DICOM header with those specified in the sequence code. Once the coordinate frame is known, the diffusion vectors may be transformed to the image coordinate frame as appropriate. This is the approach taken by dtoa which then outputs the diffusion vectors and b values

Research images are often exported from a Philips scanner in their internal PAR/REC format. Unfortunately diffusion vector information is not stored in the PAR/REC files. If the DICOM images are not available and only the PAR/REC files present, one strategy is to convert the PAR/REC to Analyze using MRIcro or ptoa and proceed as follows

On the MR scanner, recall the diffusion protocol used. On the Contrast page, check the setting for the gradient overplus and directional resolution options, on subsequent lines. There are three possibilities

For all acquisitions also note (from the Contrast page)

On the Geometry page, for low, medium, or high directional schemes, note

and from the Offc/ang page (or from the PAR file), for low, medium, or high directional schemes, note

From this information, the diffusion directions can be calculated using an extremely useful Rotation OVP Java applet. Note that the default fat shift direction on the scanner is P not A.

The next stage is to convert these directions to the coordinate system used by FSL and manually produce the bvals and bvecs text files. Remember to ensure that the vectors specified in the bvecs file are unit vectors, i.e., x2+y2+z2=1. If not, divide each component by (x2+y2+z2). The bvecs file consists of three lines where the first line contains the x component of the diffusion vector, the second line contains the y component and the third line the z component. Include the vector 0,0,0 for any images acquired without diffusion weighted, i.e., the b=0 images. When producing bvecs files from the vectors produced by the Rotation OVP Java applet, or the user defined directions entered on the scanner, negate the x and z components. The vectors (and b values in the bvals file) must be in the same order as the diffusion weighted images volumes in the image file - be especially careful if multiple b values have been acquired or no b=0 images are present.

Finally, if the standard Philips diffusion directions were used, the scanner reconstruction calculates an additional 'isotropic' diffusion weighted image. This initially appears as an extra volume in the exported image data which may be mistaken as an additional diffusion direction. This "I" volume must be removed from the converted images before the data are processed using FSL. Visually, it is obvious if the last volume is the "I" data as the diffusion weighted image is very 'flat' in normal tissue with no white matter contrast. There will also appear to be one extra diffusion direction, i.e., for the Philips medium direction scheme there should be one b=0 volume, 15 diffusion weighted volumes. However, the exported data will initially contain 17 volumes, the last volume being the "I" which must be removed. The presence of an "I" volume is also indicated in the output from the Java applet as a vector of (100,100,100) which, of course, must not be included in the bvecs file. It is not present in diffusion data acquired with user defined directions and is removed automatically if DICOM images are converted using dtoa with the -diff option.

4. Using FSL

The data should now be in a format for processing using FSL. For the following example, assume that the base Analyze file containing the diffusion images is set01_data

The graphical user interface to FSL allows filenames to be specified by typing in the filename or browsing through the directory structure for the required file. If running FSL under Cygwin, you may browse outside the directory in which Cygwin is installed and select files stored anywhere on the hard disk under Microsoft Windows. However, if you do this, after selecting the required file, the filename listed in many of the FSL tools is incorrect and must be manually editted. For example, if you browse and choose the Analyze file in D:\data\dti_subject1\set01_data then it may be listed in the FSL tool as D:\data\dti_subject1\D:\data\dti_subject1\set01_data which needs to be manually changed to remove the duplication of the directory, to just D:\data\dti_subject1\set01_data or /cygdrive/d/data/dti_subject1/set01_data
If you do not do this, the FSL tool will give an error message and not run.

Start the main FSL menu by typing

fsl &

Note: If you are running FSL from Cygwin, then be aware that there is an incompatibility between the current version of Cygwin and FSL. The incompatibility appears to relate to inheritence of environment variables between various scripts used by FSL. One solution is to use an older, compatible version of Cygwin, as described on the FSL web page. If you are only interested in using FSL's diffusion toolkit, then a quicker alternative approach to make FSL work with the latest version of Cygwin is to apply the following patch to FSL.

cd $FSLDIR
sed -i "s/sh -c/bash -l -c/g" tcl/*.tcl bin/betsmallz bin/featquery bin/featregapply

Unfortunately, the same approach does not fix issues with the fMRI processing tools.

4.1 Correct for differences in spatial distortion due to eddy currents

To start FSL's Diffusion Toolkit, either click on FDT Diffusion on the main FSL menu window, above, or type

UNIX or GNU/Linux: Fdt &
Cygwin: Fdt_gui &

As well as the notes below, more complete instructions for FDT are given on the FMRIB website. In the new FDT window that appears, change the pull-down menu from the default selection of ProbTrack Probabilistic tracking to Eddy current correction. For the Diffusion weighted data select the file containing the diffusion images, in this example, set01_data. By default, the Corrected output data will be saved to an Analyze file called data in the same directory; I suggest manually changing this to something more meaningful (especially if you have several DTI acquisitions to process in the same directory) such as set01_data_cor. Usually leave the Reference volume set to 0 as the b=0 data are usually the first volume in the Analyze file. Click Go to start the correction, which may take several minutes to perform.

Alternatively, run the eddy current correction from the command line, e.g.,

eddy_correct set01_data set01_data_cor 0

where the final character on the line above is a zero. Ignore warning messages about 'Both reference and input images have an sform matrix set'.

4.2 Create a binary mask of the brain

Start the Brain Extraction Tool by either clicking on BET Brain Extraction on the main FSL menu window, or type

UNIX or GNU/Linux: Bet &
Cygwin: Bet_gui &

In the new BET window, select the Input image to be the result of eddy current correction from above, e.g., set01_data_cor Click on the arrow to the left of Advanced Options and select the Generate binary brain mask image option. Experiment with setting different values for the Fractional intensity threshold; for typical DTI acquisitions in Nottingham, 0.2 works well. Click Apply to produce the mask, which in this example will be saved with filename set01_data_cor_brain_mask

Alternatively, run the BET from the command line, e.g.,

bet2 set01_data_cor set01_data_cor_brain -f 0.2 -m

4.3 Calculate the diffusion tensor and associated parameters

Using FSL's Diffusion Toolkit, FDT, as described above, use the pull-down menu to select DTIFit Reconstruct diffusion tensors. Select Specify input files manually and enter the appropriate files for each field - bearing in mind the comments above about duplication of the directory name if using file browsing under Cygwin. As above, once you select your input filename, FDT automatically fills in the output base filename as just dti which is not very specific; I suggest manually changing this to something more useful such as set01_dti, e.g.,

Diffusion weighted data: set01_data_cor
BET binary brain mask: set01_data_cor_brain_mask
Output basename: set01_dti
Gradient direction: set01_bvecs
b values: set01_bvals

Then click Go. Processing typically takes a few seconds to a few minutes. FDT's error messages are not particularly informative but the most common mistake is usually misspecifying the input filenames, in particular, a mismatch between the number of diffusion directions or b-values, with the number of volumes in the input image file. Note, even if you specify incorrect, but plausible, diffusion directions at this stage, DTIFit should still run. Errors are usually due to a problem with the format of the data rather than the data themselves.

The result will be several Analyze images containing the diffusion parameters -

set01_dti_FA The Fractional Anisotropy of the diffusion tensor, as floats.
set01_dti_L1 The largest eigenvalue of the diffusion tensor, as floats.
set01_dti_L2 The second largest eigenvalue of the diffusion tensor, as floats.
set01_dti_L3 The smallest eigenvalue of the diffusion tensor, as floats.
set01_dti_MD The Mean Diffusivity the diffusion tensor (equal to one third of the trace of the tensor, which represents the average diffusion in that voxel), as floats.
set01_dti_S0 as floats.
set01_dti_V1 The (principle) eigenvector of the diffusion tensor, associated with the largest eigenvalue, above. Stored in Analyze format as three float images, where values in each image correspond to the eigenvector's x,y,z values.
set01_dti_V2 The eigenvector of diffusion tensor associated with the second eigenvalue, above. Stored in Analyze format, as above.
set01_dti_V3 The eigenvector of diffusion tensor associated with the third eigenvalue, above. Stored in Analyze format, as above.

Alternatively, run DTIFit from the command line, e.g.,

dtifit --data=set01_data_cor --out=set01_dti --mask=set01_data_cor_brain_mask --bvecs=set01_bvecs --bvals=set01_bvals

4.4 Check the principle eigenvectors appear plausible

Especially with data from a new scanner or from a new protocol, it is wise to check that the processing, above, has produced plausible results. This may be assessed visually using FSLeyes or the older FSLView.

4.4a Using FSLeyes

Start FSLeyes by clicking on that option from the main FSL window, or type

fsleyes &

at the command prompt. As well as the notes below, viewing diffusion data with FSLeyes is also well described at FMRIB.

4.4b Using FSLView

Start FSLView by clicking on that option from the main FSL window, or type

fslview &

at the command prompt. As well as the notes below, viewing diffusion data with FSLView is also well described at FMRIB.

In FSLView, select File / Open and browse to set01_dti_FA. which will display the FA map as a MPR. While the cross-hair is selected, click on the images to select an appropriate slice to demonstrate correct or incorrect white matter fibre orientation, e.g. a point in a pyramidial tract, left or right, just below the corpus callosum. Then select File / Add and browse to a complementary set01_dti_V1 file. This displays the principle eigenvector as an overlay. To inform FSLView that this is a vector rather than an image of floats, ensure that the V1 file is highlighted in the subwindow, lower left, then click on the info button button. In the new Overlay Information window, select DTI Display and set this menu to RGB. Then pull down the Modulation menu and select set01_dti_FA. Click OK. This displays a colour coded FA map, where red indicates that the principle eigenvectors point mostly left-right, green indicates anterior-posterior, and blue indicates feet-head.

Again, select File / Add and browse to the same set01_dti_V1 file. Click on the info button button for this second occurance of V1 but now select DTI Display and choose Lines and click OK. This overlays the principle eigenvector for each voxel as a red line. Explore FSLView's zoom features to display these more clearly (either increase the zoom factor in all windows by increasing the value immediately below the File menu, or select the zoom button button (below the View menu) and select a region to magnify). The only way to save the images is to obtain a snapshot of the screen, in whatever manner defined by your operating system.