ANTsX / ANTs

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

Different resolution of moving image after rigid registration #1447

Closed Zntznkv closed 1 year ago

Zntznkv commented 1 year ago

Describe the problem

Hi, could anyone tell me why when I use antsRegistrationSyn - RIGID TRANSFORMATION, output resolution of moving images changed? Rigid means preservation of size, right? Im still new to image processing and this output is confusing me. I have moving image with voxel size size 0.49x0.49x3.00 mm and fixed is 0.9x0.9x0.8 mm. I would expect output image resolution of moving image to be as fixed image in any other transformation, but rigid. I will appreciate any advice, thanks.

Command: antsRegistrationSyN.sh -d 3 -f /T1.nii -m /nms.nii -o /nms_toT1 -t r

ntustison commented 1 year ago

You're correct in that one could apply a calculated rigid transform to the image header without resampling. See related ITK discussion here. However, this is not a typical application so the behavior for rigid transforms is the same as the other transform options---the warped moving image is resampled to the space of the fixed image.

gdevenyi commented 1 year ago

ANTS ignores the NIFTI sform vs qform "alignment" features, in favour of always resampling into the grid of a target space.

You can convert your ants transform into another software's format (probably with c3d) and use its features if you need that

Zntznkv commented 1 year ago

Thanks for answer. So if I resample the fixed image first (to the resolution of the moving image), will it solve my problem? And so, the result will be the same as if I resample the output of the moving image back to its resolution at the beginning? Thanks

cookpa commented 1 year ago

Resampling any image on a different grid will introduce subtle changes due to interpolation and aliasing, but that's also an issue if all the voxel spacings are identical.

You can resample your fixed space to XYZ mm after registration and use that as the reference image (-r).

ResampleImageBySpacing 3 fixed.nii.gz fixedResample.nii.gz X Y Z 0 0
antsApplyTransforms -d 3 -r fixedResample.nii.gz -i moving.nii.gz -t transform0GenericAffine.mat -o deformedResample.nii.gz -v 1

This works because you're not changing the definition of the fixed physical space, you're just changing the resolution of the grid on which that space is sampled. This is true regardless of the transform type.

When you call antsApplyTransforms like this, a grid of points at the center of voxels in the fixed space is transformed to the moving space, where an interpolated intensity is computed for each point. These interpolated intensities make the output image. Because your transform is rigid, the distance between sample points doesn't change after applying the transform. This is what we mean by a volume preserving transform. An affine or deformable registration does not preserve volumes, meaning two points in the reference image might not be the same distance apart after applying the transform.

Imagine a group of points that cover some volume of interest in the fixed space, like the thalamus. In a rigid transform, that group of points will be spaced the same way after applying the transform, and will cover the same volume (though their position can change, they can be shifted or rotated). In a non-rigid transform, the spacing can change. The transformed points might get further apart, meaning a larger volume of the moving image is covered (ie, the moving image thalamus is larger). Or the points might get closer together (the moving image thalamus is smaller).

I hope I'm making sense here, what I'm trying to say is volumes preserved in a rigid transform are the volumes of physical space, not the volumes of voxels. Voxels represent a decision about discretely sampling a signal at some space and time. The underlying space, and its transforms, are continuous.