Skip to content, Skip to search

Changes

Scripting TrackMate

295 bytes added, 09:19, 9 July 2013
WIP: move to TrackMate v2.1.0 API
Since we are calling the internals of TrackMate, we must get to know a bit of its guts. I have tried to come up with a rational design; though not always successfully. There is 3 main classes to interact with in a script:
* TrackMateModel Model ([http://fiji.sc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/TrackMate_/src/main/java/fiji/plugin/trackmate/TrackMateModel.java;hb=HEAD <code>fiji.plugin.trackmate.TrackMateModel</code>]) is the class in charge of <u>storing the data</u>. It cannot do anything to create it. It can help you follow manual modifications you would made in the manual editing mode, interrogate it, ... but it is conceptually just a data recipient.
* Settings ([http://fiji.sc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=src-plugins/TrackMate_/src/main/java/fiji/plugin/trackmate/Settings.java;hb=HEAD <code>fiji.plugin.trackmate.Settings</code>]) is a part of the model. It is a class storing the fields that will configure TrackMate and pilot how the data is created. As you can see, it is mainly make of public fields.
<source lang="python">import fiji.plugin.trackmate.Settings as Settingsimport fiji.plugin.trackmate.Settings;Model as Modelimport fiji.plugin.trackmate.TrackMateModel;SelectionModel as SelectionModelimport fiji.plugin.trackmate.TrackMate_;TrackMate as TrackMateimport fiji.plugin.trackmate.Logger;as Loggerimport fiji.plugin.trackmate.segmentationdetection.DogSegmenter;DetectorKeys as DetectorKeysimport fiji.plugin.trackmate.detection.DogDetectorFactory as DogDetectorFactoryimport fiji.plugin.trackmate.tracking.SimpleFastLAPTracker;as SimpleFastLAPTrackerimport fiji.plugin.trackmate.tracking.LAPUtils as LAPUtilsimport fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer;as HyperStackDisplayerimport fiji.plugin.trackmate.features.FeatureFilter as FeatureFilter
# Get currently selected image
# imp = WindowManager.getCurrentImage()#imp = IJ.openImage('http://fiji.sc/tinevez/TrackMatesamples/FakeTracks.tif')
imp.show()
#------------------------
# Prepare settings object
#------------------------
settings = fiji.plugin.trackmateSettings()settings.SettingssetFrom(imp) # Configure segmenterdetectorsettings.segmenter detectorFactory = fiji.plugin.trackmate.segmentation.DogSegmenterDogDetectorFactory()settings.segmenterSettings detectorSettings = fiji{ DetectorKeys.pluginKEY_DO_SUBPIXEL_LOCALIZATION : True, DetectorKeys.trackmateKEY_RADIUS : 2.segmentation5, DetectorKeys.LogSegmenterSettings()KEY_TARGET_CHANNEL : 1,settings DetectorKeys.segmenterSettingsKEY_THRESHOLD : 0.expectedRadius = 2, DetectorKeys.5KEY_DO_MEDIAN_FILTERING : False,}  
# Configure tracker
settings.tracker = fiji.plugin.trackmate.tracking.SimpleFastLAPTracker()settings.trackerSettings = fiji.plugin.trackmate.trackingLAPUtils.LAPTrackerSettingsgetDefaultLAPSettingsMap()
print(str(settings))
#-----------------------------
# Instantiate model and plugin
#-----------------------------
model = fiji.plugin.trackmate.TrackMateModelModel()model.setSettings(settings) trackmate = fiji.plugin.trackmate.TrackMate_TrackMate(model, settings)
#---------------------
# Execute segmentation
#---------------------
print('Segmenting with parameters:')
print(str(settings.segmenterdetectorFactory))print(str(settings.segmenterSettingsdetectorSettings)) trackmate.execSegmentationexecDetection()
print(str(model.getSpots()))
#--------------------------
# Execute initial filtering
#--------------------------
settings.initialSpotFilterValue = 3.6
print('Initial spot filtering with quality above ' + str(settings.initialSpotFilterValue))
trackmate.execInitialSpotFiltering()
print(str(model.getSpots()))
#--------------------------
# Execute spot filtering
#--------------------------
filter1 = fiji.plugin.trackmate.FeatureFilter('QUALITY', 20, True)
print('Spot filtering with ' + str(filter1))
settings.addSpotFilter(filter1)
trackmate.execSpotFiltering(True) print(str(model.getFilteredSpotsgetSpots()))
#-----------------
# Execute tracking
#-----------------
print('Tracking with parameters:')
print(str(settings.tracker))
print(str(settings.trackerSettings))
trackmate.execTracking()
print('Found ' + str(model.getNTracksgetTrackModel().nTracks(True)) + ' tracks.')
#----------------
# Display results
#----------------
displayer selectionModel = fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayerSelectionModel(model)displayer.setModel= HyperStackDisplayer(model, selectionModel, imp)
displayer.render()
displayer.refresh()
Emailconfirmed, incoming, administrator, uploaders
1,394
edits