# How to transform fiducial coordinates into image space

**URL:** <https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442>\
**Category:** Development\
**Created:** [January 10, 2021, 10:51pm UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442 "2021-01-10T22:51:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)\
**Post date:** [January 10, 2021, 10:51pm UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442/1 "2021-01-10T22:51:59Z")

</div>

Thanks a lot @lassoan

One last (and kind of dumb) question : If I want to transform my fiducials points to my image space, (rather than rotating my slice view), can I do that by using this transform matrix ? I have some other models, which I don’t know how to rotate. Therefore I don’t want to rotate my image(s), but just adjust fiducial RAS’s, so that they are not cut through multiple slices. Is this doable ?

Thanks a lot.

---

<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:** [January 10, 2021, 10:58pm UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442/2 "2021-01-10T22:58:53Z")

</div>

You can find complete examples of transforming between world (RAS) and voxel (IJK) coordinates (even if the volume and fiducials are under arbitrary, even warping transforms) in the script repository:

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_volume\_voxel\_coordinates\_from\_markup\_fiducial\_RAS\_coordinates](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates)

---

<div class="post-metadata">

**Author:** ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)\
**Post date:** [January 11, 2021, 12:54am UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442/3 "2021-01-11T00:54:22Z")

</div>

If I understand correctly, I need the following step to solve my problem (the rest is for mapping from RAS to IJK). However, when I applied the following code to my fiducials, their coordinates do not change (i.e., point\_VolumeRas = point\_Ras) . Why would that be ? Should I change the first argument of GetTransformBetweenNodes from None to something else ?

```python
# If volume node is transformed, apply that transform to get volume's RAS coordinates
transformRasToVolumeRas = vtk.vtkGeneralTransform()
slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(None, volumeNode.GetParentTransformNode(), transformRasToVolumeRas)
point_VolumeRas = transformRasToVolumeRas.TransformPoint(point_Ras[0:3])

```

---

<div class="post-metadata">

**Author:** ![FatihSogukpinar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fatihsogukpinar/32/7257_2.png) [@FatihSogukpinar](https://discourse.slicer.org/u/FatihSogukpinar)\
**Post date:** [January 11, 2021, 1:02am UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442/4 "2021-01-11T01:02:25Z")

</div>

If my question is not clear enough, here is what I am doing :

```python
fidList = slicer.util.getNode(nodeName)
numFids = fidList.GetNumberOfFiducials()
markupsNode = getNode(nodeName)
for i in range(numFids):
    ras = [0,0,0]
    fidList.GetNthFiducialPosition(i,ras)
    point_Ras = [ras[0], ras[1], ras[2], 1]
    markupsIndex = i 
    markupsNode.GetNthFiducialWorldCoordinates(markupsIndex, point_Ras)
    transformRasToVolumeRas = vtk.vtkGeneralTransform()
    slicer.vtkMRMLTransformNode.GetTransformBetweenNodes(None, volumeNode.GetParentTransformNode(), transformRasToVolumeRas)
    point_VolumeRas = transformRasToVolumeRas.TransformPoint(point_Ras[0:3])

```

But point\_VolumeRas is the same as point\_Ras

Thanks a lot.

---

<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:** [January 11, 2021, 6:13am UTC](https://discourse.slicer.org/t/how-to-transform-fiducial-coordinates-into-image-space/15442/5 "2021-01-11T06:13:03Z")

</div>

`point_VolumeRas` is expected to be the same as `point_Ras`, unless the volume is transformed.

If you want to compute voxel coordinates (IJK) then use the complete example code that I linked above.
