# Difficulty using Rigid2DTransform in python registration demo

**URL:** https://discourse.itk.org/t/difficulty-using-rigid2dtransform-in-python-registration-demo/4777
**Category:** Beginner Questions
**Tags:** registration, python
**Created:** [February 2, 2022, 3:41am UTC](https://discourse.itk.org/t/difficulty-using-rigid2dtransform-in-python-registration-demo/4777 "2022-02-02T03:41:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chris\_Roat](https://discourse.itk.org/user_avatar/discourse.itk.org/chris_roat/32/2521_2.png) [@Chris\_Roat](https://discourse.itk.org/u/Chris_Roat)
#### Post date: [February 2, 2022, 3:41am UTC](https://discourse.itk.org/t/difficulty-using-rigid2dtransform-in-python-registration-demo/4777/1 "2022-02-02T03:41:43Z")

</div>

### Description

I have not been able to successfully alter the translation-based python registration example to use rigid-2d-based translation (adding just a rotation angle).

### Steps to Reproduce

1. Verify the unmodified [demo](https://itk.org/ITKExamples/src/Registration/Common/Perform2DTranslationRegistrationWithMeanSquares/Documentation.html) works, using the downloaded images from that page.

Command:

```sh
python reg.py BrainProtonDensitySliceBorder20.png BrainProtonDensitySliceShifted13x17y.png output.png diff_after.png diff_before.png

```

1. Apply the following patch, which alters the transform type and handles the extra parameter.

```shell
$ diff reg.py reg_2drigid.py 
30c30
< TransformType = itk.TranslationTransform[itk.D, Dimension]
---
> TransformType = itk.Rigid2DTransform[itk.D]
53a54
> initialParameters[2] = 0
69,70c70,72
< translationAlongX = finalParameters.GetElement(0)
< translationAlongY = finalParameters.GetElement(1)
---
> rigid0 = finalParameters.GetElement(0)
> rigid1 = finalParameters.GetElement(1)
> rigid2 = finalParameters.GetElement(2)
77,78c79,81
< print(" Translation X = " + str(translationAlongX))
< print(" Translation Y = " + str(translationAlongY))
---
> print(" Rigid 0 = " + str(rigid0))
> print(" Rigid 1 = " + str(rigid1))
> print(" Rigid 2 = " + str(rigid2))

```

### Expected behavior

The modified code should give the same results for X & Y translation, and give a result consistent with zero rotation angle.

The original code gives:

```auto
Result = 
 Translation X = 13.00123653240422
 Translation Y = 16.999943471681494
 Iterations = 22
 Metric value = 0.0006793961893802234

```

### Actual behavior

The code seems to get zero metric and error out immediately.

```auto
Result = 
 Rigid 0 = -3.9967219658711683
 Rigid 1 = 0.11854330443492171
 Rigid 2 = 0.1102769808099171
 Iterations = 2
 Metric value = 0.0

```

### Reproducibility

100%

### Versions

5.1.2

### Environment

Ubuntu 20.04  
python 3.8.12

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [February 2, 2022, 4:31pm UTC](https://discourse.itk.org/t/difficulty-using-rigid2dtransform-in-python-registration-demo/4777/2 "2022-02-02T16:31:30Z")

</div>

This was asked and commented [on GitHub](https://github.com/InsightSoftwareConsortium/ITK/issues/3151).
