# Using the invert displacement field function

**URL:** <https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768>\
**Category:** Development\
**Tags:** transforms\
**Created:** [November 15, 2018, 6:35pm UTC](https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768 "2018-11-15T18:35:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RuurdK](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RuurdK](https://discourse.slicer.org/u/RuurdK)\
**Post date:** [November 15, 2018, 6:35pm UTC](https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768/1 "2018-11-15T18:35:13Z")

</div>

Dear all,

I have been using the invert button in the Transforms module to invert displacement fields which I can regrettably only derive as a forward transform. Now I am trying to replicate this inversion using ITK or SimpleITK functions, such as InverseDisplacementField, InvertDisplacementField, FixedPointInverseDisplacementField and IterativeInverseDisplacementField. However, I am never able to replicate the results I get through Slicer. If someone could explain which algorithm Slicer uses I would be most grateful.

Thanks in advance,

RK

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 15, 2018, 6:41pm UTC](https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768/2 "2018-11-15T18:41:33Z")

</div>

Slicer uses [VTK’s transform classes](https://www.vtk.org/doc/nightly/html/classvtkAbstractTransform.html), which are far more versatile than ITK (SimpleITK):

- you can concatenate arbitrary chain of forward/inverse transforms and VTK can apply it to objects dynamically
- VTK transforms provide transformation on the entire 3D space (while in ITK transforms, displacement drops to 0 outside the specified domain)
- VTK ensures displacement is smoothly converging 0 or constant outside the specified domain, which allows robust inverse computation.

If you need an inverse transform that ITK can use, you can convert the transform to a displacement field (in Transforms module / Convert section).

---

<div class="post-metadata">

**Author:** ![RuurdK](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RuurdK](https://discourse.slicer.org/u/RuurdK)\
**Post date:** [November 15, 2018, 7:10pm UTC](https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768/3 "2018-11-15T19:10:11Z")

</div>

Thank you for your quick and comprehensive answer. I had been looking into the VTK classes but had some trouble loading the .nrrd files which my code outputs. I will look into this again and report back with the results.

R

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 15, 2018, 7:18pm UTC](https://discourse.slicer.org/t/using-the-invert-displacement-field-function/4768/4 "2018-11-15T19:18:58Z")

</div>

Slicer can load a vector field into a transform node (and inside it as a VTK grid transform) from .nrrd file: in the “Add data…” dialog, choose to load it as a “Transform” (in “Description” column).
