# Initial transform as a deformation field (.nrrd)

**URL:** https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130
**Category:** Support
**Tags:** elastix
**Created:** [December 18, 2018, 4:36pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130 "2018-12-18T16:36:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rayan](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@rayan](https://discourse.slicer.org/u/rayan)
#### Post date: [December 18, 2018, 4:36pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130/1 "2018-12-18T16:36:08Z")

</div>

Hello,

I am registering two images using Elastix. I want to define an initial transform which I created outside of Elastix in .nrrd format. However, I see Elastix can only accept a text file transform (.txt) defined using -t0 option. I was wondering is there a way to put the deformation field .nrrd as an initial transform? Or convert the deformation field to a text file parameters that Elastix can read?

Thanks,  
Rayan

---

<div class="post-metadata">

### Author: ![stephan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephan/32/2444_2.png) [@stephan](https://discourse.slicer.org/u/stephan)
#### Post date: [December 18, 2018, 8:21pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130/2 "2018-12-18T20:21:10Z")

</div>

Have you had a look at  
[http://elastix.isi.uu.nl/doxygen/classelastix\_1\_1DeformationFieldTransform.html](http://elastix.isi.uu.nl/doxygen/classelastix_1_1DeformationFieldTransform.html)

I am not sure about .nrrd files (the example there uses .mhd), but this might be a good starting point at least.

Stephan

---

<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: [December 18, 2018, 8:26pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130/3 "2018-12-18T20:26:41Z")

</div>

Unfortunately, Elastix does not use standard ITK transform file format. I’ve already [reported this issue](https://github.com/SuperElastix/elastix/issues/18) and several users supported it but it was not important enough for Elastix developers to work on it and I did not have time to implement it. You may add a comment to the issue to confirm that this is an important need.

Until it gets fixed in Elastix, you can _harden_ the initial transform in Slicer. Hardening a linear transform only changes the image header, does not resample the voxels, so it is fast and does not affect image quality.

---

<div class="post-metadata">

### Author: ![stephan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephan/32/2444_2.png) [@stephan](https://discourse.slicer.org/u/stephan)
#### Post date: [December 18, 2018, 8:41pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130/4 "2018-12-18T20:41:15Z")

</div>

@lassoan, I found that at least for affine transforms returned by Elastix one can simply copy/paste the parameters 1:1 into an ITK .tfm file to import the linear transform into Slicer.  
So, for example, the Elastix output

> (Transform “AffineTransform”)  
> (NumberOfParameters 12)  
> (TransformParameters **0.885096 -0.037625 0.021871 0.053013 0.878547 -0.037054 -0.046384 0.040843 0.821334 0.789846 -6.528138 2.683686** )  
> (InitialTransformParametersFileName “NoInitialTransform”)  
> (UseBinaryFormatForTransformationParameters “false”)  
> (HowToCombineTransforms “Compose”)
> 
> // AdvancedAffineTransform specific  
> (CenterOfRotationPoint **6.2539062500 -240.1992187500 262.1000061035** )

becomes

> #Insight Transform File V1.0  
> #Transform 0  
> Transform: AffineTransform\_double\_3\_3  
> Parameters: **0.885096 -0.037625 0.021871 0.053013 0.878547 -0.037054 -0.046384 0.040843 0.821334 0.789846 -6.528138 2.683686**  
> FixedParameters: **6.2539062500 -240.1992187500 262.1000061035**

This ITK .tfm file can then be loaded into Slicer to get a linear transform. Something similar might be possible with the Elastix BSplineTransform and the corresponding ITK .tfm “BSplineTransform\_double\_3\_3”, but I have not tested this.  
I admit it’s a little bit crude as work-around and direct ITK output would be great, but for the time being this is what I resort to when I have an affine transform from SlicerElastix and do not want to have it represented by gigabytes of deformation data.

---

<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: [December 18, 2018, 9:50pm UTC](https://discourse.slicer.org/t/initial-transform-as-a-deformation-field-nrrd/5130/5 "2018-12-18T21:50:54Z")

</div>

Yes, for basic transforms parameter conversion is trivial. I’ve been considering adding a Elastix transform file parser to SlicerElastix instead of improving transform reader/writer classes in Elastix.
