# Applying computed transformation

**URL:** <https://opentps.discourse.group/t/applying-computed-transformation/98>\
**Category:** General\
**Created:** [August 21, 2025, 2:01am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98 "2025-08-21T02:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrMechine](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MrMechine](https://opentps.discourse.group/u/MrMechine)\
**Post date:** [August 21, 2025, 2:01am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98/1 "2025-08-21T02:01:00Z")

</div>

I am using the rigid registration module to compute a registratration between two Ct scans. The compute function returns a transformation3d object. How do I apply this transformation? Do I translate the origin by the translation returned by get translate?

TL;DR how do I apply the computed translation?

---

<div class="post-metadata">

**Author:** ![Eliot-P](https://yyz2.discourse-cdn.com/free1/user_avatar/opentps.discourse.group/eliot-p/32/6_2.png) [@Eliot-P](https://opentps.discourse.group/u/Eliot-P)\
**Post date:** [August 21, 2025, 8:24am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98/2 "2025-08-21T08:24:34Z")

</div>

Hi Ben W,

To apply the computed `transformation3D` :

First, use your `transformation3D` (transform) object directly with the `deformImage` method

```python
deformedImage = transform.deformImage(moving)

```

Then: use the resampler with the deformed image to align the two grids

```python
resampledOnFixedGrid = resampleImage3DOnImage3D(deformedImage, fixedImage=fixed, fillValue=-1000)

```

You can check out our example on our website : [Rigid registration | OpenTPS](https://opentps.org/2023/08/08/exampleRigid.html)

Regards,

Eliot

---

<div class="post-metadata">

**Author:** ![Ana\_Barragan\_Montero](https://yyz2.discourse-cdn.com/free1/user_avatar/opentps.discourse.group/ana_barragan_montero/32/5_2.png) [@Ana\_Barragan\_Montero](https://opentps.discourse.group/u/Ana_Barragan_Montero)\
**Post date:** [August 22, 2025, 9:59am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98/3 "2025-08-22T09:59:29Z")

</div>

Hi Ben,  
did it work? I have done a similar thing in the past (i.e. reading a DICOM reg file) but I used a different function (i.e. transform3D.deformData) to perform the transform:

```
    # Perform registration
    transform3D = Transform3D()
    transform3D.setCenter('dicomOrigin') # other option is 'imgCenter' but in this case we should use dicomOrigin
    transform3D.setMatrix4x4(tformMatrix_1)
    mr_reg = transform3D.deformData(mr, outputBox='keepAll')
    # resample to CT grid
    mr_reg.resample(ct.spacing, ct.gridSize, ct.origin)

```

---

<div class="post-metadata">

**Author:** ![MrMechine](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MrMechine](https://opentps.discourse.group/u/MrMechine)\
**Post date:** [August 27, 2025, 2:30am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98/4 "2025-08-27T02:30:19Z")

</div>

Hey Ana,

Sorry for the late reply took me a while to figure out the best way to test the outputs. The above method given by Eliot does work. Is there a difference with what you have done or should it give the same output?

---

<div class="post-metadata">

**Author:** ![Eliot-P](https://yyz2.discourse-cdn.com/free1/user_avatar/opentps.discourse.group/eliot-p/32/6_2.png) [@Eliot-P](https://opentps.discourse.group/u/Eliot-P)\
**Post date:** [August 28, 2025, 9:17am UTC](https://opentps.discourse.group/t/applying-computed-transformation/98/5 "2025-08-28T09:17:56Z")

</div>

After looking at our source code, the two methods are pretty similar.

In @Ana_Barragan_Montero code, a `Transform3D` object is initialized and then the transformation matrix is set. In the example version, the `Transform3D` object is initialized and computed by the the `RigidRegistration.compute()` method.

As for the difference between `deformImage` and `deformData`, `deformData` is a more flexible implementation for deforming the moving image i.e. you can choose the interpolation order and if the computed angles (of the `Tranform3D`) are all 0° are simple translation will be applied while with the `deformImage` method, the interpolation order is always 1 (linear) and there is no case check for 0° angles (but this should not change that much the output).

Hope this clarifies things for you.
