ANTsX / ANTs

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

ANTs and SPM compatibility #1726

Open lisajeschke opened 5 months ago

lisajeschke commented 5 months ago

I work with fmri BOLD data of a brain slab and currently encounter problems when I calculate GLMs in SPM after I have warped them into mni space using ANTs.

The warping works fine and the output looks anatomically and qualitatively correct. However, in contrast to native space images, my warped images cause SPM to display my results very frizzy/noisy, such as if my significant clusters would be very small and frizzy. I have attached two example images of my "normal" (native space, 1st image) output and the "distorted" issue (mni space with ants; 2nd image). The resolution and smoothing kernel are the same in both spaces.

Has anyone dealt with that problem before? Is it just a displaying problem?

Is there some header issue or something else that would need to be changed before I use SPM on the warped data?

nativespace mnispace

gdevenyi commented 5 months ago

Please take a look at https://github.com/ANTsX/ANTs/wiki/How-does-ANTs-handle-qform-and-sform-in-NIFTI-1-images%3F which explains how ITK/ANTs handles the coordinate systems in NIFTI imaging data.

I cannot provide a reference for how SPM handles things, but I suspect the answer is "differently". Either SPM will have to be adjusted to read things by the same conventions, or you will have to do post processing on the ANTs images to provide metadata in a convention SPM can use.

cookpa commented 5 months ago

I recommend never using statistical images to evaluate image processing quality. Look at the actual data in the template space.

There are two main issues I'm aware of:

  1. SPM does use sform_code=4, with the sform describing an affine transform to MNI space. ITK and therefore ANTs does not support this (header transforms must be rotation + voxel scaling + offset), but I think this is more of a problem for importing SPM images into ITK frameworks, whereas here we want to import ITK/ANTs images to SPM.

SPM might be OK with an image that is properly resampled into MNI space, with the sform indicating an identity transform, but

  1. There are different MNI spaces, and different references images at resolutions in each space. You need to check your MNI reference image aligns with the SPM one. The resolution might also be important, it might need the images resampled into the 2mm version of whatever MNI space it's using.

This man page might be helpful to figure out what the reference space is

https://github.com/spm/spm12/blob/03ac9473cad402407b6472228377c0167fdc54b8/spm_templates.man#L499

cookpa commented 5 months ago

BTW, ITK does not correctly write the temporal units of NIFTI images (the xyzt_units field), and has some issues with scaling of nonstandard units. I'm working on a fix https://github.com/InsightSoftwareConsortium/ITK/pull/4595.

I don't know if this has anything to do with this issue.

@lisajeschke, when you say

The warping works fine and the output looks anatomically and qualitatively correct.

Does it look correct with an ITK viewer or in SPM? What is the MNI template image for this visualization?