coregister with sitk Elastix #756
Replies: 5 comments
-
What is the problem? Is it related to TorchIO?
Wow! That sounds like a bad idea... At the moment I'm pretty busy writing my thesis, so I'm not sure when I will be able to look into this. |
Beta Was this translation helpful? Give feedback.
-
This issue is related to #693, in the sense that I try to fully characterize the given affine one want to set with Ok, as for the recent PR #712 , on could argue that it does not really matter for a use of RandomAffine transform since we want random affine no matter to get a lelft/right inversion ... It will be really important for torchio if one want to add a coregistration transform as you suggested here #428. Indeed this must be resolved, because a simple test to setup would be to applied a given Affine (with tio.Affine) and retrieve the exact affine you have applied. (or applied a given set of rotation+translation, and retrieve this set of rotation+translation, but because the euleur representation is not invertible, we have to go through the 4*4 matrix representation (Cf For instance in the code example here, the last tested transform is a translation of [10, 10, 10] and a rotation of [10, 0, 0] applied with center='image' (because I did not find how to change elastix convention that also report the euler parameter with rotation applied at image center). The elastix report an Euler rigid transform of
Since it is in LPS, the translation should be read as [-10 -11.59 -8.11] and since itk is storing the reference to source transfo one should add an extra inversion to find what we set. ... [10, 10, 10 ] ... well it is almost it ... !!! argg !!! If we do only rotation and translation it is find but because we have a "mixt" affine here, we need to go with affine representation.
Note that the direct itk affine we applied with tio.Affine is not [10, 10, 10] in the translation part, because the rotation center is not at [0,0,0] ... I understand you do not have so much time, but since you made all the code to translation from nibable to itk, may be you would notice an obvious mistake ... Although this may not be obvious (I try a few days ... without success ! ) But ok, I will consider to make a working example without torchio, and try to ask to SimpleElastix folks ... |
Beta Was this translation helpful? Give feedback.
-
Ok, I just found a workaround: it gives me the correct result !
and, then : but I must still miss something since looking for the inverse transformation should give the inverse affine matrix ... arg ... by the way I found the explanation why itk is storing the transformation from reference to the moving image
|
Beta Was this translation helpful? Give feedback.
-
Just to put my numerical output (if it can helps ... ) : aff_elastix, elastix_trf = ElastixRegister(sdata.t1, srot.t1)
aff_elastix2, elastix_trf2 = ElastixRegister( srot.t1, sdata.t1)
In[78]: affitk
Out[78]:
array([[ 1. , 0. , 0. , 10. ],
[ 0. , 0.98, 0.17, 6.6 ],
[ 0. , -0.17, 0.98, 7.15],
[ 0. , 0. , 0. , 1. ]])
In[75]: aff_elastix
Out[75]:
array([[ 1.00e+00, -2.93e-05, 6.67e-05, 1.00e+01],
[ 1.73e-05, 9.85e-01, 1.74e-01, 9.42e+00],
[-7.08e-05, -1.74e-01, 9.85e-01, 3.12e+00],
[ 0.00e+00, 0.00e+00, 0.00e+00, 1.00e+00]])
In[77]: np.linalg.inv(aff_elastix2)
Out[77]:
array([[ 1.00e+00, -3.07e-05, -4.11e-05, 9.99e+00],
[ 3.74e-05, 9.85e-01, 1.74e-01, 6.59e+00],
[ 3.51e-05, -1.74e-01, 9.85e-01, 7.15e+00],
[ 0.00e+00, 0.00e+00, 0.00e+00, 1.00e+00]]) inv(all_elastix2) is the same as the applied affine from tio.Affine, but why it is not the same as aff_elastix ... ? |
Beta Was this translation helpful? Give feedback.
-
Ok I have a working solution now, (finally !) I made 2 big errors, here, first try and test with angle [10, 10, 10] was a bad idea, (I though I had a working solution but this was just because the angle are equal) the sencond error was to try to rely on spm convention are change itk eurler to matrix definition (so the line It should be the other way around : I need to addapt spm_imatrix to match simpleitk conventions. |
Beta Was this translation helpful? Give feedback.
-
🚀 Feature
I would like to make a PR to propose, a coregistration transform
but here I want to report an issue with Euler to affine matrix problem
Motivation
Cf #428
I open a new issue, to see if someone can help with orientation issue,
Pitch
I try to apply a given affine to a image, (with given translation and Euler Angle) and then use Elastix to coregister the 2 images and retrieve the same affine (or the same euler transform)
I put here the code because I can not find the solution. @fepegar I would appreciate any insight (I am getting sick of euler to affine transform ! ) ...
it works ok for single translation or single rotation but not when I have a mix of both
Note that in order to make it run You need to install SimpleElastix, (in to of SimpleItk (because, both package have the same name ...)
Beta Was this translation helpful? Give feedback.
All reactions