# Porting a transformation from Matlab to Slicer

**URL:** <https://discourse.slicer.org/t/porting-a-transformation-from-matlab-to-slicer/868>\
**Category:** Support\
**Created:** [August 14, 2017, 7:49pm UTC](https://discourse.slicer.org/t/porting-a-transformation-from-matlab-to-slicer/868 "2017-08-14T19:49:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [August 14, 2017, 7:49pm UTC](https://discourse.slicer.org/t/porting-a-transformation-from-matlab-to-slicer/868/1 "2017-08-14T19:49:04Z")

</div>

Operating system: Windows 10  
Slicer version: 4.7  
Expected behavior: Transformation to match registered and transformed image in Matlab  
Actual behavior: Transformation is off

Hi, I am trying to double check the results of image registration (developed in Matlab) by copying the linear transformation matrix into slicer and applying it to the image. However, I do not get the same result. In matlab I use the affine3d() function to apply a homogenous transformation to an image.

I know that there is a difference between coordinate system definitions in Matlab and Slicer (IJK to RAS), but I still can’t seem to match the registration output when trying to compensate for this. What is the correct way of porting matlab affine3d() transformations to slicer?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 15, 2017, 2:24am UTC](https://discourse.slicer.org/t/porting-a-transformation-from-matlab-to-slicer/868/2 "2017-08-15T02:24:30Z")

</div>

Slicer works in RAS coordinate system, but transform files are written as LPS, so you need a base transform between them: multiply from left and right by `diag([-1,-1,1,1])`.  
You might also need to invert the matrix, depending on what you need: transform _to_ or _from_ parent.

---

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [August 15, 2017, 3:56am UTC](https://discourse.slicer.org/t/porting-a-transformation-from-matlab-to-slicer/868/3 "2017-08-15T03:56:56Z")

</div>

Thanks, I just realised shortly after posting that the transforms are in LPS, and the above base transform works correctly!
