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
638 stars 162 forks source link

WIP: Time-varying transform for landmarks. #415

Closed ntustison closed 1 year ago

ntustison commented 1 year ago

Hey @stnava ,

When you get some time, it would be great if you could take a look. I think I'm close on this one.

import ants
import numpy as np
fixed = np.array([[50.0,50.0],[200.0,50.0],[200.0,200.0]])
moving = np.array([[50.0,50.0],[50.0,200.0],[200.0,200.0]])
domain_image = ants.image_read(ants.get_ants_data("r16"))
xfrm = ants.fit_transform_to_paired_points(moving, fixed, transform_type="tv", 
   domain_image=domain_image, number_of_fitting_levels=5, composition_step_size=10.0,
   number_of_integration_points=4)
grid = ants.create_warped_grid(domain_image)

xfrm_forward = ants.transform_from_displacement_field(ants.integrate_velocity_field(xfrm, 0, 1))
ants.plot(ants.apply_ants_transform_to_image(xfrm_forward, grid, grid))

xfrm_inverse = ants.transform_from_displacement_field(ants.integrate_velocity_field(xfrm, 1, 0))
ants.plot(ants.apply_ants_transform_to_image(xfrm_inverse, grid, grid))
ntustison commented 1 year ago

Hey @stnava, I think this is working now (as well as the one over in ANTsR). I'll probably add a verbose for the diffeo transforms but that'll be a future commit. Note that I had to update both the ITK and ANTs tag so I hope I didn't cause any problems there.