Rotation matrix from the Transform Module

Operating system: windows 7
Slicer version: 4.8.1
Expected behavior:
Actual behavior:
I create a needle model to insert it to a specific region in my 3D model in slicer. This way, the position of the needle tip and the orientation of the needle is important. The desired pose of the needle is obtained by the translation and rotation part of the transform module (the needle model is defined as the transformed i.e the active transform is applied to it.)
The problem is that:
First: if i save the txt.file of the linear transform and load it in matlab, it can be undestood that the rotation part is not really the rotation matrix i.e the inverse and the traspose are not equal.
(I convert the matrix from the LPS to RAS and the one that i load in matlab is exactly the same as seen in slicer)
Second: The result is not the same as i use the invert in slicer in comparison to the inverse of the matrix from matlab.

I would be appreciated if anyone could help me…

See this topic for explanation and solution: Saving Linear Transformation Matrix

Thanks Mr. Lasso.
Actually i saw the topic and i use it for the conversion to have the same rotation matrix in matlab. But i don’t want to use the Matlab bridge extension. I need to know which euler-angles the Slicer rotation matrix is based on?

You don’t need to use the entire extension but just use the few lines of code that inverts axes and the matrix.

Euler angles are not well suited for representing arbitrary orientations (suffers from gimbal lock and there are multiple parametrizations for the same orientation). I would recommend using orientation matrix or quaternion representation.

Actually, i’m working on a robotic project and i should define the orientation of my tool.
this way i want to know how the transformation module creates the rotation part based on the degrees which can be defined by the users?

Slicer stores transformation as a 4x4 homogeneous transformation matrix, you can use this to compute robot joint coordinates from this matrix (inverse kinematics).

I think that i misunderstood your previous request.
i found that the slicer works on Quaternions based on the Euler angles defined by users.

In Matlab, This could be obtained by converting the transformation matrix of slicer to the Quaternion definition and then find the Euler angles of the related Quaternion.
Thanks a lot from your guidance…

Hello again,

I came to the problem again when using the transform module.
when i save the transformation matrix even the translation part is changed. why is this happen? is there any way to obtain the same translation part (position) which can be seen in slicer software?
Actually i need the position of the needle tip in RAS coordinate system.

here is the position (red square box) which i can be seen in slicer:

and here is the piece of matlab code to convert LPS to RAS for the data which have been saved as linear transform_3. it can be obviously seen that the position is totally changed while the other arrays in rows are the columns of the transform module in slicer.

I know that i ask a lot but i need to use this module correctly. and i am so grateful from your guidance, Mr. Lasso. @lassoan

It seems that you don’t put the matrix elements into their correct location because the orientation part is transposed. If the orientation part is incorrect then the translation is computed incorrectly, too. Probably you need to swap the row and column indices.

Is the needle model origin at (0,0,0)? You can verify this by creating a “Coordinate system” model using “Create models” module in SlicerIGT and apply the same transform to it. Axes of the coordinate system model should intersect at the needle tip.

The transposed Matrix was from the inverse in Matlab code. So the arrays are now at the correct locations.
I add a coordinate system to the of the needle by applying the same transform to both of the needle and coordinate system model.

But the problem is still exist…Is there any translational offset between the RAS and LPS coordinate systems? I mean that multiplying the matrix from the saved file to the diagonal matrix is just because of the rotational difference between the RAS and LPS and it doesn’t have any effect on the translation values…
Another surprising is that the position is changed as changing the rotation part. I mean that if i changed the orientation of the needle and entering the same position in the Matrix, the position data will be different in saved file from the previous file, even they are entered the same in slicer but with different rotation part…

As I wrote above, there is a mistake in how the B (fromParent_LPS) matrix is constructed in your example above. The correct fromParent_LPS matrix looks something like this:

[[  -0.65   -0.44    0.62 -107.59]
 [   0.62    0.15    0.76 -227.31]
 [  -0.43    0.89    0.18  -88.75]
 [   0.      0.      0.      1.  ]]

The inverse operator is responsible for computing the “to parent” transform (displayed in Slicer) from the “from parent” transform (stored in the ITK transform). Do not remove it. The first formula that you used above was correct:

toParent_RAS =
= LPS_to_RAS * toParent_LPS * RAS_to_LPS
= LPS_to_RAS * inv(fromParent_LPS) * RAS_to_LPS
= diag(-1,-1,1,1) * inv(fromParent_LPS) * diag(-1,-1,1,1)

toParent_RAS => shown in Slicer
fromParent_LPS => saved in ITK transform

1 Like

Thanks a lot Mr. Lasso.
By following your suggestion, now it is work…

1 Like