Diagnose tensor orientation problems: Difference between revisions

From VrlWiki
Jump to navigation Jump to search
Jadrian Miles (talk | contribs)
Jadrian Miles (talk | contribs)
Line 40: Line 40:


== Fixing Problems ==
== Fixing Problems ==
There are two ways to correct tensor orientation problems: you can either transform each tensor in place, or you can transform all the DWIs and then re-fit the tensors.  '''Transforming the DWIs''' is cheaper than '''transforming the tensors''', which is cheaper than '''fitting the tensors'''.  Therefore there are pros and cons to each approach.
There are three ways to correct tensor orientation problems, each of which comes at a different point in the pipeline:
# Transform the b vectors before converting the DWIs to MRIimage
# Transform the MRIimage DWIs before fitting the tensors
# 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 option has the lowest costTherefore 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.
 
=== ... by Transforming the b Vectors ===
<code>/map/gfx0/common0/diffusion/Interface/bin/data/mri_io.py</code> 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):
<pre>
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)
</pre>


=== ... by Transforming the DWIs ===
=== ... by Transforming the DWIs ===
<code>$G/bin/mritransp</code> can perform dimension permutations and flips on DWIs.
<code>mritransp</code> can perform dimension permutations and flips on DWIs. Here's an example that flips the y dimension in a collection of DWIs (in tcsh):
* '''Long-Term Advantage:''' the next time you get a dataset from the same protocol, you can fix the orientation problem cheaply at the DWI stage and then the tensors that you fit to the DWIs will be correct.
<pre>
*; {{infobox|Total processing (long term) <nowiki>=</nowiki> transform DWIs + fit tensors}}
mkdir -p dwi/flipped
* '''Immediate Disadvantage:''' when you discover the orientation problem for a single dataset, you have already fit the tensors, so fixing it by modifying the DWIs means you will have to re-fit the tensors, which takes time.
foreach n ( `/bin/ls dwi/original` )
*; {{infobox|Total processing (short term) <nowiki>=</nowiki> transform DWIs + fit tensors}}
mkdir dwi/flipped/$n
mritransp -i dwi/original/$n -o dwi/flipped/$n -flipy
end
</pre>


=== ... by Transforming the Tensors ===
=== ... by Transforming the Tensors ===
<code>$G/bin/mritensormult</code> can perform general transformations on all the tensors in a DTI, leaving the tensors in the same positions but changing their values in place.
<code>mritensormult</code> 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:
* '''Long-Term Disadvantage:''' the next time you get a dataset from the same protocol, the same orientation problem will probably be present, and so you will have to correct it, and transforming the tensors is expensive.
<pre>
*; {{infobox|Total processing (long term) <nowiki>=</nowiki> fit tensors + transform tensors}}
cd voxel_models; mv tensors original_tensors
* '''Immediate Advantage:''' when you discover the orientation problem for a single dataset, you don't have to re-fit the tensors, which means that you can quickly move on to the next step in the [[Diffusion Processing Pipeline|pipeline]] without waiting.
mritensormult -i voxel_models/original_tensors -o voxel_models/tensors -mat -1 0 0 0 1 0 0 0 1
*; {{infobox|Total processing (short term) <nowiki>=</nowiki> transform tensors}}
</pre>


== Automatic Diagnosis ==
== Automatic Diagnosis ==

Revision as of 20:24, 15 July 2009

Sometimes when processing diffusion MRI data, the DWIs come to us flipped or 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. X 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 tensors have three-way mirror symmetry (that is, orientation but not direction 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.

HOWTO Detect 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.

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 option has the lowest 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.

... by Transforming the b Vectors

/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

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

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.