# Can I read the transform calculated from elastix

**URL:** https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191
**Category:** Development
**Tags:** extensions-manager
**Created:** [June 24, 2020, 5:12am UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191 "2020-06-24T05:12:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [June 24, 2020, 5:12am UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/1 "2020-06-24T05:12:01Z")

</div>

I’d like to add an already calculated elastix transform file(txt) to Slicer. However, when I try to add the file to Slicer using the “Add Data” screen, it fails almost silently.

---

<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: [June 25, 2020, 9:39pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/2 "2020-06-25T21:39:34Z")

</div>

Unfortunately, elastix uses its own transformation file format, but you can use the [`readElastixTransformToVTK` function](https://github.com/lassoan/SlicerElastix/blob/master/Elastix/Elastix.py#L525) we implemented in SlicerElastix to read an elastix transform. It only supports linear and bspline components.

To make things simpler, you can add your registration parameter set file to SlicerElastix preset list and run Elastix from Slicer. Then the module automatically imports the output transform file into Slicer.

---

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [June 26, 2020, 12:25pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/3 "2020-06-26T12:25:21Z")

</div>

Compared with the volume create with the SlicerElastix module, there is a huge difference with aplling the transform.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/b/5b06245446c5e2c944e2ee09606a73c6d736d2fd.jpeg)

---

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [June 26, 2020, 12:33pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/4 "2020-06-26T12:33:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/3/d317abd7cd562c73ded1c94a8c0c9671f75d3fbf.jpeg)

---

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [June 26, 2020, 12:37pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/5 "2020-06-26T12:37:01Z")

</div>

the mrb file (4.11.0-2020-06-17 r29154 / 2a9d59c)  
[https://c-t.work/s/1f0cca770c1642](https://c-t.work/s/1f0cca770c1642)

42majh （ 24h）

---

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [June 26, 2020, 12:44pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/6 "2020-06-26T12:44:52Z")

</div>

> <https://github.com/nipy/nipype/blob/4f08c9abd6744f2ef346ebc524590ed1aa0abf75/nipype/interfaces/elastix/utils.py#L46>

---

<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: [June 26, 2020, 2:24pm UTC](https://discourse.slicer.org/t/can-i-read-the-transform-calculated-from-elastix/12191/7 "2020-06-26T14:24:11Z")

</div>

It all looks good except:

- non-linear transforms are only reflected in volume rendering if you harden the transform on the volume
- automatic intensity-based registration methods typically cannot converge if initial rotation error was more than a few ten degrees; you can fix this by pre-aligning the volumes by an approximate landmark registration using 3-4 points (using Fiducial registration wizard module of SlicerIGT):

[![](https://img.youtube.com/vi/TBHr2wizGTM/maxresdefault.jpg "Align 3D objects using landmarks in 3D Slicer") ](https://www.youtube.com/watch?v=TBHr2wizGTM)

The referenced `EditTransform` function just modifies parts of a transform file, it cannot transform 3D objects.
