Skip to content, Skip to search

Changes

TrakEM2 Scripting

1,060 bytes added, 11:03, 2 July 2015
Interact with a Ball object
ballOb.repaint(True, None)
##############
</source>
 
== Export all Ball objects as a CSV file ==
 
<source lang="python">
# Open a text window containing all Ball objects as a CSV file,
# in calibrated coordinates.
# The text window has a "File - Save" menu for saving to a file.
 
# Albert Cardona 2015-07-02 for Jemima Burden at UCL.
 
# See also the API of the Ball class:
# https://github.com/trakem2/TrakEM2/blob/master/TrakEM2_/src/main/java/ini/trakem2/display/Ball.java#L716
 
 
from ini.trakem2.display import Display, Ball
from ij.text import TextWindow
 
ball_obs = Display.getFront().getLayerSet().getZDisplayables(Ball)
 
# One entry for each id,x,y,z,r
rows = []
 
# Iterate every Ball instance, which contains one or more x,y,z,r balls
for ball_ob in ball_obs:
id = ball_ob.getId()
# Iterate every x,y,z,r ball of a Ball instance, calibrated
wbs = ball_ob.getWorldBalls()
for ball_coords in wbs:
# Store every ball as a row with id, x, y, z, r
rows.append(str(id) + "," + ",".join(str(c) for c in ball_coords))
 
csv = "\n".join(rows)
 
t = TextWindow("Balls CSV", csv, 400, 400)
</source>
Emailconfirmed, uploaders
653
edits