Linear Motion LAP Tracker maximal amount of tracks

I am using ImageJ and Trackmate during a research to analyze spatters of a technical process.
As Tracker i use the Linear Motion LAP Algorithm, because the spatters have a very straight (no curves), roughly linear motion.

It works very well for the first part of my video but then i get some problems.

Like https://forum.image.sc/t/linear-motion-lap-tracker-in-trackmate-only-tracks-1-8th-of-video/6334, it seems that there is a limit of trackable Tracks. In my case its 206 Tracks (without any filter) after 350 frames. And every Track afterwards can’t be tracked, even if its obvious that there should be a lot more tracks.

The Analysis is started with a jython script. I checked if i did any mistake in my script, so i changed just the part of configuring the tracker from:

settings.trackerFactory = KalmanTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
settings.trackerSettings[‘KALMAN_SEARCH_RADIUS’] = 15.0
settings.trackerSettings[‘GAP_CLOSING_MAX_FRAME_GAP’] = 3
settings.trackerSettings[‘LINKING_MAX_DISTANCE’] = 15.0

to the Sparse LAP Tracker:

settings.trackerFactory = SparseLAPTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
settings.trackerSettings[‘LINKING_MAX_DISTANCE’] = 15.0
settings.trackerSettings[‘GAP_CLOSING_MAX_DISTANCE’]= 15.0
settings.trackerSettings[‘MAX_FRAME_GAP’]= 3

and with that change i get more than 1000 Tracks depending on how many frames i analyze where i only got the 206 before with the Linear Motion LAP Tracker.
So in my opinion there is a issue with the Linear Motion LAP Algorithm, that you got a limit of tracks somehow.

Does anybody have a solution or any experience using the Linear Motion LAP Tracker for a high amount of tracks? Or is there another preferable Tracker Algorithm for straight, constant movements?

Thank you!

1 Like

Hi @bar_ger

Now this is a strange bug.
Could you share the data with me?

Bonjour @tinevez ! :slightly_smiling_face:

Thank you for answering. Of course i can share the data:

  • Here is a video of the spatters: Substack (1-6000).zip (17.1 MB)

  • And here is the important part of the jython code for analyzing the video in imageJ with TrackMate.

imp = WindowManager.getCurrentImage()
imp.show()

dims = imp.getDimensions() # default order: XYCZT : (width, height, channels, slices, frames)
if (dims[4] == 1): # Swap Z and T dimensions if T=1S
imp.setDimensions( dims[2],dims[4],dims[3] )

#-------------------------

Instantiate model object

#-------------------------

model = Model()

Set logger

model.setLogger(Logger.IJ_LOGGER)

#------------------------

Prepare settings object

#------------------------

settings = Settings()
settings.setFrom(imp)

Configure detector

settings.detectorFactory = LogDetectorFactory()
settings.detectorSettings = {
DetectorKeys.KEY_DO_SUBPIXEL_LOCALIZATION : True,
DetectorKeys.KEY_RADIUS : 6.0,
DetectorKeys.KEY_TARGET_CHANNEL : 1,
DetectorKeys.KEY_THRESHOLD : 0.25,
DetectorKeys.KEY_DO_MEDIAN_FILTERING : False,
}

Add the analyzers for some spot features.

settings.addSpotAnalyzerFactory(SpotIntensityAnalyzerFactory())
settings.addSpotAnalyzerFactory(SpotContrastAndSNRAnalyzerFactory())

settings.initialSpotFilterValue = 0

Configure spot filters

filter1 = FeatureFilter(‘MIN_INTENSITY’, 30.0, False) #Filter for Spots in the melt pool
settings.addSpotFilter(filter1)

Configure tracker

settings.trackerFactory = KalmanTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
settings.trackerSettings[‘KALMAN_SEARCH_RADIUS’] = 15.0
settings.trackerSettings[‘GAP_CLOSING_MAX_FRAME_GAP’] = 3
settings.trackerSettings[‘LINKING_MAX_DISTANCE’] = 15.0
#settings.trackerFactory = SparseLAPTrackerFactory()
#settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
#settings.trackerSettings[‘LINKING_MAX_DISTANCE’] = 15.0
#settings.trackerSettings[‘GAP_CLOSING_MAX_DISTANCE’]= 15.0
#settings.trackerSettings[‘MAX_FRAME_GAP’]= 3

Add an analyzer for some track features, such as the track mean speed

settings.addTrackAnalyzer(TrackSpeedStatisticsAnalyzer())
settings.addTrackAnalyzer(TrackDurationAnalyzer())
settings.addTrackAnalyzer(TrackMeanIntensityAnalyzer())
settings.addSpotAnalyzerFactory( SpotMultiChannelIntensityAnalyzerFactory() )

Configure track filters

#filter2 = FeatureFilter(‘TRACK_DISPLACEMENT’, 50.0, True)
#settings.addTrackFilter(filter2)
#settings.initialSpotFilterValue = 1
filter2 = FeatureFilter(‘TRACK_MEAN_SPEED’, 2.5, True) #filter very slow spatters
settings.addTrackFilter(filter2)

filter3 = FeatureFilter(‘MEAN_TRACK_INTENSITY01’, 150.0, False) #filter tracks in the melt pool
settings.addTrackFilter(filter3)

#----------------------

Instantiate trackmate

#----------------------
trackmate = TrackMate(model, settings)

#------------

Execute all

#------------
ok = trackmate.checkInput()
if not ok:
sys.exit(str(trackmate.getErrorMessage()))

ok = trackmate.process()
if not ok:
sys.exit(str(trackmate.getErrorMessage()))

#----------------

Display results

#----------------

model.getLogger().log(‘Found ’ + str(model.getTrackModel().nTracks(True)) + ’ tracks.’)
selectionModel = SelectionModel(model)
displayer = HyperStackDisplayer(model, selectionModel, imp)
displayer.render()
displayer.refresh()

The feature model, that stores edge and track features.

fm = model.getFeatureModel()

for id in model.getTrackModel().trackIDs(True):

# Fetch the track feature from the feature model.
v = fm.getTrackFeature(id, 'TRACK_MEAN_SPEED')
model.getLogger().log('')
model.getLogger().log('Track ' + str(id) + ': mean velocity = ' + str(v) + ' ' + model.getSpaceUnits() + '/' + model.getTimeUnits())
   
track = model.getTrackModel().trackSpots(id)
for spot in track:
    sid = spot.ID()
    # Fetch spot features directly from spot. 
    x=spot.getFeature('POSITION_X')
    y=spot.getFeature('POSITION_Y')
    t=spot.getFeature('FRAME')
    q=spot.getFeature('QUALITY')
    snr=spot.getFeature('SNR') 
    mean=spot.getFeature('MEAN_INTENSITY')
    model.getLogger().log('\tspot ID = ' + str(sid) + ': x='+str(x)+', y='+str(y)+', t='+str(t)+', q='+str(q) + ', snr='+str(snr) + ', mean = ' + str(mean))

I still have the mentioned issue with the linear motion tracker. Doesn’t matter if i run the script or click through the GUI. It always stops tracking after a certain amount of frames/tracks. With the simple LAP Tracker it works fine!

I can totally reproduce the bug, thanks!

I guess it is linked somehow to the fact that there are no spots at frame 1576 where it stops.

I will investigate.

1 Like

I refined a bit the diagnosis:

It seems that this tracker is unable to initiate new tracks in a frame if there are no living tracks at said frame.
In your movie, this is what happens. At frame 1576 there no living tracks anymore, and the tracker is not able to initiate new ones, so it effectively ends tracking at this frame.
I could reproduce this weird behavior on synthetic data.
Now onward to the code!

BTW I don’t know what you are working on but if it is not cool nothing is cool.

I created an issue about it: https://github.com/fiji/TrackMate/issues/141

Look at this beauty:
@bar_ger I made a quick time movie about the results. It is really beautiful but I cannot upload it to the forum. Can I upload it to youtube and ink it here? Or do you wish not to disclose it too much?

I think I have found and fixed the bug btw.

1 Like

Great! Yes it’s fine if you link it here. I am looking forward to see your movie!

Thanks!

Can you tell me what it is and who / institution should be acknowledged on YouTube?

It’s a research during my Master Thesis at the University of Stuttgart and the process is in the field of welding. The aim is to gain knowledge about the spatters. Especially their amount, the behavior and their origin. :slightly_smiling_face:

Et voilà

3 Likes

haha in two weeks you won’t see such nice fireworks!

1 Like

True!

I have found the source of the bug and fixed it (hopefully, I always say that and then comes ironic life lessons).
The fix is here: https://github.com/fiji/TrackMate/commit/756e45c9a4a94c069e2c4acc261daa9f8dc97723

It looks small, and it is indeed. But this issue was entangled with others, that were treated separately first.

There should be a new TrackMate release this Friday, probably 5.1.0 that will ship the fix.

Thanks for reporting and helping!

Thank you, too. For helping and implementing this great tool!

1 Like

^^V
Can I make a tweet with the movie?
WHO should I acknowledge?

Sure! I don’t have an twitter account, so Thomas from the University of Stuttgart is fine!