Mapping markups from coordinates to pixel values

Hello dear 3D slicer community,

We have annotated a dataset of CT scans using markups in 3D slicer, we have used boxes, fiducials and planes. I have written a python script that would map the coordinate values from the patient coordinate space to pixel space, since we need this for downstream tasks. I have had some success, but also experienced that, there is sometimes an offset by one or two pixels, which is especially a problem regarding the z axis (we are using axial view, so the box is either too hight or too low, compared to the annotations in 3D slicer). I noticed that 3D slicer itself is doing this transformation (since it is displaying both the coordinates and the pixel values in the data probe window in the lower left corner, see attached screenshot). My questions are as follows:

Is there a way to extract the exact transformation equation that 3D slicer is using to be able to display pixel values? It seems to be doing it anyway, so the information must be somewhere right?

Secondly, might there be an easier way of achieving what I want? I basically would like to extract every markup as a nifti file .

Sorry, if this question has come up before, I browsed this forum and did not find anything helpful ragarding this problem so far.

Many thanks,

Johannes

You can have a look at the source code of the Data Probe module to see how the calculations are done and there should also be good examples in the script repository.