# Invert a ScaleVersor3DTransform

**URL:** https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483
**Category:** Beginner Questions
**Created:** [September 24, 2020, 11:17am UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483 "2020-09-24T11:17:28Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [September 24, 2020, 11:17am UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/1 "2020-09-24T11:17:28Z")

</div>

I tried to invert a ScaleVersor3DTransform, but I get this error message:

```
>>> import SimpleITK as sitk
>>> tx = sitk.ScaleVersor3DTransform()
>>> tx.SetTranslation([1,2,3])
>>> tx.SetScale([0.9, 1.1, 1.2])
>>> tx.GetInverse()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.local/lib/python3.7/site-packages/SimpleITK/SimpleITK.py", line 4628, in GetInverse
    return _SimpleITK.Transform_GetInverse(self)
RuntimeError: Exception thrown in SimpleITK Transform_GetInverse: /tmp/SimpleITK-build/ITK-prefix/include/ITK-5.1/itkScaleVersor3DTransform.hxx:202:
itk::ERROR: itk::ERROR: ScaleVersor3DTransform(0x556225fcac90): Setting the matrix of a ScaleVersor3D transform is not supported at this time.

```

This error does not sound like it can not calculate the inverse but not set the inverted matrix?  
Is there a caveat to inverting the ScaleVersor transform or could I simply invert scale, translation and rotation on my own?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 24, 2020, 1:16pm UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/2 "2020-09-24T13:16:28Z")

</div>

Hello,

It sounds like there is some missing functionality in the ITK class the should be added.

Inverting the scale, translation, and rotation with reguards to the _center_ and the composition is certainly possible, but may be tricky to get the composition and computation correctly.

The easier solution may be to convert the transform to an affine matrix and invert it. There are many examples of this in the [SimpleITK Transform Notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/22_Transforms.ipynb). Specifically the following should work:

```auto
affine = sitk.AffineTransform(3)
affine.SetMatrix(tx.GetMatrix())
affine.SetTranslation(tx.GetTranslation())
affine.SetCenter(tx.GetCenter())

```

---

<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: [September 24, 2020, 1:32pm UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/3 "2020-09-24T13:32:24Z")

</div>

Hello @reox,

Is there a specific reason that you are using the ScaleVersor3DTransform? I suspect it isn’t what you want, it isn’t the standard composition of scaling and a rigid transformation represented as a versor+translation. See section titled **Scale Versor** in the notebook @blowekamp pointed you to .

If for some reason it is what you want to do, then @blowekamp’s solution above and then calling the `GetInverse` on the affine transform should allow you to move forward.

---

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [September 24, 2020, 1:50pm UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/4 "2020-09-24T13:50:32Z")

</div>

> [@zivy](#):
>
> Is there a specific reason that you are using the ScaleVersor3DTransform? I suspect it isn’t what you want, it isn’t the standard composition of scaling and a rigid transformation represented as a versor+translation

I used Similarity3DTransform before but also wanted to try anisotropic scaling - I thought that ScaleVersor3DTransform would do the right thing?

---

<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: [September 24, 2020, 2:05pm UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/5 "2020-09-24T14:05:05Z")

</div>

Hello @reox,

Unfortunately, the name ScaleVersor3DTransform is misleading and it is not a composition of anisotropic scaling and rigid, so it isn’t what you were looking for.

The closest transform is Affine, but it also admits shearing. In a multi-step registration, you could use rigid ( [Euler3DTransform](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1Euler3DTransform.html) or [VersorRigid3DTransform](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1VersorRigid3DTransform.html)) followed by anisotropic scaling ([ScaleTransform](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ScaleTransform.html)), or other way round as the order for these specific transformations doesn’t matter. This wouldn’t be equivalent to optimizing all of the parameters from the two transformations in one go but is often close enough.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 24, 2020, 2:37pm UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/6 "2020-09-24T14:37:43Z")

</div>

> [@reox](#):
>
> I used Similarity3DTransform before but also wanted to try anisotropic scaling - I thought that ScaleVersor3DTransform would do the right thing?

IMHO and experience using this transform, it works well with the registration framework. And this transform does incorporate anisotropic scaling as you need.

However, the “scaling” parameters are an approximation because the following optimization was done to make the parameters independent for optimization.

S\*R \approx (S-1)+R where R is the rotation matrix and S is the scaling matrix. As the rotational angle increases the scaling parameter will diverge from a true scaling factor.

---

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [September 25, 2020, 5:07am UTC](https://discourse.itk.org/t/invert-a-scaleversor3dtransform/3483/7 "2020-09-25T05:07:20Z")

</div>

thank you both for the information! I use it in an optimizer, and it seemed to work properly.  
I’ll also take a look at the multi-step approach.
