ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.19k stars 380 forks source link

Problem when creating FA map after Warping and reorienting a DT image #1003

Closed stremblay18 closed 4 years ago

stremblay18 commented 4 years ago

Hi,

After reviewing literature on registration of diffusion MRI data, I've realized that registering the tensor image is better, as it allows to use orientational, as well as spatial, information during registration (I had previously applied registration on my FA and MD maps).

I followed the steps outlined here: https://github.com/ANTsX/ANTs/wiki/Warp-and-reorient-a-diffusion-tensor-image, and I started by testing the deformation and reorientation with a simple affine transformation (so no warps combination is necessary) on one subject. I used antsRegistration to compute my affine transform using the b0 image as the moving image and a UNI image (MP2RAGE) as the fixed, and then applied it to the tensor image using antsApplyTransforms. These are my lines of code:

antsApplyTransform -d 3 -e 2 -o tensor_deformed.nii.gz -i dtAnts.nii.gz -t b0_reg2UNI_rigid_Affine_0GenericAffine.mat -r UNI_image.nii.gz -f 0.0007

ReorientTensorImage 3 tensor_deformed.nii.gz tensor_reoriented.nii.gz b0_reg2UNI_rigid_Affine_0GenericAffine.mat

Before applying the transform, I ensured my tensor image was in the appropriate format as described here: https://github.com/ANTsX/ANTs/wiki/Importing-diffusion-tensor-data-from-other-software. After following those steps, PrintHeader indicated the appropriate intent code (1005) and dimensions: dim[0] = 5, the x,y,z dimensions of the image, and dim[4] = 1, dim[5] = 6, dim[6] = 1, dim[7] = 1. When overlaying the registered tensor image (deformed and reoriented) on the UNI image, it looks fine, it seems reasonably well aligned, although I'm unsure what a tensor image should look like exactly... However, when I computed FA (tensor2metric in Mrtrix) from that dtReoriented.nii.gz image, it looks completely wrong, the whole map is white (1 everywhere in the brain). I'm unsure where it went wrong. I thought the issue could be due to using an mrtrix function to compute FA on a DT image in ANTs format so I tried with ImageMath. I used 3 as a dimension because that's the only number the function allowed but if I understood the previous steps correctly, the DT image is now a 5D matrix, no? Is there an additional step that has to be done before computing scalar metrics (FA, MD, AD, RD) on the reoriented tensor? This is my line of code to compute FA:

ImageMath 3 FA_image.nii.gz TensorFA Reoriented_dt.nii.gz

The FA maps generated look wrong, with values near 1.0 everywhere. I tried using linear interpolation in log space with -f 0.0007 as suggested in the wiki and I also tried with Nearest Neighbor. Both yield very similar FA maps. I've attached screenshots of the tensor registered to UNI (overlayed on the UNI image) and of the FA that was then computed with the the 2 types of interpolation.

Here is an image of the tensor registered to UNI (overlayed on the UNI image) with linear interpolation in log space with -f 0.0007: Tensor_linearlog_reg2UNI The FA that was computed from it: FA_Tensor_linearlog_reg2UNI

The tensor registered to UNI (overlayed on the UNI image) with nearest neighbor interpolation: Tensor_NearestNeighbor_reg2UNI And the FA that was computed from it: FA_Tensor_NearestNeighbor_reg2UNI

Thank you for your help,

Stéfanie Tremblay PhD student Concordia University

ntustison commented 4 years ago

Thanks for posting this here. @cookpa is our resident DTI expert and probably wrote the wiki page so I'll wait for him to answer. But, in the meantime, can you post the T1 and DTI images so that we can make sure all the steps are producing the expected output?

cookpa commented 4 years ago

I only have a phone right now and can’t look into this in detail yet, but one thing that produces scrambled images is having the tensor component ordering wrong for the software that computes FA. ITK expects nifti tensors to be in lower triangular order.

For ImageMath TensorFA etc, the correct dimension is 3. It knows that a 3D tensor image has 6 components, the 3 is for the number of spatial dimensions.

stremblay18 commented 4 years ago

Hi,

Thank you for the quick responses.

The DT image I used to produce the FA image is in lower triangular order, I followed the steps of the "Importing diffusion tensor data from other software" Wiki to convert my tensor (initially a 4D image with dim[0]=4, the x,y,z dimensions of the image, and dim[4] = 6, dim[5] = 1, dim[6] = 1, dim[7] = 1) to this format (dim[0] = 5, the x,y,z dimensions of the image, and dim[4] = 1, dim[5] = 6, dim[6] = 1, dim[7] = 1 with intent code 1005).

Thank you for clarifying the dimensions for using ImageMath TensorFA, it makes sense now.

Here is the link to a sample of my data: https://drive.google.com/open?id=1_t01HCdWw94i9LVVn1jItfvWhLtwOjJZ

You will find the tensor image before converting it to the ANTs format, the tensor in ANTs format, my UNI image to which I want to register my tensor, the deformed and reoriented tensor (with the 2 types of interpolation I've tried) and FA maps that I computed from it.

Best,

Stéfanie

ntustison commented 4 years ago

I forgot that @cookpa is otherwise occupied with personal matters so let me see if I can help.

It would facilitate matters if you renamed the data so that it can be easily identified--short and simple names. Also, it would help if the commands that you specified correspond to the file names you used. And I don't see the transformation files. Although things might seem obvious to you, we are coming at this without as much familiarity with the situation.

Basically, I want to be able to click on a link to download your data, cd to that data directory, and simply copy-and-paste your commands into my terminal window to be able to check the output for each step.

stremblay18 commented 4 years ago

Hi,

Here is a new link with the renamed data: https://drive.google.com/open?id=11m82UUUPjSFhUKWohjoO0B5ZEP0A5ZlB

And my commands again, with the correct file names:

To convert my tensor image to the format supported by ANTs:

ImageMath 4 dtiComp.nii.gz TimeSeriesDisassemble tensorimg.nii.gz i=0 for index in xx xy xz yy yz zz; do mv dtiComp100${i}.nii.gz dtiComp${index}.nii.gz i=$((i+1)) done ImageMath 3 dtAnts.nii.gz ComponentTo3DTensor dtiComp_

To apply the Generic Affine transform to the tensor image (computed with antsRegistration, using the b0 image as the moving image and the UNI as the fixed image, with rigid and affine transforms with MI as a similarity metric; let me know if you need to see this script)

antsApplyTransform -d 3 -e 2 -o tensor_deformed_linear_log.nii.gz -i dtAnts.nii.gz -t GenericAffine.mat -r UNI_img.nii.gz -f 0.0007 And: antsApplyTransform -d 3 -e 2 -o tensor_deformed_NearestNeighbor.nii.gz -i dtAnts.nii.gz -t GenericAffine.mat -r UNI_img.nii.gz -n NearestNeighbor

Reorienting tensor:

ReorientTensorImage 3 tensor_deformed_linear_log.nii.gz tensor_reoriented_linear_log.nii.gz GenericAffine.mat And: ReorientTensorImage 3 tensor_deformed_NearestNeighbor.nii.gz tensor_reoriented_NearestNeighbor.nii.gz GenericAffine.mat

Computing FA:

ImageMath 3 tensor_reoriented_linear_log_FA.nii.gz TensorFA tensor_reoriented_linear_log.nii.gz And: ImageMath 3 tensor_reoriented_NearestNeighbor_FA.nii.gz TensorFA tensor_reoriented_NearestNeighbor.nii.gz

I apologize for not providing the appropriate info/data, it's the first time I post an issue on this type of platform. Please let me know if you would need anything else.

I really appreciate your help, thank you,

Stéfanie

ntustison commented 4 years ago

Okay, so the first thing to check is the DTI conversion before reorientation. Specifically, did you look at, for example, the FA image

ImageMath 3 FA.nii.gz TensorFA dtAnts.nii.gz 

This looks wrong and seems that maybe the component definition is incorrect from the original file. What's the source of tensor_img.nii.gz?

stremblay18 commented 4 years ago

Hi Nick,

You were right, the problem was in the conversion of the tensor. My tensor image comes from Mrtrix (dwi2tensor) which orders tensor components as such: xx, yy, zz, xy, xz, yz which is different from the order ANTs expects (xx xy xz yy yz zz). I should have checked that earlier, thank you for pointing it out. The components were thus mislabeled. I fixed this by changing this line of code:

for index in xx xy xz yy yz zz; do

To this:

for index in xx, yy, zz, xy, xz, yz; do

The FA image that is then generated from the resulting dtAnts tensor is in the expected range.

Another question: I am used to Mrtrix for dealing with DTI metrics, so I'm wondering if the TensorColor option (in ImageMath) is the equivalent of the vector option in Mrtrix (which produces a colored map showing the principal diffusion direction where red indicates L-R diffusion, green ant-post and blue sup-inf)? If it is, how can you view it in FSLeyes? I get a greyscale map when viewing the tensorColor image in FSLeyes.

Best,

Stéfanie

ntustison commented 4 years ago

If you're going to look at ANTs results, you should really use ITK-SNAP (www.itksnap.org). There are some known incompatibilities with the way FSL and ITK/ANTs use image headers and that could lead to problems in looking at the results. But, yes, I'm guessing TensorColor is meant to have the same functionality as the Mrtrix vector option.

cookpa commented 4 years ago

Thanks I will update the Wiki when I can.

For a vector image to load into fsleyes, you want ImageMath ExtractVectorComponent.

Different software can have different conventions for storage, as you’ve seen, but also for display. So if the vectors look wrong in FSL it’s not necessarily a problem with ITK or mrtrix.

Sent from my iPhone

On May 19, 2020, at 3:02 PM, stremblay18 notifications@github.com wrote:



Hi Nick,

You were right, the problem was in the conversion of the tensor. My tensor image comes from Mrtrix (dwi2tensor) which orders tensor components as such: xx, yy, zz, xy, xz, yz which is different from the order ANTs expects (xx xy xz yy yz zz). I should have checked that earlier, thank you for pointing it out. The components were thus mislabeled. I fixed this by changing this line of code:

for index in xx xy xz yy yz zz; do

To this:

for index in xx, yy, zz, xy, xz, yz; do

The FA image that is then generated from the resulting dtAnts tensor is in the expected range.

Another question: I am used to Mrtrix for dealing with DTI metrics, so I'm wondering if the TensorColor option (in ImageMath) is the equivalent of the vector option in Mrtrix (which produces a colored map showing the principal diffusion direction where red indicates L-R diffusion, green ant-post and blue sup-inf)? If it is, how can you view it in FSLeyes? I get a greyscale map when viewing the tensorColor image in FSLeyes.

Best,

Stéfanie

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ANTsX/ANTs/issues/1003#issuecomment-631020028, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEVJM5BAELZ72HXTOZFHV3RSLJSXANCNFSM4NEI4GVQ.

cookpa commented 4 years ago

Unfortunately ITK-SNAP allows RGB overlay but not the vector lines, which is necessary for checking tractography because the color mapping is not unique over the hemisphere.

Sent from my iPhone

On May 19, 2020, at 3:18 PM, Nick Tustison notifications@github.com wrote:



If you're going to look at ANTs results, you should really use ITK-SNAP (www.itksnap.orghttp://www.itksnap.org). There are some known incompatibilities with the way FSL and ITK/ANTs use image headers and that could lead to problems in looking at the results. But, yes, I'm guessing TensorColor is meant to have the same functionality as the Mrtrix vector option.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ANTsX/ANTs/issues/1003#issuecomment-631028752, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEVJM6KGAXQVCKKXD36QFLRSLLOZANCNFSM4NEI4GVQ.

stremblay18 commented 4 years ago

Ok thank you both. So would you suggest viewing the output of ImageMath ExtractVectorComponent in FSLeyes (or perhaps Mrview) to check directions @cookpa? I usually only use those vector outputs as a sanity check as I don't do tractography because of too few acquisition directions (20).

stremblay18 commented 4 years ago

Also, if I don't specify the interpolation but I specified -e 2 to indicate the input is a tensor, will the default interpolation be linear in log space? I added the -f 0.0007 option.

cookpa commented 4 years ago

Yes linear in log space

Sent from my iPhone

On May 19, 2020, at 10:38 PM, stremblay18 notifications@github.com wrote:



Also, if I don't specify the interpolation but I specified -e 2 to indicate the input is a tensor, will the default interpolation be linear in log space? I added the -f 0.0007 option.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ANTsX/ANTs/issues/1003#issuecomment-631199280, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEVJM5HDN45PLIHXWWQ7K3RSM7DLANCNFSM4NEI4GVQ.

cookpa commented 4 years ago

I've updated the Wiki with mrtrix info, and will edit a bit more to try to make this all a bit easier to work on. Thanks