Initial transform as a deformation field (.nrrd)

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

Have you had a look at
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

Unfortunately, Elastix does not use standard ITK transform file format. I’ve already reported this issue 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.

@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.

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.