How to use linear transform to convert X,Y Coordinate to RAS coordinates

Hi everyone,

I have multiples 2D coordinates (X,Y). These coordinates are all mapped by a linear transform in which I have access. I’m wondering if there’s a way to convert a 2D coordinates using the linear transform matrix to RAS programatically using python.

For exemple, my 2D coordinate would look like this [220, 100] and my linear transform matrix :
[-0.28146, 0.958297, 0.0494615, 142.429, 0.955756, 0.275374, 0.103442, 134.392, 0.0855075, 0.0763878, -0.993405, -37.0582, 0, 0, 0, 1]

I want to convert my coordinate to RAS so I can then programatically display segmentations in 3D.
I’m new to slicer and is wondering if this is possible to do?

Thank you in advance!

You can get the xy to RAS transform for a given slice view from the slice node, using this function: Slicer/vtkMRMLSliceNode.h at 177f3b324247de4e77d4497cc9121fe37dd5b3f3 · Slicer/Slicer · GitHub

You can get the slice node like this:
https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#change-slice-orientation

1 Like