How do I load fiducial node data from Slicer in Python?

405 views Asked by At

I am trying to import the R,A,S (x,y,z) coordinates of fiducial nodes defined in the program Slicer into a Python code.

Using 3D Slicer 4.4.0, I created a number of fiducial nodes in space defined by R,A,S coordinates (x,y,z coordinates) by visually placing the points. I did not enter in the coordinates, I just pointed and clicked where I wanted them put. I then saved the node placement data, and Slicer saved that data in an FCSV file. I am able to load that data in Slicer again, and I am also able to read the data by opening the FCSV file using a text editor. In the text editor, the node data is listed in this format (where the 2nd, 3rd, and 4th entries in each line of node data are the x,y,z coordinates):

# Markups fiducial file version = 4.4
# CoordinateSystem = 0
# columns = 
id,x,y,z,ow,ox,oy,oz,vis,sel,lock,label,desc,associatedNodeID
vtkMRMLMarkupsFiducialNode_1,-48.0839,17.9915,59.9101,0,0,0,1,1,1,0,F-2,,vtkMRMLScalarVolumeNode2
vtkMRMLMarkupsFiducialNode_2,-46.5946,-4.34737,59.9101,0,0,0,1,1,1,0,F-3,,vtkMRMLScalarVolumeNode2
vtkMRMLMarkupsFiducialNode_3,-48.5803,-24.2042,59.9101,0,0,0,1,1,1,0,F-4,,vtkMRMLScalarVolumeNode2
vtkMRMLMarkupsFiducialNode_4,-47.0911,-44.061,59.9101,0,0,0,1,1,1,0,F-5,,vtkMRMLScalarVolumeNode2

... and it continues on with more points.

I would like to have a way to import the coordinates of the data into python (from a python script), preferably into 3 separate arrays each containing the x, y, or z, coordinates, or into one 3xN or Nx3 array that contains the x, y, z data for each point. I don't care what order the points are in.

I tried retrieving the FCSV file using the code below:

os.chdir('C:\Users\Me\Desktop\Code_folder')
InputFile = open('C:\Users\Me\Desktop\Code_folder\f.fcsv','r')
lines = InputFile.readlines()
InputFile.close()

... but it returned an error that stated:

runfile('C:/Users/Me/Documents/Python Scripts/load_fiducials_test.py', wdir='C:/Users/Me/Documents/Python Scripts') File "C:/Users/Me/Documents/Python Scripts/load_fiducials_test.py", line 126 InputFile = open('C:\Users\Me\Desktop\Code_folder\f.fcsv','r') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

How might I go about retrieving those data points, either by modifying my previous attempt or by trying another way, for use as an array in Python?

0

There are 0 answers