Scripting TrackMate

Revision as of 07:55, 19 June 2012 by JeanYvesTinevez (talk | contribs) (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...')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Here is an example of full tracking process, using the easy image found in the first tutorial. The following 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();