ITK Euler3DTransform in MATLAB


I’m trying to warp a 3D MR image (stored as a nifti-file) to a 3D PET image (stored as a nifti-file) in MATLAB using an Euler3DTransfom transformation matrix from ITK registration. However, the results does not resemble the results derived directly by warping in ITK. I use the following MATLAB code:

A = eul2rotm(Euler3DTransform_double_3_3(1:3)’, ‘ZYX’);
t = Euler3DTransform_double_3_3(4:6);
c = fixed(1:3);
itk_trans = A;
itk_trans(:, 4) = t + c - A*c;
itk_trans = itk_trans; [0, 0, 0, 1]];
nifti_trans = diag([-1, -1, 1, 1])*itk_trans*diag([-1, -1, 1, 1]); % going from LPS -> RAS
mr_info = niftiinfo(…);
mr_im = niftiread(mr_info);
pet_info = niftiinfo(…);
matlab_trans = pet_info.Transform.T*nifti_trans*inv(mr_info.Transform.T); % going from RAS -> matlab coordinate system
mr2pet = imwarp(mr_im, affine3d(inv(matlab_trans)’), ‘OutputView’, imref3d(pet_info.ImageSize));

Does anyone have an idea of what I’m doing wrong?

Best regards,


Have you considered the default rotation order?

In itk::Euler3DTransform the default order is ZXY. In Matlab it is (eul2rotm) ZYX.
Furthermore the coordinate system are not equal. Unfortunaely I do not have a current version. So I do not have access to the niftiinfo() and niftiread() function.