Hello!
I have had a private conversation with Stefan Klein about this question, but now I found the forum so I will address my questions here for the benefit of all users. First of all, Elastix is a great tool for image registration, thank you! Now to my problem.
I have two images that I want to register in a nonrigid fashion. First I want to do a rigid registration, followed by a non-rigid registration. This could be done in several ways using elastix and transformix, and this is where my confusion comes in.
1) The first and simplest method I tried was to use the resulting image from the rigid registration as the moving image of the nonrigid registration. I consider this as the reference case.
elastix -f Fixed\Fixed.mhd -m Moving\Moving.mhd -out rigidReg -p rigidReg\rigidParams.txt -fMask Mask\Mask.mhd
elastix -f Fixed\Fixed.mhd -m rigidReg\result.0.mhd -out nonRigidReg -p nonRigidReg\nonRigidParams.txt -fMask Mask\Mask.mhd
2.1) I also tried applying both resulting transforms from step (1) using transformix, setting the rigid registration transform as the initial transform of the nonrigid transform:
transformix -tp nonRigidReg\TransformParameters.0.WithInitialTransform.txt -in Moving\Moving.mhd -out TransformixOutput
From my conversation with Stefan Klein I gather that this is not correct. In fact, to reproduce the same result as in (1) I should use the rigid transform as my transform parameter file, and set the nonrigid transform as the initial transform:
2.2) transformix -tp rigidReg\TransformParameters.0.WithInitialTransform.txt -in Moving\Moving.mhd -out TransformixOutputReversed
So when using transformix, InitialTransformParametersFileName should be though of as SubsequentTransformParametersFileName
3) I also tried to use the rigid transform as an initial transform in elastix:
elastix -f Fixed\Fixed.mhd -m Moving\Moving.mhd -out rigidReg -p rigidReg\rigidParams.txt -fMask Mask\Mask.mhd
elastix -f Fixed\Fixed.mhd -m Moving\Moving.mhd -out nonRigidWithInitialTransform -p nonRigidReg\nonRigidParams.txt -fMask Mask\Mask.mhd -mMask Mask\Mask.mhd -t0 rigidReg\TransformParameters.0.txt
Originally I would have thought that (1) and (3) would produce the same result, but they don't. Looking at the TransformParameters.0.txt file, I see (InitialTransformParametersFileName "rigidReg\TransformParameters.0.txt")
This would seem reasonable to me, except that I learned from (2.1) that this is not correct. OK, so now I think that the result from (3) must match the result from (2.1), since the transforms are applied in the wrong order. However, this is not the case either. Results from (3) and (2.1) are not identical, nor correct
I think I need som help now. InitialTransform does not work as I expect for either Elastix nor Transformix. I have a couple of questions:
Q1: Why does Elastix put the rigid transform as the InitialTransformParametersFileName in example (3) when it is not correct?
Q2: Assuming this is not a bug, how should the TransformParameters.0.txt file from (3) be used when transforming an image?
Q3: How should I use Initial transform in Elastix to combine a previously computed rigid transform when calculating my nonrigid transform?
I would like to avoid resampling my images several times as in example (1), but the only way to avoid this seems to be to use Transformix according to (2.2).
I hope someone can help me understand what's going on, and show me how to use initial transforms correctly in elastix when registering and resampling images.
Thank you all in advance
/Patrik Brynolfsson