ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
625 stars 161 forks source link

ants.apply_transforms(..., compose=...) cannot write hdf5 displacement field. Only nii.gz possible #475

Closed MSco closed 5 months ago

MSco commented 1 year ago

Is your feature request related to a problem? Please describe. .nii.gz is a format, that cannot deal with very large data. It would be nice to be able to write hdf5 displacement fields instead of nii.gz. antsApplyTransforms itself makes this possble, but the python wrapper function ants.apply_transforms can only write .nii.gz. It is quite easy to let the developer decide, which kind of displacement field format he would like to create.

Describe the solution you'd like In ants.apply_transforms, just replace the line

tfn = '%scomptx.nii.gz' % compose if compose is not None else 'NA'

with

if compose:
    tfn = '%scomptx.nii.gz' % compose if not compose.endswith('.h5') else compose
else:
    tfn = 'NA'

Using this solution. The developer can use ants.apply_transforms(..., compose="path/to/my/dispfield.h5") to create an hdf5 displacement field. Using the old code instead, this would just create the following displacement field: "path/to/my/dispfield.h5comptx.nii.gz", which is a .nii.gz.

stnava commented 1 year ago

can you try this , test it and make a pull request?

MSco commented 1 year ago

Tested it successfully and created pull request #476

cookpa commented 1 year ago

Fixed by #476?