ANTsPy
ANTsPy copied to clipboard
ants.read_transform fails for syn warp file
antspy 0.2.7
There are a couple wacky things going on with ants.read_transform
. For one, the dimension
kwarg is ignored, as dimension
is reassigned on line 293. Should make another issue for that.
Here's the bug:
tx = ants.read_transform('warp.nii.gz', dimension=3)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-34-c277abb66a46> in <module>
----> 1 tx = ants.read_transform('warp.nii.gz', dimension=3)
~/.local/lib/python3.6/site-packages/ants/core/ants_transform_io.py in read_transform(filename, dimension, precision)
291
292 libfn1 = utils.get_lib_fn("getTransformDimensionFromFile")
--> 293 dimension = libfn1(filename)
294
295 libfn2 = utils.get_lib_fn("getTransformNameFromFile")
RuntimeError: /build101/ANTsPy/itksource/Modules/IO/TransformBase/src/itkTransformFileReader.cxx:128:
itk::ERROR: itk::ERROR: TransformFileReaderTemplate(0x154c5520): Could not create Transform IO object for reading file warp.nii.gz
Tried to create one of the following:
HDF5TransformIOTemplate
HDF5TransformIOTemplate
MatlabTransformIOTemplate
MatlabTransformIOTemplate
TxtTransformIOTemplate
TxtTransformIOTemplate
You probably failed to set a file suffix, or
set the suffix to an unsupported type.
I thought this might just be an issue with getTransformDimensionFromFile
, so I tried running
read_transform = utils.get_lib_fn('readTransform%s%i' % (utils.short_ptype(precision), dimension))
tx = read_transform('warp.nii.gz', dimension, precision)
Same error.
Also tried removing the suffix, using the absolute path, using the absolute path and removing the suffix, none of that worked.
ants.apply_transform
works fine with the same file. Using ants.read_transform
because I need to apply the transform to a point.
To Reproduce
Run ants.registration
, rename syn forward warp to warp.nii.gz
(probably unnecessary), try to load transform
the intended approach is:
import ants
reg=ants.registration( ants.image_read( ants.get_data("r16" ) ), ants.image_read( ants.get_data("r16" ) ), 'SyN')
warp=ants.image_read( reg['fwdtransforms'][0] ) # image not transform
warptx = ants.transform_from_displacement_field( warp )
now you have a transformation object. 2 ways to apply to points:
help(ants.apply_transforms_to_points) # on disk transforms
and for tx objects
help( ants.apply_ants_transform_to_point )
That's very helpful, thanks.
Is there any reason we can't dispatch to transform_from_displacement_field
from read_transform
?
the objects saved in the reg['fwdtransforms'][0]
is not explicitly coded as a transformation .... so we'd have to guess that it represents an actual deformation field ......
True, but if I'm trying to read a .nii as a transform I presumably already know it's own. What do you think about dispatching and printing a warning? Or at least a more descriptive error
we would welcome any contributions that improve clarity and usability.