Trackmate export hyperstack display to PNG in a Jython script

Hi @tinevez,

Hope you’re doing well!

With your kind help, we’ve been able to automate trackmate and its numeric output via scripting, which is working amazing for us, but would also like to have some visual record of segmentation/tracking process, along with the numeric output.

Can you please point us how to include functionality of hyperstack display -> PNG output of a few frames of our video, saved to harddrive, into a macro/script?

Thank you!

Hi @l-jaye

The command that does that is based on ImageJ capture image. You can find the code here:

This is what you would have to call to capture a RGB capture of the movie.
Best
jy

3 Likes

Hi @tinevez,

Thanks to the example Jython script you provided, I am able to perform batch analysis. Now I would also like to export the capture of the hyperstack display in the script like what @l-jaye mentioned above. Since the example script is written in Jython, does that mean I will need to adopt the java script you’ve shown into Jython for this purpose? Ideally I would like to implement the capture overlay step after generating the display:

#----------------
# Display results
#----------------

model.getLogger().log('Found ' + str(model.getTrackModel().nTracks(True)) + ' tracks.')
    
selectionModel = SelectionModel(model)
displayer =  HyperStackDisplayer(model, selectionModel, imp)
displayer.render()
displayer.refresh()

#save image with overlay

#-------------

I’m new to scripting and I’m not sure how to do that. I hope you can give me more hints. Many thanks!

This is a very late response but for someone looking for an answer here is how you can save an image with tracks overlay using jython.


from fiji.plugin.trackmate.action import CaptureOverlayAction
from ij.io import FileSaver

# define trackmate model, do tracking...
# ...
model = trackmate.getModel()
selectionModel = SelectionModel(model)
displayer =  HyperStackDisplayer(model, selectionModel, imp)
displayer.render()
displayer.refresh()

# command CaptureOverlayAction.capture(trackmate, startframe, endframe) 
capture = CaptureOverlayAction.capture(trackmate, -1, imp.getNFrames()) 

# save capture image with overlay as tiff 
FileSaver(capture).saveAsTiff( savePath, saveName + ".tif"))

For reference: Scripting to export track movies using the CaptureOverlayAction function

2 Likes