# Effect of setting orientation on CenteredTransformInitializer

**URL:** https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786
**Category:** Beginner Questions
**Created:** [March 4, 2020, 7:00pm UTC](https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786 "2020-03-04T19:00:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![trypag](https://discourse.itk.org/user_avatar/discourse.itk.org/trypag/32/1271_2.png) [@trypag](https://discourse.itk.org/u/trypag)
#### Post date: [March 4, 2020, 7:00pm UTC](https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786/1 "2020-03-04T19:00:24Z")

</div>

Hello,

I am a complete beginner in image registration, much more I am lacking experience in debugging and tuning a registration pipeline.

Goal : Translate a head CT to the center and rotate based on a CT template image. So let’s says moving.nii is my moving image and fixed.nii is the template, in the end I would like moving.nii to be of the same size as before the registration, in the common RAI space, centered and rotated. Even as a beginner, I think it’s basic rigid registration, should be easy… well

First thing I noticed is that moving.nii and fixed.nii have different orientations :

> moving\_image.GetDirection()  
> (1.0,  
> 0.0,  
> 0.0,  
> 0.0,  
> 0.9914448880836518,  
> 0.13052598937071197,  
> 0.0,  
> -0.1305259893385041,  
> 0.9914448880794114)

> fixed\_image.GetDirection()  
> (-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0)

Accordingly I decide to set a common space for both :

# change orientation to RAI

fixed\_image.SetDirection(np.eye(3, 3).flatten())  
moving\_image.SetDirection(np.eye(3, 3).flatten())

Am I wrong doing this, is there anything incorrect about this ?

After setting the orientation, I tried a Centered Transform :

> 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())

For a reason I don’t understand, the volume are aligned but relatively inverted (one is anterior-superior and the other one superior-anterior). Though, removing the previous orientation change solves this problem. I would like to get someone’s point of view on this, I am pretty sure to be doing something wrong 🙂

Thanks !

---

<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: [March 4, 2020, 9:35pm UTC](https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786/2 "2020-03-04T21:35:49Z")

</div>

Direction indicates orientation of image in physical space. If you change direction, so will image’s orientation in space. That is causing your inversion.

ITK handles weird orientations, so if you skip the step of changing directions, it should work fine - or at least better.

---

<div class="post-metadata">

### Author: ![trypag](https://discourse.itk.org/user_avatar/discourse.itk.org/trypag/32/1271_2.png) [@trypag](https://discourse.itk.org/u/trypag)
#### Post date: [March 4, 2020, 10:59pm UTC](https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786/3 "2020-03-04T22:59:40Z")

</div>

Thanks !

That makes sense ! I am mistaking the image orientation and the orientation of the patient within the space.  
When changing the orientation, the image origin stays unchanged right ? and becomes the origin of the new space ?

Thank you

---

<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: [March 5, 2020, 3:43pm UTC](https://discourse.itk.org/t/effect-of-setting-orientation-on-centeredtransforminitializer/2786/4 "2020-03-05T15:43:23Z")

</div>

> [@trypag](#):
>
> the image origin stays unchanged

Correct. So just inverting the orientation (`direction`) inverts the image and moves it to the other side of the origin.
