ANTsPy icon indicating copy to clipboard operation
ANTsPy copied to clipboard

add nibabel conversion (lacey import to prevent forced dependency)

Open robert-graf opened this issue 1 year ago • 4 comments

Adding back the convert to and from nibabel, without forcing nibabel as a dependency if never used.

There was a lot of renaming going on from 0.4 to 0.5. I would like to have the same naming scheme as in the older version for backward compatibility, but I kept it the 0.5 way as I do not know why things are renamed.

nifti_to_ants works without the image decorating. So, I also did not use the add-to-image decorator.

See: #693 #64 #52

robert-graf avatar Aug 15 '24 10:08 robert-graf

The new name is a bit confusing but I think the intent was to convey that they will convert any NIFTI image, not just nibabel. I guess the key functionality is the ability to translate an image object with an RAS transform to an ANTsImage with an LPI transform.

cookpa avatar Aug 15 '24 13:08 cookpa

Then again, while the methodology is generic, the implementation does seem to rely on having nibabel Nifti1Image objects. So I would agree the function naming of nibabel_to_ants makes most sense.

Other packages requiring RAS coordinates could call get_ras_affine_from_ants and get the voxel data via numpy.

cookpa avatar Aug 15 '24 13:08 cookpa

I missed a ants_mni.to_nibabel(), which used the 0.4 version.

And then, I noticed the given nifti_to_ants were not invariant.

The get_ras_affine_from_ants form Torchio assumes that the axis is mirrored and mirrors the original as well. The q-form does not do this; rotating the image with ants to the same orientation shows this is not invariant.

Maybe this Q-form stuff was a red herring, and that's why you had trouble writing this code.

robert-graf avatar Aug 15 '24 13:08 robert-graf

Coverage Status

coverage: 83.789% (-0.9%) from 84.726% when pulling 7dcc27f68405399d4ff3f09b75b0ca1e5b7010d7 on robert-graf:nibable_conversion into 5f550b8dc42a782195f5fb177be84c1a2f113f49 on ANTsX:master.

coveralls avatar Aug 15 '24 13:08 coveralls

Closing in favor of #877 - I renamed things back to be nibabel specific, given that the code relies explicitly on nibabel objects.

I don't use qform explicitly, instead use the nibabel image's affine matrix, which may derive from either the qform or the sform. Thus users can follow the nibabel convention for which transform to use, or apply their own logic to set the affine.

On export to nibabel, the affine matrix is set according to the ITK direction / origin / spacing. nibabel puts this in the sform, but users can use the affine to update the nibabel qform if they want.

cookpa avatar Dec 12 '25 17:12 cookpa