# CenteredTransformInitializer with only TranslationTransform?

**URL:** https://discourse.itk.org/t/centeredtransforminitializer-with-only-translationtransform/4635
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [December 3, 2021, 4:16pm UTC](https://discourse.itk.org/t/centeredtransforminitializer-with-only-translationtransform/4635 "2021-12-03T16:16:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sdbonte](https://discourse.itk.org/user_avatar/discourse.itk.org/sdbonte/32/2412_2.png) [@sdbonte](https://discourse.itk.org/u/sdbonte)
#### Post date: [December 3, 2021, 4:16pm UTC](https://discourse.itk.org/t/centeredtransforminitializer-with-only-translationtransform/4635/1 "2021-12-03T16:16:02Z")

</div>

I am trying to register two 3D CT scans using SimpleITK. After checking they have the same orientation, I load them from .nii.gz files. Then they look like this (central axial slice displayed):  
Fixed image:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/4/423d89252645b40d241f743fe1386fc38c315c3f.jpeg)  
Moving image:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/0/0b07cb8c8972453a51a9eca39ef40adb791bea6e.png)

To initialize the registration, following [this tutorial](https://simpleitk.org/SPIE2019_COURSE/04_basic_registration.html) we first need to align the two volumes. However, after doing this:

```auto
initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY
                                                    ) 

moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

```

The moving\_resampled image is flipped upside down:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/5/5d7e006aa665bee62ab19ea65ce7738093cbc36e.png)

Is this normal behavior?

As an alternative, I tried to just align the images using a 3D translation, which gives an error:

```auto
initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.TranslationTransform(3),#sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY,
                                                    ) # .MOMENTS)

moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

```

**File “C:\Users\stijnb\AppData\Local\Continuum\miniconda3\envs\mimicsenv352\lib\site-packages\SimpleITK\SimpleITK.py”, line 6169, in CenteredTransformInitializer**  
\*\*return \_SimpleITK.CenteredTransformInitializer(\*args, **kwargs)**  
**RuntimeError: Exception thrown in SimpleITK CenteredTransformInitializer: D:\a\1\sitk\Code\BasicFilters\src\sitkCenteredTransformInitializerFilter.cxx:132:**  
**sitk::ERROR: Error converting input transform to required transform type with center.**

Any suggestions how this can be solved? 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: [December 3, 2021, 5:05pm UTC](https://discourse.itk.org/t/centeredtransforminitializer-with-only-translationtransform/4635/2 "2021-12-03T17:05:30Z")

</div>

Hello @sdbonte,

Hard to debug without the short code used here. This is possibly a display issue.

When working with 3D images highly recommended to use an external viewer. Fiji is the default in SimpleITK, ITK-SNAP highly recommended for quick image viewing, see [this notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/04_Image_Display.ipynb) for details.

Short code snippet:

```auto
import SimpleITK as sitk

fixed_image_file = 'a.nii.gz'
moving_image_file = 'b.nii.gz'

fixed_image = sitk.ReadImage(fixed_image_file, sitk.sitkFloat32)
moving_image = sitk.ReadImage(moving_image_file, sitk.sitkFloat32)

sitk.Show(fixed_image, 'fixed')
sitk.Show(moving_image, 'moving')

initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY
                                                    )
moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

sitk.Show(moving_resampled, 'moving_resampled')

```

Meaning of error message:  
The `CenteredTransformInitializer` is expecting a transformation which has a `center`, `TranslationTransform` is not one of the transformations that has a center, hence the error. For additional details about transformations see [this notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/22_Transforms.ipynb).

---

<div class="post-metadata">

### Author: ![ljjiayou](https://discourse.itk.org/user_avatar/discourse.itk.org/ljjiayou/32/3211_2.png) [@ljjiayou](https://discourse.itk.org/u/ljjiayou)
#### Post date: [February 11, 2023, 1:20pm UTC](https://discourse.itk.org/t/centeredtransforminitializer-with-only-translationtransform/4635/3 "2023-02-11T13:20:10Z")

</div>

I also met this problem. Have you solved it?
