Diagnose tensor orientation problems

From VrlWiki
Jump to navigation Jump to search

Sometimes when processing diffusion MRI data, the DWIs come to us in a different coordinate system than the b vectors. This issue manifests itself in orientation problems with the fit tensors, which can be very subtle and hard to detect.

There are two types of mis-orientations:

  • Permutations, where e.g. the X dimension has been exchanged with Y. These are easy to detect using an RGB-mapped visualization of the tensor field, or even by examining the DWIs if you know the b vectors.
  • Flips, where the images have been mirrored in e.g. X. These are easy to detect using a tensor ellipse visualization or by looking at a tractogram, a fair bit harder to spot by looking at a field of the off-diagonal elements of the tensors, and impossible to spot in an RGB visualization of the tensor field due to the mirror symmetry of the colormap. Since the orientation but not the direction of each tensor matters, only non-axis-aligned tensors display any irregularity when flipped in one dimension.

Since generating streamtubes takes a long time, it is ideal to detect orientation problems just by looking at the tensors, before generating the tubes. However, the effects of incorrect orientation are far more apparent in the tube visualization than in the tensor map. On the first pass through a new dataset, it's recommended that you run the diffusion processing pipeline at low resolution so that you don't have to wait so long to detect problems.

Detecting Tensor Orientation Problems

... Before Generating Tubes

  1. Generate RGB-coded tensor maps with mriatlas:
    1. cd into the directory of the processed brain you'd like to diagnose.
    2. mriatlas -o tensors.pdf voxel_models/tensors
    3. Open up the resulting tensors.pdf in your favorite PDF viewer.
      • The color coding is: red = X, green = Y, blue = Z.
      • mriatlas specifies slices by the plane's equation, e.g. x = 30. The named dimension is therefore the through-plane direction in the slice you're looking at.
  2. Check for orientation problems:
    1. Look at a slightly para-sagittal section; this section should contain the corpus callosum (going through-plane) and cingulum bundle (superior to the CC, running anterior-posterior). Verify that the CC is the appropriate through-plane color.
      • If it's the wrong color, you have a permutation.
    2. Look at a coronal section and make sure that cingulum (which should now be running through-plane) is the appropriate color.
      • Again, an incorrect color indicates a permutation.

Lots of other groups seem to use planes of diffusion ellipses to diagnose orientation problems, but we don't currently have a way to generate those from tensors in MRIimage format. If we did, we could detect dimension flips before generating streamtubes.

... After Generating Tubes

  1. Generate tubes with tubegen (check a diffusion processing pipeline Makefile to see how).
  2. View them with Brainapp.
  3. Check for orientation problems:
    1. Look at a front view of the tubes through the callosum and make sure they complete a U the goes all the way to the superior cortex. Since the CC is almost always axis-aligned, it rarely visibly breaks.
      • If they're broken, you have a flip in either the superior-inferior direction or the left-right direction.
    2. Look at a top view of tubes and make sure that forceps major and minor complete a pair of U shapes that go anterior and posterior from the callosum.
      • If they're broken, you have a flip in either the anterior-posterior direction or the left-right direction.
A tractogram with an anterior-posterior flip. Note the absence of the forceps major and minor.

Choosing which Coordinate System to Trust

Since the source of an orientation problem is a disagreement between the coordinate systems of the b-vectors and the DWIs, one must choose which coordinate system to treat as the "true" one when fixing the problem. Due to conflicting "standards" for medical image formats, sometimes the DWIs use a left-handed coordinate system or otherwise store images in a funky way; if this is the case, you probably want to trust the coordinate system of the b vectors. On the other hand, if the DWIs seem to be stored correctly, you probably want to trust their coordinate system.

You can use the Matlab commands readMriImage(), stackToVideo(), and viewSlice() to examine the source DWIs. The standard coordinate system is right-handed and based on the perspective of a doctor standing upright and facing a standing patient. Positive X goes to the doctor's right (patient's left), positive Y goes to the posterior (back) side of the patient, and positive Y goes to the superior side of the patient. In a Cartesian view of a single X-Y slice, then, the anterior (front) of the patient should be facing downward, with the patient's left side on the right side of the slice; this is the same perspective the doctor would have looking straight down on the top of the patient's head. As Z increases, the slice moves up the body (superior) and therefore closer to the observer.

If inspection of the DWIs indicates a direction flip of the sort that you observed in the tensors, it makes sense to flip the images. If the DWIs seem correct, it might be better to flip the b vectors.

Fixing Problems

There are three ways to correct tensor orientation problems, each of which comes at a different point in the pipeline:

  1. Transform the b vectors before converting the DWIs to MRIimage
  2. Transform the MRIimage DWIs before fitting the tensors
  3. Transform the tensors in place before computing tensor measures and the tractogram

There are pros and cons to each approach. In the short term, when you've discovered an orientation problem and are trying to fix it, the last option has the lowest cost. In the long term, when you already know the orientation problem and want to fix it automatically for each dataset coming from a particular collaborator, the first two options have lower cost. Therefore it's advised that you transform the tensors in place when checking a fix, but once you've confirmed the orientation problem and how to fix it, it's advised that you code up a change to the b vectors or the DWIs.

... by Transforming the b Vectors

By transforming the b vectors before converting the original DWIs from the source format to MRIimage, you avoid transforming the images and instead change the coordinate frame for the b vectors to correspond to the coordinate frame for the images. This operation makes the assumption that the coordinate frame for the images is the "true" one and that there is some error in the coordinate frame for the b vectors. There may be a genuine problem with the images, though (for example, if they use a left-handed coordinate system); in which case transforming the images is the correct thing to do. Transforming the b vectors is also faster than transforming the images.

/map/gfx0/common0/diffusion/Interface/bin/data/mri_io.py has handy tools for I/O involving bvecs files. Though no command-line tool has yet been created to transform b vectors, here's an example that flips the y component (in Python):

from mri_io import *
bvecfname = findUpward('.', 'bvecs')
fid = open(bvecfname, 'r')
vecs = parseBvecs(fid.read())
fid.close()
for i in range(len(vecs)):
	vecs[i][1] = -1.0 * vecs[i][1]
fid = open('bvecs.yflipped', 'w')
writeBvecs(vecs, fid)
fclose(fid)

... by Transforming the DWIs

As discussed above, transforming the DWIs is more computationally expensive than transforming the b vectors. Due to conflicting "standards" for medical imaging coordinate systems, though, sometimes it actually does make sense to transform the DWIs instead. Transforming the DWIs makes the assumption that the coordinate frame for the b vectors is the "true" one, and that there is some error in the coordinate frame for the DWIs.

mritransp can perform dimension permutations and flips on DWIs. Here's an example that flips the y dimension in a collection of DWIs (in tcsh):

mkdir -p dwi/flipped
foreach n ( `/bin/ls dwi/original` )
	mkdir dwi/flipped/$n
	mritransp -i dwi/original/$n -o dwi/flipped/$n -flipy
end

... by Transforming the Tensors

Transforming the tensors in a DTI is equivalent to transforming the b vectors, and so makes the same assumption that the coordinate frame of the DWIs is the "true" one and that there was some error with the coordinate frame of the b vectors. It has the downside of being more computationally expensive than either of the previous techniques, though if you've already computed the tensors, it is more immediately expedient.

mritensormult can perform general transformations on all the tensors in a DTI, leaving the tensors in the same positions but changing their values in place. Here's an example that flips the y dimension in a DTI:

cd voxel_models; mv tensors original_tensors
mritensormult -i voxel_models/original_tensors -o voxel_models/tensors -mat 1 0 0 0 -1 0 0 0 1

Automatic Diagnosis

Automatic diagnosis is beyond our grasp at the moment but in principle it's not impossible, given certain assumptions about the structure that generated the data (that is, that it's a brain). This might be a neat project for someone.