Created
October 30, 2019 01:08
-
-
Save nkicg6/dac228705c8c04324219263c3c6aa33b to your computer and use it in GitHub Desktop.
Jython script to fit paths automatically from a traces file and image in SNT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @SNTService sntService | |
# script to fit paths from previous tracing session programatically via Jython and SNT | |
# single threaded fitting and slow. Will refactor to multithreaded in future.... | |
# see: https://forum.image.sc/t/fit-paths-with-simple-neurite-tracer-api/30139/ | |
# test traces file | |
traces_test = "path/to/traces_file.traces" | |
# test img file | |
image_test = "path/to/image_file.tif" | |
import os | |
from java.io import File | |
from sc.fiji.snt import Path | |
from sc.fiji.snt import PathFitter | |
from sc.fiji.snt import PathAndFillManager | |
from sc.fiji.snt import Tree | |
print("starting") | |
snt = sntService.initialize(image_test, False) # No GUI | |
sntService.loadTracings(traces_test) | |
loaded_tree = sntService.getTree(False) | |
pfm = PathAndFillManager() # for later quick export. | |
pfm.addTree(loaded_tree) # add tree to manager instance | |
for p in loaded_tree.list(): | |
pf = PathFitter(snt, p) | |
pf.setMaxRadius(10) # option for path fitting. | |
pf.setScope(PathFitter.RADII_AND_MIDPOINTS) # another option for path fitting. | |
pf.setReplaceNodes(True) | |
pf.call() | |
print("fitting {} : {}".format(p, str(pf.getSucceeded()))) | |
new_traces_fname = os.path.join(os.path.dirname(traces_test), "new_traces.traces") | |
new_properties_fname = os.path.join(os.path.dirname(traces_test), "new_properties.csv") | |
print("saving csv properties: {}".format(new_properties_fname)) | |
pfm.exportToCSV(File(new_properties_fname)) # export quick measurements to csv, using Java IO file. | |
print("saving traces properties: {}".format(new_traces_fname)) | |
sntService.save(new_traces_fname) # save traces file for csv | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment