Saving Linear Transformation Matrix

Operating system: Windows 10
Slicer version: 4.6.2
Expected behavior: Matrix in ijk coordinates
Actual behavior: Matrix in unknown reference system

Hi guys,
I’m a beginner in Slicer and I’m in trouble saving the transformation matrix. I obtained this matrix with the Fiducial registration module and is expressed w.r.t. RAS reference system, I think. When I save it in other formats, such as .h5 or .txt or .mat, the values are different. I think that automatically the reference frame w.r.t. it is expressed has changed; is it based of IJK or LPS frames?
Thanks

I think this topic should answer your questions: Displayed transform vs .tfm content

Thank you @lassoan for your answer. Yes, the question is the same, but I’m sorry I didn’t understand what I should do to obtain the transformation matrix in xyz coordinates.

What anatomical axes your xyz axes correspond to: LPS or RAS?

Do you process your images in Matlab?

Maybe I was not clear in the question, I’m sorry but I was a little bit confused.
I didn’t understand how to deal with the matrix in the txt file, so w.r.t. LPS axes (e.g.I have to do its inverse, to pre or post multiply it for a certain matrix ,…) to obtain the matrix that appears in Slicer. How is it possible?
Then I suppose that applying this matrix to my moving dataset, e.g. I can apply it using Matlab, I can obtain the same results that I obtained applying the tranformation matrix in Slicer and saving the result.
If I’m not clear, please let me know.

Here is the conversion done by Slicer’s MatlabBridge extension:

If you need the values that are displayed in Slicer, use the computation in the ‘slicer’ branch.

Note that Slicer’s MatlabBridge extension allows you to run Matlab functions directly from the Slicer GUI. So, if you are forced to use Matlab for certain processing, you can still do that, while keeping the GUI and rest of your workflow in Slicer/Python. See more information about the MatlabBridge extension here: https://www.slicer.org/wiki/Documentation/Nightly/Extensions/MatlabBridge

This is full python code to get the transform matix same in Slicer

The important thing in python
We can not use

transfrom_itk = np.reshape(transform_raw, (3,4))
or
transfrom_itk = np.reshape(transform_raw, (3,4), order='F')

reader = pd.read_table("Your path\\LinearTransform_3.txt", header=None)
transform_raw = np.array(list(map(float, reader[0][3].split(':')[-1].split(' ')[1:])))

transform_itk  = np.zeros((4,4))
transform_itk[:3,:3] = np.reshape(transform_raw [:9], (3, 3))
transform_itk[:3, 3] = transform_raw [9:12]
transform_itk[3,3] = 1

lps2ras = np.diag([-1, - 1, 1, 1])
ras2lps = np.diag([-1, - 1, 1, 1])
transform_slicer = lps2ras @ np.linalg.inv(transform_itk) @ ras2lps
1 Like