Skip to content, Skip to search


Scripting TrackMate

3,060 bytes added, 08:15, 10 September 2018
no edit summary
By default, TrackMate only computes a very limited number of features. The GUI forces TrackMate to compute them all, but if you do scripting, you will have to explicitly configures TrackMate to compute the features you desire. This is done by adding feature analyzers to the settings object.
There are some gotchas: some feature analyzers require other numerical features to be already calculated. If something does not work, it is a good idea to directly check the preamble in the source code of the analyzers ([ / TrackMate feature logic]).
Finally, depending on their type, numerical features are not stored at the same place:
== Calling TrackMate with multi-channel analyzer == TrackMate allows for the addition of jar files that contain extra TrackMate modules. The [[TrackMate#Downloadable_jars|multi-channel spot mean intensity analyzer]] is such a module. As any other module it can be used in a script, provided the jar file is in the plugins or jars folder of Fiji: {{GitHubEmbed|org=fiji|repo=TrackMate|source=../../../scripts/}} == Making TrackMate macro recordable with a 64-line script == Contributed by {{Person|JeanYvesTinevezEglinger}} during a NEUBIAS course. Quoting from Jan: <blockquote>"The macro language is too limited to work with such awesome things as TrackMate, but that you can do everything with a more powerful scripting language. So when using a 64-line script to call it, it actually is macro recordable."</blockquote> {{GitHubEmbed|org=fiji|repo=TrackMate|source=../../../scripts/Run_TrackMate_Headless.groovy}}  == Add 3D maximas in the ROI Manager using TrackMate ==  Using the 3D spots finder of TrackMate, it is possible to add the maximas to the ROI Manager with a simple Jython code: <source lang="python"># @ImagePlus imp # Importsfrom fiji.plugin.trackmate.detection import LogDetectorfrom net.imglib2.img.display.imagej import ImageJFunctions from ij.plugin.frame import RoiManagerfrom ij.gui import PointRoi # Set the parameters for LogDetectorimg = ImageJFunctions.wrap(imp)interval = imgcal = imp.getCalibration()# Get the calibration from the metadata if existscalibration = [cal.pixelWidth, cal.pixelHeight, cal.pixelDepth] # Values to enter based on the TrackMate GUIradius = 5 # the radius is half the diameterthreshold = 1050doSubpixel = TruedoMedian = True  # Setup spot detector (see public LogDetector(RandomAccessible<T> img,# Interval interval,# double[User talk] calibration,# double radius,# double threshold,# boolean doSubPixelLocalization,# boolean doMedianFilter) detector = LogDetector(img, interval, calibration, radius, threshold, doSubpixel, doMedian) # Start processing and display the resultsif detector.process(): # Get the list of peaks found peaks = detector.getResult() print str(len(peaks)), "peaks were found."  # Add points to ROI manager rm = RoiManager.getInstance() if not rm:JeanYvesTinevez|talk]] rm = RoiManager() 09  # Loop through all the peak that were found for peak in peaks:20 # Print the current coordinates print peak.getDoublePosition(0), 11 March 2015 peak.getDoublePosition(CDT1), peak.getDoublePosition(2) # Add the current peak to the Roi manager roi = PointRoi(peak.getDoublePosition(0) / cal.pixelWidth, peak.getDoublePosition(1) / cal.pixelHeight) # Set the Z position of the peak otherwise the peaks are all set on the same slice roi.setPosition(int(round(peak.getDoublePosition(2) / cal.pixelDepth))+1) rm.addRoi(roi) # Show all ROIs on the image rm.runCommand(imp, "Show All") else: print "The detector could not process the data."</source>