# InPlace and Order of the Operations in Transform

**URL:** <https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232>\
**Category:** Algorithms\
**Created:** [June 26, 2020, 6:10pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232 "2020-06-26T18:10:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 26, 2020, 6:10pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/1 "2020-06-26T18:10:33Z")

</div>

Dear All,

By the manual I do not understand the difference between InPlace True and False. Could you please explain? What it is adequate.

##Don’t optimize in-place, we would possibly like to run this cell multiple times.  
registration\_method.SetInitialTransform(initial\_transform, inPlace=False)

And please confirm. The resulting transform of a registration must be applied to the moving image, first the rotation and the then translation.

Thanks,

Luis Gonçalves

---

<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:** [June 26, 2020, 8:35pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/2 "2020-06-26T20:35:34Z")

</div>

Hello @Luis_Carlos_Carneiro,

`inPlace=True` means that `initial_transform` is modified by the registration, if it is `False` then the transform isn’t modified. Please see [the documentation](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ImageRegistrationMethod.html#a6f8d5b96434b73bc9d4c0afacfc2beaf) for details.

The resulting transform maps points from the fixed image to the moving image. Please read the [Registration Overview](https://simpleitk.readthedocs.io/en/master/registrationOverview.html) and the [Fundamental Concepts](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html) pages to gain better understanding of how transforms are applied.

---

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 26, 2020, 8:51pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/3 "2020-06-26T20:51:02Z")

</div>

Thanks for the confirmation (again). There was a contradiction at a newer post.

But which the advantages of inPlace=True and of inPlace=False? In which situations one gives better than the other?

In sitk.Euler3DTransform() parameters output:

* * *

#Insight Transform File V1.0  
#Transform 0  
Transform: CompositeTransform\_double\_3\_3  
#Transform 1  
Transform: Euler3DTransform\_double\_3\_3  
Parameters: 0.0011635719083707028 -0.05268331433173672 0.0395152745443439 1.3770413687711978 3.3794554573645668 3.4098819618569753  
FixedParameters: 54.6 54.15 33.9 0

* * *

I must apply the rotation first to the fixed image then the translation (divided by the dimensions to give voxels). This to match the moving image.

---

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 26, 2020, 11:59pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/4 "2020-06-26T23:59:57Z")

</div>

Sorry, I hope to not annoy all you.

I saw in the link you presented the following text:

* * *

### Features of Interest

#### Transforms and image spaces

While the goal of registration, as defined above, refers to a single transformation and two images, the ITKv4 registration and the SimpleITK ImageRegistrationMethod provide additional flexibility in registration configuration.

From a coordinate system standpoint ITKv4 introduced the **virtual image domain** , making registration a symmetric process so that both images are treated similarly. As a consequence the ImageRegistrationMethod has methods for setting **three transformations** :

1. SetInitialTransform ToTo - composed with the moving initial transform, maps points from the virtual image domain to the moving image domain, modified during optimization.

2. SetFixedInitialTransform TfTf - maps points from the virtual image domain to the fixed image domain, never modified.

3. SetMovingInitialTransform TmTm- maps points from the virtual image domain to the moving image domain, never modified.

The transformation that maps points from the fixed to moving image domains is thus:

pmoving=To(Tm(T^{−1}\_f(pfixed)))

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*+

In example

[http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python\_html/60\_Registration\_Introduction.html](http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/60_Registration_Introduction.html)

which is To,Tm,Tf?

---

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 29, 2020, 3:55am UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/5 "2020-06-29T03:55:02Z")

</div>

Problem solved. Sorry.

---

<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:** [June 29, 2020, 1:12pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/6 "2020-06-29T13:12:04Z")

</div>

Describing what the problem was, and how you solved it will be helpful if someone in the future comes across this thread.

---

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 29, 2020, 2:45pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/7 "2020-06-29T14:45:27Z")

</div>

I was doing the rotation Z-\>Y-\>X instead of X-\>Y-\>Z. But there space for better results. All cases improved a lot but not yet perfect.

Some cases are good enough but others are not the best fit despite a close fit. I do not know yet if a mine problem or a convergence problem because of the images or algorithm.

---

<div class="post-metadata">

**Author:** ![Luis\_Carlos\_Carneiro](https://discourse.itk.org/user_avatar/discourse.itk.org/luis_carlos_carneiro/32/1486_2.png) [@Luis\_Carlos\_Carneiro](https://discourse.itk.org/u/Luis_Carlos_Carneiro)\
**Post date:** [June 29, 2020, 9:18pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/8 "2020-06-29T21:18:53Z")

</div>

> [@Luis\_Carlos\_Carneiro](#):
>
> #### Transforms and image spaces
> 
> While the goal of registration, as defined above, refers to a single transformation and two images, the ITKv4 registration and the SimpleITK ImageRegistrationMethod provide additional flexibility in registration configuration.
> 
> From a coordinate system standpoint ITKv4 introduced the **virtual image domain** , making registration a symmetric process so that both images are treated similarly. As a consequence the ImageRegistrationMethod has methods for setting **three transformations** :
> 
> 1. SetInitialTransform ToTo - composed with the moving initial transform, maps points from the virtual image domain to the moving image domain, modified during optimization.
> 2. SetFixedInitialTransform TfTf - maps points from the virtual image domain to the fixed image domain, never modified.
> 3. SetMovingInitialTransform TmTm- maps points from the virtual image domain to the moving image domain, never modified.
> 
> The transformation that maps points from the fixed to moving image domains is thus:
> 
> pmoving=To(Tm(T^{−1}\_f(pfixed)))

* * *

In the above formula the transform is inverse. Seems that to convert the fixed image in the moving image it is needed the inverse transform. And seems the transform is from the moving to the fixed.

Sorry about to come again about this question.

---

<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:** [June 29, 2020, 10:25pm UTC](https://discourse.itk.org/t/inplace-and-order-of-the-operations-in-transform/3232/9 "2020-06-29T22:25:43Z")

</div>

I think this thread should be “closed”, and discussion continued in the [original thread](https://discourse.itk.org/t/registration-in-one-rotation-parameters-of-the-transform-not-doing-well/3215/).
