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
629 stars 161 forks source link

compose_ants_transforms change #651

Closed ntustison closed 4 months ago

ntustison commented 4 months ago

With the recent ANTsPy changes, this random transform generator example used to work but now throws an error when trying to compose and linear and deformable ants transform as illustrated as follows:

>>> import ants
>>> import antspynet
>>> 
>>> image = ants.image_read(ants.get_ants_data("r16"))
>>> 
>>> linear_transform = ants.create_ants_transform(transform_type=
>>>     "AffineTransform", precision='float', dimension=image.dimension)
>>> 
>>> displacement_field = ants.simulate_displacement_field(image,
>>>     field_type="bspline", number_of_random_points=1000,
>>>     sd_noise=10.0, enforce_stationary_boundary=True,
>>>     number_of_fitting_levels=4, mesh_size=1,
>>>     sd_smoothing=4.0)
>>> displacement_field_xfrm = ants.transform_from_displacement_field(displacement_field)
>>> 
>>> xfrm = ants.compose_ants_transforms([linear_transform, displacement_field_xfrm])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ntustison/miniconda3/envs/antsx/lib/python3.11/site-packages/ants/core/ants_transform.py", line 415, in compose_ants_transforms
    itk_composed_tx = libfn(tx_ptr_list, precision, dimension)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: composeTransformsF2(): incompatible function arguments. The following argument types are supported:
    1. composeTransformsF2(arg0: list[ants.lib.AntsTransformF22], arg1: str, arg2: int, /) -> ants.lib.AntsTransformF22

Invoked with types: list, str, int

Is this a change in functionality, a bug, or is my recollection incorrect? Note that it would seem that currently ants.compose_ants_transforms(...) only works with linear transforms.

ncullen93 commented 4 months ago

Yes I see that the input argument type on the composeTransforms c++ function is more strictly defined now and it's causing that issue. I will try to fix it.

Although I'm not sure it worked before because everything gets casted to the same itk::Transform type in the old function also.

ncullen93 commented 4 months ago

Ok I've got a working version in a PR right now.

ntustison commented 4 months ago

Awesome. Thanks.