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

simpleneuritetracer
Tags: #<Tag:0x00007fd5431292b8>

#1

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.


Finding lengths along traces in Simple Neurite Tracer
#2

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??

eta


#3

Welcome to the forum @mandymell12!)

Sorry for the delay reply (@etarena, 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

try:
    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()
        log.info(path_points)
except:
    ui.showDialog("Could not retrieve coordinates. Not a valid traces file?")
finally:
    ui.getDefaultUI().getConsolePane().show()

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.


#4

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.


#5

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.


#6

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?