diff --git a/src/antsTransform.cxx b/src/antsTransform.cxx index 4fde0f1c..3c557cae 100644 --- a/src/antsTransform.cxx +++ b/src/antsTransform.cxx @@ -128,7 +128,7 @@ AntsTransform antsTransformFromDisplacementField( AntsImage -AntsImage antsTransformToDisplacementField( AntsTransform & xfrm, +AntsImage antsTransformToDisplacementField( AntsTransform & xfrm, AntsImage> & ref ) { //typedef itk::Transform TransformType; @@ -246,6 +246,16 @@ void local_antsTransform(nb::module_ &m) { m.def("transformImage", &transformImage, itk::Image>); m.def("transformImage", &transformImage, itk::Image>); + // displacement field transforms + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("transformImage", &transformImage, itk::Image>); + m.def("inverseTransform", &inverseTransform, itk::Transform>); m.def("inverseTransform", &inverseTransform, itk::Transform>); m.def("inverseTransform", &inverseTransform, itk::Transform>); @@ -286,7 +296,7 @@ void local_antsTransform(nb::module_ &m) { m.def("antsTransformToDisplacementField", &antsTransformToDisplacementField, itk::VectorImage,float,2>); m.def("antsTransformToDisplacementField", &antsTransformToDisplacementField, itk::VectorImage,float,3>); - + nb::class_>>(m, "AntsTransformDF2"); nb::class_>>(m, "AntsTransformDF3"); nb::class_>>(m, "AntsTransformF22"); diff --git a/tests/test_core_ants_transform.py b/tests/test_core_ants_transform.py index f6aef044..4b195ced 100644 --- a/tests/test_core_ants_transform.py +++ b/tests/test_core_ants_transform.py @@ -175,6 +175,15 @@ def test_apply_ants_transform_to_image(self): tx.set_parameters((0.9,0,0,1.1,10,11)) img2 = ants.apply_ants_transform_to_image(tx, img, img) + def test_apply_ants_transform_to_image_displacement_field(self): + img = ants.image_read(ants.get_ants_data("r27")).clone('float') + img2 = ants.image_read(ants.get_ants_data("r16")).clone('float') + reg = ants.registration(fixed=img, moving=img2, type_of_transform="SyN") + tra = ants.transform_from_displacement_field(ants.image_read(reg['fwdtransforms'][0])) + deformed = tra.apply_to_image(img2, reference=img) + deformed_aat = ants.apply_transforms(img, img2, reg['fwdtransforms'][0], singleprecision=True) + nptest.assert_allclose(deformed.numpy(), deformed_aat.numpy(), atol=1e-6) + def test_invert_ants_transform(self): img = ants.image_read(ants.get_ants_data("r16")).clone('float') tx = ants.new_ants_transform(dimension=2)