Difference between revisions of "Scripting TrackMate"

(Created page with 'Here is an example of full tracking process, using the easy image found in the first tutorial. The following script works as following: * It f...')
 
(make internal links to TrackMate, mention that it is a Jython script, remove semicolons and add whitespace around plusses)
Line 1: Line 1:
Here is an example of full tracking process, using the easy image found in the [[Getting started with TrackMate|first tutorial]]. The following script works as following:
+
Here is an example of full tracking process, using the easy image found in the [[Getting started with TrackMate|first tutorial]]. The following (Jython) script works as following:
  
 
* It fetches the image from the web
 
* It fetches the image from the web
 
* It configures settings for segmentation and tracking
 
* It configures settings for segmentation and tracking
 
* The model is instantiated, with the settings and imp objects
 
* The model is instantiated, with the settings and imp objects
* The trackmate plugin is instantiated with the model object
+
* The [[TrackMate]] plugin is instantiated with the model object
* Then the trackmate object performs all the steps needed.
+
* Then the [[TrackMate]] object performs all the steps needed.
 
* The final results is displayed as an overlay.
 
* The final results is displayed as an overlay.
  
Line 20: Line 20:
 
# Get currently selected image
 
# Get currently selected image
 
# imp = WindowManager.getCurrentImage()
 
# imp = WindowManager.getCurrentImage()
imp = IJ.openImage('http://fiji.sc/tinevez/TrackMate/FakeTracks.tif');
+
imp = IJ.openImage('http://fiji.sc/tinevez/TrackMate/FakeTracks.tif')
imp.show();
+
imp.show()
  
 
#------------------------
 
#------------------------
Line 32: Line 32:
 
settings.segmenter = fiji.plugin.trackmate.segmentation.DogSegmenter()
 
settings.segmenter = fiji.plugin.trackmate.segmentation.DogSegmenter()
 
settings.segmenterSettings = fiji.plugin.trackmate.segmentation.LogSegmenterSettings()
 
settings.segmenterSettings = fiji.plugin.trackmate.segmentation.LogSegmenterSettings()
settings.segmenterSettings.expectedRadius = 2.5;
+
settings.segmenterSettings.expectedRadius = 2.5
  
 
# Configure tracker
 
# Configure tracker
Line 47: Line 47:
 
model.setSettings(settings)
 
model.setSettings(settings)
  
trackmate = fiji.plugin.trackmate.TrackMate_(model);
+
trackmate = fiji.plugin.trackmate.TrackMate_(model)
  
 
#---------------------
 
#---------------------
Line 65: Line 65:
 
#--------------------------
 
#--------------------------
  
model.setInitialSpotFilterValue(3.6);
+
model.setInitialSpotFilterValue(3.6)
  
print('Initial spot filtering with quality above '+str(model.getInitialSpotFilterValue()))
+
print('Initial spot filtering with quality above ' + str(model.getInitialSpotFilterValue()))
  
trackmate.execInitialSpotFiltering();
+
trackmate.execInitialSpotFiltering()
  
 
print(str(model.getSpots()))
 
print(str(model.getSpots()))
Line 77: Line 77:
 
#--------------------------
 
#--------------------------
  
filter1 = fiji.plugin.trackmate.FeatureFilter('QUALITY', 20, True);
+
filter1 = fiji.plugin.trackmate.FeatureFilter('QUALITY', 20, True)
  
print('Spot filtering with '+str(filter1))
+
print('Spot filtering with ' + str(filter1))
  
model.addSpotFilter(filter1);
+
model.addSpotFilter(filter1)
trackmate.execSpotFiltering();
+
trackmate.execSpotFiltering()
  
 
print(str(model.getFilteredSpots()))
 
print(str(model.getFilteredSpots()))
Line 96: Line 96:
 
trackmate.execTracking()
 
trackmate.execTracking()
  
print('Found '+str(model.getNTracks())+' tracks.')
+
print('Found ' + str(model.getNTracks()) + ' tracks.')
  
 
#----------------
 
#----------------
Line 102: Line 102:
 
#----------------
 
#----------------
  
displayer =  fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer();
+
displayer =  fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer()
displayer.setModel(model);
+
displayer.setModel(model)
displayer.render();
+
displayer.render()
displayer.refresh();
+
displayer.refresh()
  
 
</source>
 
</source>

Revision as of 18:05, 19 June 2012

Here is an example of full tracking process, using the easy image found in the first tutorial. The following (Jython) script works as following:

  • It fetches the image from the web
  • It configures settings for segmentation and tracking
  • The model is instantiated, with the settings and imp objects
  • The TrackMate plugin is instantiated with the model object
  • Then the TrackMate object performs all the steps needed.
  • The final results is displayed as an overlay.


import fiji.plugin.trackmate.Settings;
import fiji.plugin.trackmate.TrackMateModel;
import fiji.plugin.trackmate.TrackMate_;
import fiji.plugin.trackmate.Logger;
import fiji.plugin.trackmate.segmentation.DogSegmenter;
import fiji.plugin.trackmate.tracking.SimpleFastLAPTracker;
import fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer;

# Get currently selected image
# imp = WindowManager.getCurrentImage()
imp = IJ.openImage('http://fiji.sc/tinevez/TrackMate/FakeTracks.tif')
imp.show()

#------------------------
# Prepare settings object
#------------------------

settings = fiji.plugin.trackmate.Settings(imp)

# Configure segmenter
settings.segmenter = fiji.plugin.trackmate.segmentation.DogSegmenter()
settings.segmenterSettings = fiji.plugin.trackmate.segmentation.LogSegmenterSettings()
settings.segmenterSettings.expectedRadius = 2.5

# Configure tracker
settings.tracker = fiji.plugin.trackmate.tracking.SimpleFastLAPTracker()
settings.trackerSettings = fiji.plugin.trackmate.tracking.LAPTrackerSettings()

print(str(settings))

#-----------------------------
# Instantiate model and plugin
#-----------------------------

model = fiji.plugin.trackmate.TrackMateModel()
model.setSettings(settings)

trackmate = fiji.plugin.trackmate.TrackMate_(model)

#---------------------
# Execute segmentation
#---------------------

print('Segmenting with parameters:')
print(str(settings.segmenter))
print(str(settings.segmenterSettings))

trackmate.execSegmentation()

print(str(model.getSpots()))

#--------------------------
# Execute initial filtering
#--------------------------

model.setInitialSpotFilterValue(3.6)

print('Initial spot filtering with quality above ' + str(model.getInitialSpotFilterValue()))

trackmate.execInitialSpotFiltering()

print(str(model.getSpots()))

#--------------------------
# Execute spot filtering
#--------------------------

filter1 = fiji.plugin.trackmate.FeatureFilter('QUALITY', 20, True)

print('Spot filtering with ' + str(filter1))

model.addSpotFilter(filter1)
trackmate.execSpotFiltering()

print(str(model.getFilteredSpots()))

#-----------------
# Execute tracking
#-----------------

print('Tracking with parameters:')
print(str(settings.tracker))
print(str(settings.trackerSettings))

trackmate.execTracking()

print('Found ' + str(model.getNTracks()) + ' tracks.')

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

displayer =  fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer()
displayer.setModel(model)
displayer.render()
displayer.refresh()