# Getting null coordinates for newly acquired Fiducials

**URL:** <https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638>\
**Category:** Support\
**Created:** [December 11, 2017, 6:08pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638 "2017-12-11T18:08:06Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 6:08pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/1 "2017-12-11T18:08:06Z")

</div>

Hello,

I am returning to Slicer after several years, and I’m finding that the Fiducials interface does not properly acquire the coordinates the selected point. Everything that I acquire shows RAS coordinates set to 0.0, 0.0, 0.0. Is there something that I need to be doing to acquire proper Landmark coordinates?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/4/3428c4a11f9755a2cb15d322200026c1abc80538.png)

Best wishes

Michel Audette

---

<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:** [December 11, 2017, 6:29pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/2 "2017-12-11T18:29:51Z")

</div>

“New fiducial” button in the advanced section of Markups module creates a markup in the (0,0,0) position. To create a point in a specific position, click on the “Place fiducial” button on the toolbar then click in a viewer to place it.

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 6:33pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/3 "2017-12-11T18:33:06Z")

</div>

Hi. I cannot find the Place Fiducial button. Which toolbar do you mean?

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 6:46pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/4 "2017-12-11T18:46:17Z")

</div>

Never mind. I found it. Thanks for your support.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 11, 2017, 6:46pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/5 "2017-12-11T18:46:44Z")

</div>

This should help illustrate: [https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#Mouse\_Modes](https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#Mouse_Modes)

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 8:40pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/6 "2017-12-11T20:40:06Z")

</div>

Hi again,

I am using the Fiducials to initialize a deformable surface model, and the code for this model seems to operate in voxel coordinates rather than world coordinates. Can you tell me if I can save in the Fiducials in voxel coordinates?

Best wishes,

Michel

---

<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:** [December 11, 2017, 8:56pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/7 "2017-12-11T20:56:31Z")

</div>

Fiducial positions are displayed and saved in physical coordinates (in mm).

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 9:02pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/8 "2017-12-11T21:02:30Z")

</div>

Yes, I know. Hence the question. Is there a flag that I can use to save in IJK, or must I get the IJK-RAS transformation from the mrml file?

I was under the impression that saving in IJK format was feasible with a resource flag set somehow.

---

<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:** [December 11, 2017, 9:06pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/9 "2017-12-11T21:06:27Z")

</div>

Fiducials are not linked to a particular volume, so you cannot save them relative to a particular volume’s IJK coordinate system. I don’t remember this having come up as a need ever, since volumes are defined in physical coordinate system, too.

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 9:12pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/10 "2017-12-11T21:12:04Z")

</div>

It did come up. I googled " fiducials slicer voxel coordinates". In fact, it came up with my former student Rabia Haq, but she is not providing much in terms of support, so I’m having to redo the same legwork now.

---

<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:** [December 11, 2017, 9:20pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/11 "2017-12-11T21:20:14Z")

</div>

I guess you’ve found how to get IJK positions from the saved fiducial positions, but if not then let us know.

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 11, 2017, 9:23pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/12 "2017-12-11T21:23:00Z")

</div>

I cannot follow what they did. I need to have a simple solution in just a few lines, not several threads with the keywords I am looking for. I merely pointed them out to show you that the issue has come up before.

---

<div class="post-metadata">

**Author:** ![Nicole\_Aucoin](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nicole\_Aucoin](https://discourse.slicer.org/u/Nicole_Aucoin)\
**Post date:** [December 11, 2017, 10:03pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/13 "2017-12-11T22:03:17Z")

</div>

Fiducial points are linked to the volume for which the slice on which  
they’ve placed, via  
GetNthFiducialAssociatedNodeID

I’d started to work on the Get method for IJK but didn’t finish it - the  
use case was for sending it to CLI modules via the storage node.

If you get the RAS to IJK transform of the volume you’re working with and  
create a new transform node with that transform, you can place your world/  
RAS coordinates fiducial list under it and then harden it to get the IJK  
coordinates (or just display them in the Markups module by clicking the  
Transformed checkbox).

---

<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:** [December 11, 2017, 10:03pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/14 "2017-12-11T22:03:50Z")

</div>

What would you like to achieve? Run a Matlab function using inputs provided by Slicer?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 11, 2017, 10:13pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/15 "2017-12-11T22:13:11Z")

</div>

This post is a follow up of [http://slicer-users-archive.65878.n3.nabble.com/convert-fiducials-in-slicer-to-world-coordinates-td4026776.html](http://slicer-users-archive.65878.n3.nabble.com/convert-fiducials-in-slicer-to-world-coordinates-td4026776.html)

**WARNING: This snippets posted below are not production ready and will most likely break in the future**

### Fiducial and coordinate system

It is indeed possible to choose the coordinate system when using the python console (there is not yet a UI to select the output coordinate system). The default is LPS.

Here is a code snipped allowing to save fiducials from the python console.

```python
node = slicer.util.getNode("vtkMRMLMarkupsFiducialNode1")

fileName = "/tmp/markups.fcsv"

io = slicer.app.ioManager()
snode = io.createAndAddDefaultStorageNode(node)
snode.SetFileName(fileName)

fileFormat = io.completeSlicerWritableFileNameSuffix(node)
snode.SetWriteFileFormat(fileFormat)

snode.SetCoordinateSystem(slicer.vtkMRMLMarkupsStorageNode.RAS)

snode.WriteData(node)

```

`IJK` is already a valid format, the only “issue” is that the writer doesn’t implement it yet:

> <https://github.com/Slicer/Slicer/blob/47e5662bf321acb87f15e83d7f3415faeb44f72f/Modules/Loadable/Markups/MRML/vtkMRMLMarkupsFiducialStorageNode.cxx#L517-L530>

### Exporting fiducial to IJK (aka voxel coordinates): A draft implementation

If I recall properly, the reason why this is not yet implemented is because the IJKToRAS matrix is associated with the volume and there is no obvious linkage between the volume and the fiducial.

That said, you could do the following:

```python
def exportFiducials(markupNode, outputFileName, outputCoordinates, associatedVolumeNode=None):
  """Export fiducials to `outputFileName` considering the `outputCoordinates`.

  Supported outputCoordinates are `LPS`, `RAS` and `IJK`.

  Specifying `IJK` requires `associatedVolumeNode` to be specified.
  """
  
  # Create temporary node
  savedMarkupNode = slicer.vtkMRMLMarkupsFiducialNode()
  savedMarkupNode.Copy(markupNode)
  
  snode = slicer.vtkMRMLMarkupsFiducialStorageNode()
  snode.SetFileName(outputFileName)
  savedMarkupNode.SetAndObserveStorageNodeID(snode.GetID())
  
  io = slicer.app.ioManager()
  fileFormat = io.completeSlicerWritableFileNameSuffix(markupNode)
  snode.SetWriteFileFormat(fileFormat)
  
  snode.SetCoordinateSystem(outputCoordinates)
  
  if outputCoordinates == slicer.vtkMRMLMarkupsStorageNode.IJK:
  
    if associatedVolumeNode is None: 
      print("Can not save markup node with IJK coordinate system without a valid volume node")
      return
    
    # Get RAStoIJK matrix associated with the volume
    rasToIJK = vtk.vtkMatrix4x4()
    associatedVolumeNode.GetRASToIJKMatrix(rasToIJK)
    
    # Convert from RAS to IJK
    for idx in range(savedMarkupNode.GetNumberOfFiducials()):
      rasCoord = [0.] * 4
      savedMarkupNode.GetNthFiducialWorldCoordinates(idx, rasCoord)
      ijkCoord = [0.] * 4
      rasToIJK.MultiplyPoint(rasCoord, ijkCoord)
      savedMarkupNode.SetNthFiducialWorldCoordinates(idx, ijkCoord)
  
  snode.WriteData(node)

# Prerequisites
# (1) Download MRHead
# (2) Place a fiducial

# Download sampledata
volume = slicer.util.getNode("MRHead")

# Get Markup (aka fiducial)
node = slicer.util.getNode("vtkMRMLMarkupsFiducialNode1")

# Output filename
fileName = "/tmp/markups.fcsv"

exportFiducials(node, fileName, slicer.vtkMRMLMarkupsStorageNode.IJK, volume)

```

The file will then indicate `CoordinateSystem = 2` which correspond to `IJK`

```auto
# Markups fiducial file version = 4.8
# CoordinateSystem = 2
# columns = id,x,y,z,ow,ox,oy,oz,vis,sel,lock,label,desc,associatedNodeID
vtkMRMLMarkupsFiducialNode_0,-2.1452,-27.7047,-48.6402,0,0,0,1,1,1,0,F-1,,vtkMRMLScalarVolumeNode1

```

---

<div class="post-metadata">

**Author:** ![MichelODU](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@MichelODU](https://discourse.slicer.org/u/MichelODU)\
**Post date:** [December 12, 2017, 4:16pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/16 "2017-12-12T16:16:04Z")

</div>

Thanks for your support, gents. Warm wishes, Michel

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [October 29, 2019, 3:39am UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/17 "2019-10-29T03:39:40Z")

</div>

Hi andras,  
Is there a way to convert ijk points to ras world coordinates.

Thank you

Regards,  
Saima Safdar

---

<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:** [October 29, 2019, 12:08pm UTC](https://discourse.slicer.org/t/getting-null-coordinates-for-newly-acquired-fiducials/1638/18 "2019-10-29T12:08:27Z")

</div>

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