ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.2k stars 381 forks source link

antsApplyTransforms resulting in severe distortions in fMRI data set #1366

Closed casparms closed 2 years ago

casparms commented 2 years ago

Describe the problem

I am trying to apply nonlinear volumetric transforms computed with antsRegistration to an fMRI data set. Part of the data (behind the orbit in one hemisphere) is subsequently severely distorted. The same transforms work well on anatomical data sets.

To Reproduce

Registration, seems to work fine. antsRegistration --dimensionality 3 --float 0 --output \ [${outputStem},${outputStem}Warped.nii.gz] --interpolation \ Linear --winsorize-image-intensities [0.005,0.995] --use-histogram-matching $useHistogramMatching \ ${initXfmString} --transform Rigid[0.1] \ --metric MI[${referencePath},${inputPath},1,32,Regular,0.25] --convergence [1000x500x250x100,1e-6,10] \ --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[0.1] \ --metric MI[${referencePath},${inputPath},1,32,Regular,0.25] --convergence [1000x500x250x100,1e-6,10] \ --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[0.1,3,0] \ --metric CC[${referencePath},${inputPath},1,4] --convergence [100x70x50x20,1e-6,10] \ --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox ${maskString}

Application antsApplyTransforms -d 3 -e 3 -z 1 -i {1}/${funcfile} -r ${regdir}/funcTemplate2atlas_Warped.nii.gz -n Linear \ -t ${regdir}/freesurfer2atlas_warp.nii.gz -t ${regdir}/funcTemplate2atlas_antsformat.mat \ -o {1}/fmc_atlas.nii.gz -v 1

Results in bad distortions. Including or excluding z does not make a difference. Using Linear or NearestNeighbor for n does not make a difference. nii or nii.gz as input or output does not make a difference. A screenshot is available here: https://owncloud.dpz.eu/index.php/s/dRsfyikxcflhzJQ

System information (please complete the following information)

ANTs version information

Additional information

cookpa commented 2 years ago

To protect code from markdown formatting, enclose in triple backticks

like this

What are the fixed and moving images?

casparms commented 2 years ago

I am computing a registration between a T1 that has been downsampled to fMRI resolution to an atlas. I am then applying this transform to the fMRI time series.

cookpa commented 2 years ago

OK. So the issue is that ${outputStem}Warped.nii.gz looks correct, but the functional image does not?

To apply a transform derived from one moving image to another image, the other image must be in the same physical space as the registration moving image. So verifying that is the first step.

I can't really follow the code posted above, can you try again using verbatim formatting? Better yet, a reproducible example with code and data would allow us to help most effectively.

casparms commented 2 years ago

Yes, ${outputStem}Warped.nii.gz looks correct, but the functional image does not. I think the issue might be that there is a slight misalignment between the T1 that has been downsampled to fMRI resolution and the fMRI data set. I guess I could compute the registration matrix between these two and add this to my antsApplyTransforms?

antsApplyTransforms -d 3 -e 3 -z 1 -i {1}/{regdir}/funcTemplate2atlas_Warped.nii.gz -n Linear
-t {regdir}/funcTemplate2atlas_antsformat.mat
-o {1}/fmc_atlas.nii.gz -v 1
cookpa commented 2 years ago

Yes, you would want to register the fmri to the t1w with a suitable transform, and verify that this puts the fmri image into the space of the T1w. Then you can call antsApplyTransforms with additional transforms (-t). Something like

-r funcTemplate2atlas_Warped.nii.gz -t funcTemplate2atlas_1Warp.nii.gz -t funcTemplate2atlas_0GenericAffine.mat -t boldToT1w0GenericAffine.mat

assuming you did rigid registration from the bold to t1w.

I don't know what the -z option to antsApplyTransforms does on the command line, but the usage says it's for R, so I would leave that out unless you know what you're doing.