# transform point with inverse bspline

**URL:** https://discourse.itk.org/t/transform-point-with-inverse-bspline/5248
**Category:** Algorithms
**Created:** [August 8, 2022, 9:02am UTC](https://discourse.itk.org/t/transform-point-with-inverse-bspline/5248 "2022-08-08T09:02:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ilay\_Kamai](https://discourse.itk.org/user_avatar/discourse.itk.org/ilay_kamai/32/2875_2.png) [@Ilay\_Kamai](https://discourse.itk.org/u/Ilay_Kamai)
#### Post date: [August 8, 2022, 9:02am UTC](https://discourse.itk.org/t/transform-point-with-inverse-bspline/5248/1 "2022-08-08T09:02:54Z")

</div>

Hi,  
i’m trying to transform 3D points using inverse displacement field of Bspline transformation.  
after calculating the transformation i’m creating the inverse as suggested here : [Inverse of BSpline transform](https://discourse.itk.org/t/inverse-of-bspline-transform/496)  
this is my code:

```auto
disp_filter = sitk.TransformToDisplacementFieldFilter()
disp_img = disp_filter.Execute(outx)
inv_disp_filter = sitk.InverseDisplacementFieldImageFilter()
inv_disp_filter.SetReferenceImage(ref_img)
inv_disp_img = inv_disp_filter.Execute(disp_img)
return sitk.DisplacementFieldTransform(inv_disp_img), disp_img

```

however, when trying to use TransformPoint nothing happens (point is not transformed). the points are inside the Domain. what am i doing wrong?  
thanks!

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [August 8, 2022, 1:46pm UTC](https://discourse.itk.org/t/transform-point-with-inverse-bspline/5248/2 "2022-08-08T13:46:07Z")

</div>

Hello @Ilay_Kamai,

The problem is due to missing settings for the `disp_filter` which is using defaults.

To create a displacement field from a transformation we need to define its physical bounds (origin, size, spacing, direction cosine matrix). This is because the transformation can be a global/unbounded transformation and a displacement field is bounded. When this isn’t done explicitly default values are used (to see this add `print(disp_img.GetSize()` to your code).

Modify the code to something like this:

```auto
output_size = 
output_spacing = 
sitk.TransformToDisplacementField(outx, outputPixelType=sitk.sitkVectorFloat64, size=output_size, outputOrigin=outx.GetTransformDomainOrigin(), outputSpacing=output_spacing, outputDirection=outx.GetTransformDomainDirection())

```

For additional details on inverting bounded transforms see the Transforms [jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/22_Transforms.ipynb). Highly recommend skimming the [SimpleITK notebooks repository](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks) to see the various examples. If you have the time, it is also worth going over the [online tutorial](https://simpleitk.org/TUTORIAL/).

---

<div class="post-metadata">

### Author: ![Ilay\_Kamai](https://discourse.itk.org/user_avatar/discourse.itk.org/ilay_kamai/32/2875_2.png) [@Ilay\_Kamai](https://discourse.itk.org/u/Ilay_Kamai)
#### Post date: [August 9, 2022, 8:00am UTC](https://discourse.itk.org/t/transform-point-with-inverse-bspline/5248/3 "2022-08-09T08:00:18Z")

</div>

thank you very much for the quick answer!
