Exporting x,y,z coordinates for every point along a path

I have traced several neurons using simple neurite tracer and have exported the data as an excel file. However, the data provided only includes x,y,z coordinates for the start and end points of every path. I was wondering if there is any way to extract x,y,z coordinates for every single point along every single path. Sorry if there is an easy answer to this I am very inexperienced with ImageJ.

Hi @mandymell12

I have never used Simple Neurite Tracer myself… so I also do not know how to answer your question. Is the only output you get an excel file? Do you also have an overlay of the traces?

But perhaps the active developer of that plugin @tferr can help you??


Welcome to the forum @mandymell12!)

Sorry for the delay reply (@etadobson, thanks for the ping. I had missed this completely).
It is certainly possible, albeit currently not from the UI. You will have to write a tiny script to obtain the coordinates using SNT’s API. Here is an example (written in python but you can choose any of IJ’s supported languages, that retrieves the coordinates of all the paths in a traces file to the ImageJ console.

You can run it, by pressing [ to open the script editor, copying it to the text area and choosing Python as a language.

#@File traces_file
#@LogService log
#@UIService ui

from tracing import PathAndFillManager

    log.info('Processing %s...' % traces_file)
    pafm = PathAndFillManager.createFromTracesFile(traces_file.getPath())
    for p in range(pafm.size()):
        path = pafm.getPath(p)
        log.info('Coordinates for %s...' % path.toString())
        path_points = path.getPoint3fList()
    ui.showDialog("Could not retrieve coordinates. Not a valid traces file?")

For SWC files, the procedure would have to be slightly more verbose, because those files typically contain no metadata (at least not in a standardized way).

Now presumably, having the coordinates printed to the console is not a convenient way to access them. If you tell us in more detail what are you trying to achieve (do you need them in a tabular form? in image coordinates? all paths? or just some that fulfill certain criteria?) we could probably help further.


Thank you for the reply. I thought I had found a way to get the x,y,z data but maybe it was not correct… I exported the paths to the ROI manager, and then under “More” clicked on “List”. This appeared to give me the x,y,z coordinates for all paths. The goal is to use this data to write a script that will allow for 3D reconstruction in other software. Again I am very inexperienced when it comes to using these kinds of softwares so its possible that I did not get what I was looking for.

Retrieving coordinates from ROI-converted paths could work, but you must keep in mind that 3D paths will be split into 2D ROIs (XY poly-lines) discretized across the Z-planes of the path’s Z dimension. Not sure this is what you are looking for.

What exacltly do you mean by this? You can export your traces as .SWC, the de facto standard in neuron reconstruction. The file is nothing more than a text file, listing the X,Y, Z coordinates (and radii) of traced paths. You can render such files in several programs. For advanced renditions, I strongly recommend Py3DN, built around Blender. For less demanding renditions you can subscribe to the neuroanatomy update site and render tracings in IJ’s built-in 3D viewer.

1 Like

Hi! Thank you so much for the code! I’m trying to export the x,y,z coordinates into a csv format that I can actually do calculations with. I’m having trouble figuring out how to break up the Points3f structure of the coordinates to put them in a csv. Do you have any suggestions?

Hi, I have tried this code, but it shows “Could not retrieve coordinates. Not a valid traces file?”…not sure the probelm. Sorry, I am inexperienced in Fiji. Thanks.

It is an unfortunate (and hopefully temporary) bug in SciJava, in which calling log.info in Python currently fails. The workaround described in this thread works. Also, SNT’s API changed quite a bit since this last post, so here is a more simplified and easier to read version of the snippet:

#@File traces_file
#@LogService log
#@UIService ui

from sc.fiji.snt import Tree
from org.scijava.log import LogLevel

# load traces file: since file may contain one or more rooted structures
# (trees), we'll use a convenience method that handles multiple trees in
# a single file (or directory). For details:
# https://javadoc.scijava.org/Fiji/sc/fiji/snt/Tree.html
trees = Tree.listFromFile(str(traces_file))
if not trees:
    ui.showDialog("Could not retrieve coordinates. Not a valid file?")
    for tree in trees:
        log.log(LogLevel.INFO, 'Processing %s...' % tree.getLabel())
        # now print all nodes in the tree
        for node in tree.getNodes():
            log.log(LogLevel.INFO, node)