# GetMatrix from SimpleITK ImageRegistrationMethod.Execute transform result

**URL:** https://discourse.itk.org/t/getmatrix-from-simpleitk-imageregistrationmethod-execute-transform-result/5256
**Category:** Beginner Questions
**Tags:** registration, simpleitk
**Created:** [August 11, 2022, 6:32pm UTC](https://discourse.itk.org/t/getmatrix-from-simpleitk-imageregistrationmethod-execute-transform-result/5256 "2022-08-11T18:32:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ktdiedrich](https://discourse.itk.org/user_avatar/discourse.itk.org/ktdiedrich/32/2784_2.png) [@ktdiedrich](https://discourse.itk.org/u/ktdiedrich)
#### Post date: [August 11, 2022, 6:32pm UTC](https://discourse.itk.org/t/getmatrix-from-simpleitk-imageregistrationmethod-execute-transform-result/5256/1 "2022-08-11T18:32:29Z")

</div>

Is there a way to GetMatrix from the base transform returned from ImageRegistrationMethod.Execute(…)?  
`final_transform = registration_method.Execute(fixed_image, moving_image)`  
Final\_transform doesn’t have access to GetMatrix even though  
`str(final_matrix)` shows the Matrix in string form.

```nohighlight
...
Matrix: \n 0.969854 0.227518 -0.0872828 \n -0.225962 0.97375 0.0274403 \n 0.0912348 -0.00689049 0.995806 \n
...

```

The descended class Euler3DTransform has GetMatrix but casting failed.

```auto
SimpleITK.Euler3DTransform(final_transform)
SimpleITK::ERROR: Transform is not of type Euler3DTransform!

```

---

<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 11, 2022, 8:33pm UTC](https://discourse.itk.org/t/getmatrix-from-simpleitk-imageregistrationmethod-execute-transform-result/5256/2 "2022-08-11T20:33:22Z")

</div>

The `final_transform` is a generic wrapper around a CompositeTransform, so if you only have one transformation inside you can get the specific transform this way:

```auto
euler3d_transform = sitk.CompositeTransform(final_transform).GetBackTransform()

```

---

<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: [August 15, 2022, 2:51pm UTC](https://discourse.itk.org/t/getmatrix-from-simpleitk-imageregistrationmethod-execute-transform-result/5256/3 "2022-08-15T14:51:32Z")

</div>

There is an issue discussing if the return type should be changed here:

> <https://github.com/SimpleITK/SimpleITK/pull/1565>
>
> The returned object from ImageRegistrationMethod::Execute when the
> InitialTrans…form had inPlace=False, was an sitk::Transform holding a
> itk::CompositeTransform pimple object. The composite transform then
> held an optimized transform of the initial type.
> 
> While the return type for the method remains a sitk::Transform, the
> object held in the pimple transform is now the optimized transform of
> the initial type.

If you pass `inPlace=True` to `SetInitialTransform` then the same transform object provided in the argument is updated. This may be preferred to the additional conversions in the code @zivy provided.
