I am writing a groovy script to batch process the detection of particle trajectories in multiple avi videos using TrackMate.
The script and analysis works well except when I want to add filters on the tracks. I am new to groovy and somehow not getting the syntax right, which is based on a Jython script (I could not find examples for groovy online).
Specifically, my code up to adding the filters is:
//Input variables
#@ File (label = "Input directory", style = "directory") srcFile
#@ File (label = "Output directory", style = "directory") dstFile
#@ Boolean (label = "Keep directory structure when saving", value = true) keepDirectories
#@ String (label = "File extension", value=".avi") ext
#@ double (label = "Spot radius", stepSize=0.1) radius
#@ double (label = "Quality threshold") threshold
#@ int (label = "Max frame gap") frameGap
#@ double (label = "Linking max distance") linkingMax
#@ double (label = "Gap-closing max distance") closingMax
#@ double (label = "min N spots") nSpotMin
import ij.IJ
import ij.ImagePlus
import ij.process.ImageProcessor
import ij.process.ShortProcessor
import ij.ImageStack;
import ij.plugin.AVI_Reader;
import fiji.plugin.trackmate.providers.SpotAnalyzerProvider
import fiji.plugin.trackmate.providers.EdgeAnalyzerProvider
import fiji.plugin.trackmate.providers.TrackAnalyzerProvider
import fiji.plugin.trackmate.features.FeatureFilter
import fiji.plugin.trackmate.Model
import fiji.plugin.trackmate.Settings
import fiji.plugin.trackmate.TrackMate
import fiji.plugin.trackmate.detection.LogDetectorFactory
import fiji.plugin.trackmate.tracking.LAPUtils
import fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory
import fiji.plugin.trackmate.action.ExportTracksToXML
def main() {
srcFile.eachFileRecurse {
name = it.getName()
if (name.endsWith(ext)) {
process(it, srcFile, dstFile, keepDirectories)
}
}
}
def process(file, src, dst, keep) {
println "Processing $file"
// Opening the video
read = new AVI_Reader();
stack = read.makeStack(file.getAbsolutePath(), 1, 0, false, true, true)
imp = new ImagePlus("avi", stack)
imp.getStack()
imp.show()
// Swap Z and T dimensions if T=1
dims = imp.getDimensions() // default order: XYCZT
if (dims[4] == 1) {
imp.setDimensions( dims[2,4,3] )
}
// Setup settings for TrackMate
settings = new Settings()
settings.setFrom(imp)
settings.dt = 1.0
settings.detectorFactory = new LogDetectorFactory()
settings.detectorSettings = settings.detectorFactory.getDefaultSettings()
settings.detectorSettings['RADIUS'] = radius
settings.detectorSettings['THRESHOLD'] = threshold
settings.detectorSettings['DO_SUBPIXEL_LOCALIZATION']= true
println settings.detectorSettings
filter1= FeatureFilter('NUMBER_SPOTS', nSpotMin, true)
settings.addTrackFilter(filter1)
filter2 = FeatureFilter('TRACK_DISPLACEMENT', 15, True)
settings.addTrackFilter(filter2)
…
As soon as I add these filters, I get the error “groovy.lang.MissingMethodException: No signature of method: org.scijava.plugins.scripting.groovy.GroovyScriptEngine.TrackBranchingAnalyzer() is applicable for argument types: (String, Double, Boolean) values: [NUMBER_SPOTS, 10.0, true]”
If I remove the filters, everything goes smoothly, so I cut the code off at this point in this example.
I tried various ways to formulate the line to add filters differently but have not had any luck.
Does anyone know the correct syntax?