# ITK Euler3DTransform in MATLAB

**URL:** https://discourse.itk.org/t/itk-euler3dtransform-in-matlab/1131
**Category:** Beginner Questions
**Tags:** registration
**Created:** [July 19, 2018, 3:14pm UTC](https://discourse.itk.org/t/itk-euler3dtransform-in-matlab/1131 "2018-07-19T15:14:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![alven](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/779978/32.png) [@alven](https://discourse.itk.org/u/alven)
#### Post date: [July 19, 2018, 3:14pm UTC](https://discourse.itk.org/t/itk-euler3dtransform-in-matlab/1131/1 "2018-07-19T15:14:55Z")

</div>

Hi!

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,

Jennifer

---

<div class="post-metadata">

### Author: ![Gordian](https://discourse.itk.org/user_avatar/discourse.itk.org/gordian/32/335_2.png) [@Gordian](https://discourse.itk.org/u/Gordian)
#### Post date: [July 21, 2018, 9:50pm UTC](https://discourse.itk.org/t/itk-euler3dtransform-in-matlab/1131/2 "2018-07-21T21:50:01Z")

</div>

Have you considered the default rotation order?

In [itk::Euler3DTransform](https://itk.org/Doxygen/html/classitk_1_1Euler3DTransform.html) the default order is ZXY. In Matlab it is ([eul2rotm](https://de.mathworks.com/help/robotics/ref/eul2rotm.html)) 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.

HTH,  
Gordian
