# Apply Demons transformation onto an image.

**URL:** https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [May 3, 2021, 7:50pm UTC](https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094 "2021-05-03T19:50:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eyalol](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@eyalol](https://discourse.itk.org/u/eyalol)
#### Post date: [May 3, 2021, 7:50pm UTC](https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094/1 "2021-05-03T19:50:06Z")

</div>

Hello,  
This is my first time using SimpleITK, I’m interested in using the Demons registration algorithm, I’m using the python version of this: [DemonsRegistration1 — SimpleITK 2.0rc2 documentation](https://simpleitk.readthedocs.io/en/master/link_DemonsRegistration1_docs.html)  
after applying the algorithm to the images, I’m only getting a transformation file (.txt),  
how do I apply this transformation to my image and save it?  
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: [May 3, 2021, 8:04pm UTC](https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094/2 "2021-05-03T20:04:15Z")

</div>

Hello @eyalol,

Welcome to SimpleITK!

The immediate, yet not so useful answer, is:

```auto
sitk.WriteImage(out, 'resampled_moving_image.nrrd')

```

The useful answer, learn SimpleITK in a principled way:

1. Read about the toolkit’s [fundamental concepts](https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html).
2. Take the [online tutorial](http://simpleitk.org/TUTORIAL/).
3. Skim the toolkit’s [Jupyter notebooks repository](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks), specifically the 6\* series that illustrate various aspects of registration.

---

<div class="post-metadata">

### Author: ![eyalol](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/47e85d/32.png) [@eyalol](https://discourse.itk.org/u/eyalol)
#### Post date: [May 4, 2021, 5:07am UTC](https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094/3 "2021-05-04T05:07:54Z")

</div>

Thank you.

I’m planning on taking that tutorial, however, for now i’m looking for a “quick and dirty” way.

Your code snippet is about writing an image to disk if i’m not wrong, though i’m looking to apply the ‘outTx’ transform in the code example that i sent, onto the ‘moving’ image.

What i’m looking for, is for a continuation to the code example i sent, in order to apply the transform and save the registered image.

Good day!

---

<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: [May 4, 2021, 12:58pm UTC](https://discourse.itk.org/t/apply-demons-transformation-onto-an-image/4094/4 "2021-05-04T12:58:35Z")

</div>

Hello @eyalol,

The code snippet was referring to the example you were pointing to. There is the section under `if ("SITK_NOSHOW" not in os.environ)` which resamples the moving image, the only thing missing there was writing it to disk which is the one liner I provided.

In your code you can just resample and write to disk as you don’t care about opening the image in an external application for visualization.
