I wrote a script to automate trackmate that uses a SparseLAPTracker and Stardist Trackmate.
When running:
def writer = new TmXmlWriter(new File(fileTrackMate))
writer.appendModel(model)
writer.appendSettings(settings)
I get a Null Pointer Exception in writer.appendSettings(settings), that I can avoid by adding this line:
settings.trackerSettings['LINKING_FEATURE_PENALTIES'] = new HashMap() //'None'
This seems weird.
Full groovy macro:
#@File(label = "File with cell to track") f
#@boolean showOutput
#@int channel_to_track
imp = IJ.openImage(f.getAbsolutePath());
model = new Model()
// Send all messages to ImageJ log window.
model.setLogger(Logger.IJ_LOGGER)
// Settings (voxel size, time delay), set up from the ImagePlus
def settings = new Settings(imp)
// ------------- Channel 1: Spot detection
// Configure detector - We use the Strings for the keys
settings.detectorFactory = new StarDistDetectorFactory() // Laplacian of gaussian detector,
settings.detectorSettings = [
'TARGET_CHANNEL' : channel_to_track
]
// qualityFilter = new FeatureFilter('QUALITY', 5.5, true) // Configure spot filters - Classical filter on quality, here : 9
// settings.addSpotFilter(qualityFilter)
// -------------- Channel 1: Tracking
// Configure tracker - We do not allow merges and fusions
settings.trackerFactory = new SparseLAPTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultSegmentSettingsMap()
settings.trackerSettings['LINKING_MAX_DISTANCE'] = 15 as double // 0.5 microns displacement may between each timeframe
settings.trackerSettings['GAP_CLOSING_MAX_DISTANCE'] = 1 as double // 0.4 microns displacement before and after gap
settings.trackerSettings['MAX_FRAME_GAP'] = 2 as int // 2 frames gap max allowed during tracking
settings.trackerSettings['LINKING_FEATURE_PENALTIES'] = new HashMap() //'None'
// Add ALL the feature analyzers known to TrackMate. They will
// yield numerical features for the results, such as speed, mean intensity etc.
settings.addAllAnalyzers()
trackmate = new TrackMate(model, settings)
ok = trackmate.checkInput()
if (!ok) IJ.log(trackmate.getErrorMessage());
ok = trackmate.process() // Actually performs the tracking
if (!ok) IJ.log(trackmate.getErrorMessage());
// ---- To display the result:
if (showOutput) {
// A selection.
selectionModel = new SelectionModel( model )
// Read the default display settings.
ds = DisplaySettingsIO.readUserDefault()
// With the line below, we state that we want to color tracks using
// a numerical feature defined for TRACKS, and that has they key 'TRACK_INDEX'.
ds.setTrackColorBy( TrackMateObject.TRACKS, 'TRACK_INDEX' )
displayer = new HyperStackDisplayer( model, selectionModel, imp, ds )
displayer.render()
displayer.refresh()
}
// Echo results with the logger we set at start:
model.getLogger().log( model.toString() )
def fileTrackMate = FilenameUtils.removeExtension(f.getAbsolutePath())+"-Channel_"+channel_to_track+".xml"
def writer = new TmXmlWriter(new File(fileTrackMate))
writer.appendModel(model)
writer.appendSettings(settings)
writer.writeToFile()
IJ.log("Trackmate file written: "+fileTrackMate)
//ExportTracksToXML.export(model, settings, new File(fileTrackMateTerraTracks))
//def fileTrackMateTracks = FilenameUtils.removeExtension(f.getAbsolutePath())+"-Channel_"+channel_to_track+"-Tracks.csv"
//def tableView = ExportStatsTablesAction.createTrackTables(model, selectionModel, new DisplaySettings())
//tableView.trackTable.exportToCsv(new File(fileTrackMateTracks))
//IJ.log("Exported tracks")
import fiji.plugin.trackmate.tracking.jaqaman.SparseLAPTrackerFactory
import fiji.plugin.trackmate.tracking.jaqaman.LAPUtils
import ij.IJ
import org.apache.commons.io.FilenameUtils
import fiji.plugin.trackmate.Model
import fiji.plugin.trackmate.Settings
import fiji.plugin.trackmate.TrackMate
import fiji.plugin.trackmate.SelectionModel
import fiji.plugin.trackmate.Logger
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettingsIO
import fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings
import fiji.plugin.trackmate.io.TmXmlWriter
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings.TrackMateObject
import fiji.plugin.trackmate.action.ExportStatsTablesAction
import fiji.plugin.trackmate.stardist.StarDistDetectorFactory
// Configure track filters - We want to get rid of the two immobile spots at
// the bottom right of the image. Track displacement must be above 10 pixels.
// filter2 = FeatureFilter('TRACK_DISPLACEMENT', 10, True)
// settings.addTrackFilter(filter2)
(It's a quick and dirty bug report, but I can give more details)
Hello!
I wrote a script to automate trackmate that uses a SparseLAPTracker and Stardist Trackmate.
When running:
I get a Null Pointer Exception in
writer.appendSettings(settings)
, that I can avoid by adding this line:This seems weird.
Full groovy macro:
(It's a quick and dirty bug report, but I can give more details)