Skip to content

Instantly share code, notes, and snippets.

@satra
Created July 21, 2011 00:50
Show Gist options
  • Save satra/1096274 to your computer and use it in GitHub Desktop.
Save satra/1096274 to your computer and use it in GitHub Desktop.
combining bbregister, fsl and ants to warp functional images

ANTS : http://picsl.upenn.edu/ANTS/ c3d : http://www.itksnap.org/pmwiki/pmwiki.php?n=Convert3D.Convert3D

export PATH=/software/ANTS-dev:$PATH

c3d_affine_tool -ref [A] -src [B] bbreg.mat -fsl2ras -oitk fsl2antsAffine.txt

WarpImageMultiTransform 3 [B] [C] -R [D] [A_Warp].nii.gz [A_Affine].txt fsl2antsAffine.txt
  • A = your structural brain/orig.mgz, but converted to nii. you should already have this in your ANTS output
  • B = con/t/z image that you want to warp
  • bbreg.mat = when your bbregister node has out_fsl_file = True
  • C = warped con/t/z image
  • D = ANTS template or other template to which you computed the ANTS warp (unless you have another affine transform see note below)
  • A_Warp = should equal the Warp fields from running ANTS, they should be called sth_Warp[xyz]vec.nii.gz. you simply need to provide sth_Warp.nii.gz
  • A_Affine = there should also be an affine transform in the place where ANTS was run.

Note

if you also have an affine transform using flirt for your own template to MNI space and you did not use the MNI spaced template as your target

c3d_affine_tool -ref [E] -src [D] flirt.mat -fsl2ras -oitk fsl2antsTemplateAffine.txt

WarpImageMultiTransform 3 [B] [C] -R [E] fsl2antsTemplateAffine.txt [A_Warp].nii.gz [A_Affine].txt fsl2antsAffine.txt
  • E = template in MNI space after flirting
@conge
Copy link

conge commented Jul 31, 2013

Hi Satra,

First of all, thank you for this file, it helped me in finding ways to bridge FSL and ANTS. But I have a question about WarpImageMultiTransform which I could not find the answer by reading the output of WarpImageMultiTransform --help. If you can help me with it that will be great!

Below, I put a summary of my understanding of your code and then my question. Could please take a look?

Purpose:

Register B to E.

Steps:

  1. B to A with bbr, get bbreg.mat
  2. A to D, get A_Warp and A_Affine
  3. D to E, get flirt.mat
  4. transform bbreg.mat and flirt.mat from FSL format to a format that ANTS can use with c3d_affine_tool.
  5. B to E by applying transformation matrix and Warp with WarpImageMultiTransform.

C is the output of the registration.

Question:

I figured the order of the transformation matrix and warp files are important for WarpImageMultiTransform. Do you know where I can find the documentation on how to organize the transform matrix and warp files?

Thanks,

Yang

@satra
Copy link
Author

satra commented Aug 2, 2013

the ants.pdf file on their webpage is the best place to get such information. although ants has moved along so that now you can combine all transforms into a single file directly and use antsApplyTransforms

@sgiavasis
Copy link

Hi Satra,

Thanks for this guide, it has helped quite a bit.

I have a question - do we know how c3d_affine_tool handles 4D functional files for its source (-src) input?

Let's say we want to register a 4D functional to a template, and we pass a 4D file to c3d_affine_tool's source input in order to produce a converted affine for use in WarpTimeSeriesImageMultiTransform (as opposed to the regular 2D/3D WarpImageMultiTransform) . When I try this and use this converted affine, the warp produces a blank output along the entire timeseries.

Now, let's say we try using a mean functional file (no timeseries) as c3d_affine_tool's source in order to produce an affine which will be used to warp a 4D file - this converted affine actually "works" with WarpTimeSeries and produces a nice-looking warped 4D file which overlays over the template perfectly. However, this warped 4D file correlates poorly with the output of FSL's ApplyWarp using the same subject and same functional-to-anatomical affine (albeit remaining in its original FSL format).

I am wondering if this is something known and there is a specific way to handle this, or if I should follow up with the ITK group. Thanks!

Steve

@9999sotelom
Copy link

Hi Satra,

I am also wondering about this question.
I like the results from ANTs in registering lesioned images to reference. I would like to use these ANTs' warp field outputs in fsl's probtrackx2 for a tractography analysis. However, testing the warp field on the moving image to the fixed image using fsl's applywarp does not yield a good registration alignment. I read in the fsl email discussion in jiscmail that the discrepancy is in the different ways warp fields are created and defined in different software, and that the discrepancy is not resolved (2015). I read in Sitek et al (2016) that they used the ANTs-obtained registration in fsl's probtrackx2 algorithm. I am wondering if the there is now a way to use ANTs registration in fsl.

Thank you very much!

Miguel

@anbai106
Copy link

@satra @9999sotelom

Hi,

I have a similar use case:

I applied a rigid+deformable transformation for my b0 image to map it on my T1 image.

Now I want to transfer the warp image in ANTS format into FSL format???

I know I can do the inverse using c3d to transfer FSL format into ANTS, but it works only for affine registration, not for non-linear registration.

Do you have any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment