# Start programming in Slicer: Transforms module, Elastix

**URL:** https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499
**Category:** Support
**Tags:** registration, python, elastix
**Created:** [April 3, 2018, 9:57am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499 "2018-04-03T09:57:34Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [April 3, 2018, 9:57am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/1 "2018-04-03T09:57:35Z")

</div>

Hi, I’m new in slicer so I have beginners questions:

I’d like to use slicer modules through python programming, which I see in many places that is possible, just not sure how to get started. I don’t want to work through the consol, but rather write scripts etc.

1. How do I do that- where do I write the scripts?
2. After I’ll figure out 1 - Is the only option is to create an extantion, and that way to operate it?
3. Can I access into a module script (how?) set a breakpoint and see how it works (as I can do in MATALB functions), like in Transformation module?

Question regarding elastix and transformation module:  
when I apply elastix transformation on an image using transformation module, I assuem it do resampling+ interpolation.

1. How\Can I control the type of interpolation?
2. Is the elastix transformation include both rigid+non-linear registration in a vector field? How can I visualize the transformation without applying it on an image?

Thanks!

---

<div class="post-metadata">

### Author: ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)
#### Post date: [April 3, 2018, 10:20am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/2 "2018-04-03T10:20:18Z")

</div>

Welcome to Slicer.

There are 4 simple [video tutorials](https://www.youtube.com/watch?v=sl-00kGpuPk&list=PLJWCUXz3GeAfmYLiFcKus_c0jcsMnVsgb) that explains the basics Slicer python programming for beginners (note: German audio with English subtitle).

elastix uses parameter text file that controls the registration process. You can modify it to control any registration component you want including interpolation, you can access all these parameter files by clicking on “Advanced” then click on “Show database folder” button.

---

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [April 3, 2018, 10:56am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/3 "2018-04-03T10:56:19Z")

</div>

Thank you @brhoom !  
I will look at the videos!  
Regarding elastix,  
1.I’m asking about the result- the transformation- How can I see it? how can I apply it with contoling the interpolation? is the same interpolation that was used during the registration is used when I apply the transformation resulted from the registration process?  
2. Parameters files- how can I know which one is related to which preset Inputs? (they don’t have the same names)

---

<div class="post-metadata">

### Author: ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)
#### Post date: [April 3, 2018, 11:35am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/4 "2018-04-03T11:35:09Z")

</div>

Slicer plugin is just an interface, to learn more about it, search for Elastix.py. If you want to learn more about elastix, install it and read the [elastix manual](https://github.com/SuperElastix/elastix/releases/download/4.9.0/elastix-4.9.0-manual.pdf), it has simple examples for different stuff, a simple usage is:

```
 elastix -f fixed_image -m moving_image -p parmaeter_file.txt -out output_folder

```

To see the results file:  
`Advanced->show temp folder.`  
The transformation is saved in TransformParameters.0.txt.

search for ElastixParameterSetDatabase.xml, it explains the parameters files connection to Slicer interface. You can control the interpolation by modifying the used parameters file before the registration, e.g. by modifying the lines (Interpolator “BSplineInterpolator”), (FixedImageBSplineInterpolationOrder 1 ), (BSplineInterpolationOrder 1) .

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [April 3, 2018, 11:40am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/5 "2018-04-03T11:40:01Z")

</div>

> [@brhoom](#):
>
> There are 4 simple [video tutorials](https://www.youtube.com/watch?v=sl-00kGpuPk&list=PLJWCUXz3GeAfmYLiFcKus_c0jcsMnVsgb) that explains the basics Slicer python programming for beginners (note: German audio with English subtitle).

These videos look great - thanks for the link!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [April 4, 2018, 4:03am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/6 "2018-04-04T04:03:41Z")

</div>

The official Slicer programming tutorial is quite good, too. It is fully up-to-date for Slicer-4.8: [https://www.slicer.org/wiki/Documentation/Nightly/Training#Slicer4\_Programming\_Tutorial](https://www.slicer.org/wiki/Documentation/Nightly/Training#Slicer4_Programming_Tutorial)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [April 4, 2018, 4:06am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/7 "2018-04-04T04:06:01Z")

</div>

> [@hadasara](#):
>
> Can I access into a module script (how?) set a breakpoint and see how it works

Yes, of course. You can choose from a number of integrated development environments with visual debuggers. I mostly use PyCharm but Visual Studio and LiClipse are quite good, too. See detailed instructions here: [Documentation/Nightly/Extensions/DebuggingTools - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [April 4, 2018, 4:10am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/8 "2018-04-04T04:10:25Z")

</div>

> [@hadasara](#):
>
> Is the elastix transformation include both rigid+non-linear registration in a vector field? How can I visualize the transformation without applying it on an image?

Yes, Elastix provides the entire transformation as a displacement field. This is somewhat inconvenient for linear and bspline transforms where it would be more efficient to be able to work with matrices and coefficients instead. We plan to have this option implemented soon.

You can visualize a transform using [Transforms module’s Display section](https://www.slicer.org/wiki/Documentation/Nightly/Modules/Transforms#Transform_display_options).

---

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [April 16, 2018, 8:12am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/10 "2018-04-16T08:12:43Z")

</div>

I scucedde using the instructions here:  
[https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools)  
to set a breakpoint.  
but when I want to stop and go back to slicer, slicer is getting “not responding” , and I have to close it and open again. Is this a normal behaviour?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [April 17, 2018, 3:42am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/11 "2018-04-17T03:42:44Z")

</div>

> [@hadasara](#):
>
> when I want to stop and go back to slicer, slicer is getting “not responding” , and I have to close it and open again. Is this a normal behaviour?

Yes, when a breakpoint is hit, execution is stopped. No need to close and open anything, just use _Resume program_ to continue.

---

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [May 7, 2018, 12:22pm UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/12 "2018-05-07T12:22:52Z")

</div>

Hi @brhoom  
I tried to change the ResampleInterpolator to:  
(ResampleInterpolator “NearestNeighborResampleInterpolator”)  
and removed (FinalBSplineInterpolationOrder 1)  
In order to change the final interpolation that is applied on the image.  
But I get an error:

```
Traceback (most recent call last):

```

File “C:/Users/user/AppData/Roaming/NA-MIC/Extensions-26813/SlicerElastix/lib/Slicer-4.8/qt-scripted-modules/Elastix.py”, line 327, in onApplyButton  
movingVolumeMaskNode = self.movingVolumeMaskSelector.currentNode())  
File “C:/Users/user/AppData/Roaming/NA-MIC/Extensions-26813/SlicerElastix/lib/Slicer-4.8/qt-scripted-modules/Elastix.py”, line 575, in registerVolumes  
self.logProcessOutput(ep)  
File “C:/Users/user/AppData/Roaming/NA-MIC/Extensions-26813/SlicerElastix/lib/Slicer-4.8/qt-scripted-modules/Elastix.py”, line 515, in logProcessOutput  
raise subprocess.CalledProcessError(return\_code, “elastix”)  
CalledProcessError: Command ‘elastix’ returned non-zero exit status 1

when I tried to keep

(ResampleInterpolator “BSplineInterpolator”)  
(FinalBSplineInterpolationOrder 0)

it runs, but the result seems like it didn’t do anything…

could you please help me understand what do I do wrong?  
thanks!

---

<div class="post-metadata">

### Author: ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)
#### Post date: [May 7, 2018, 12:41pm UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/13 "2018-05-07T12:41:20Z")

</div>

Please don’t address members in your question as this will encourage other members to answer. Try to isolate the problem, is it elastix problem or slicer problem? check elastix log, run elastix using the same images and parameters and check the result.

---

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [May 7, 2018, 2:08pm UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/15 "2018-05-07T14:08:38Z")

</div>

> check elastix log

This was a wonderfull advice! I’ve realized I didn’t use the parameter files I though I’m using.

> run elastix using the same images and parameters and check the result

What do you mean?  
Thank you!

---

<div class="post-metadata">

### Author: ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)
#### Post date: [May 7, 2018, 5:11pm UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/16 "2018-05-07T17:11:13Z")

</div>

I meant using the terminal without slicer e.g.

`elastix -f fixed_image -m moving_image -p parameter.txt -o output_folder`

---

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [May 10, 2018, 9:31am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/17 "2018-05-10T09:31:27Z")

</div>

I’m sorry, but I have a realy begginer question, hope it’s ok to ask.  
Where can I run terminal commands? the command line of windows doesn’t recognize elastix.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/0/b006aeeba063988b6690329e1d31df5c8dcb3aca.png)

should I first install elastix seperatly, and then do it?

---

<div class="post-metadata">

### Author: ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)
#### Post date: [May 10, 2018, 9:30pm UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/18 "2018-05-10T21:30:19Z")

</div>

I am not a windows user so I don’t know the path of elastix in windows, simply search for “elastix” in your system then provide the full path to run e.g. elastix\_Path\elastix.exe -f …

You can also download elastix binaries for windows from [elastix official website](http://elastix.isi.uu.nl/) and read the elastix manual to learn how to use it.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [May 14, 2018, 2:57am UTC](https://discourse.slicer.org/t/start-programming-in-slicer-transforms-module-elastix/2499/19 "2018-05-14T02:57:26Z")

</div>

On Windows, Elastix is bundled with the SlicerElastix extension. Elastix path and complete list of command-line arguments that are passed to Elastix are all shown if you enable “Show detailed log during registration” in Advanced section.
