Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create LAP tracker based on IoU instead of distance #277

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions src/main/java/fiji/plugin/trackmate/TrackMateRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,24 @@ public class TrackMateRunner extends TrackMatePlugIn
*/
private static final String ARG_MAX_DISTANCE = "max_distance";

/**
* The macro parameter to set what is the minimal frame-to-frame linking
* IoU. Accept double values.
*/
private static final String ARG_MIN_IOU = "min_iou";

/**
* The macro parameter to set what is the maximal gap-closing distance.
* Accept double values in physical units.
*/
private static final String ARG_MAX_GAP_DISTANCE = "max_gap_distance";

/**
* The macro parameter to set what is the minimal gap-closing IoU.
* Accept double values.
*/
private static final String ARG_MIN_GAP_IOU = "min_gap_iou";

/**
* The macro parameter to set what is the maximal acceptable frame gap when
* doing gap closing. Accept integer values.
Expand Down Expand Up @@ -184,7 +196,9 @@ public class TrackMateRunner extends TrackMatePlugIn
SUPPORTED_ARGS.add( ARG_INPUT_IMAGE_NAME );
SUPPORTED_ARGS.add( ARG_INPUT_IMAGE_PATH );
SUPPORTED_ARGS.add( ARG_MAX_DISTANCE );
SUPPORTED_ARGS.add( ARG_MIN_IOU );
SUPPORTED_ARGS.add( ARG_MAX_GAP_DISTANCE );
SUPPORTED_ARGS.add( ARG_MIN_GAP_IOU );
SUPPORTED_ARGS.add( ARG_MAX_GAP_FRAMES );
SUPPORTED_ARGS.add( ARG_MEDIAN );
SUPPORTED_ARGS.add( ARG_SAVE_TO );
Expand Down Expand Up @@ -594,11 +608,21 @@ private Map< String, ValuePair< String, MacroArgumentConverter > > prepareTracke
new ValuePair< >( TrackerKeys.KEY_LINKING_MAX_DISTANCE, doubleConverter );
parsers.put( ARG_MAX_DISTANCE, maxDistancePair );

// Min linking IoU.
final ValuePair< String, MacroArgumentConverter > minIouPair =
new ValuePair< >( TrackerKeys.KEY_LINKING_MIN_IOU, doubleConverter );
parsers.put( ARG_MIN_IOU, minIouPair );

// Max gap distance.
final ValuePair< String, MacroArgumentConverter > maxGapDistancePair =
new ValuePair< >( TrackerKeys.KEY_GAP_CLOSING_MAX_DISTANCE, doubleConverter );
parsers.put( ARG_MAX_GAP_DISTANCE, maxGapDistancePair );

// Min gap IoU.
final ValuePair< String, MacroArgumentConverter > minGapIoUPair =
new ValuePair< >( TrackerKeys.KEY_GAP_CLOSING_MIN_IOU, doubleConverter );
parsers.put( ARG_MIN_GAP_IOU, minGapIoUPair );

// Target channel.
final ValuePair< String, MacroArgumentConverter > maxGapFramesPair =
new ValuePair< >( TrackerKeys.KEY_GAP_CLOSING_MAX_FRAME_GAP, integerConverter );
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*-
* #%L
* TrackMate: your buddy for everyday tracking.
* %%
* Copyright (C) 2010 - 2023 TrackMate developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
package fiji.plugin.trackmate.gui.components.tracker;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Collection;
import java.util.Map;

import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import fiji.plugin.trackmate.gui.components.ConfigurationPanel;

public class LAPOverlapTrackerSettingsPanel extends ConfigurationPanel
{

private static final long serialVersionUID = 1L;

private JPanelLAPOverlapTrackerSettingsMain jPanelMain;

private final String trackerName;

private final String spaceUnits;

private final Collection< String > features;

private final Map< String, String > featureNames;

/*
* CONSTRUCTOR
*/

public LAPOverlapTrackerSettingsPanel( final String trackerName, final String spaceUnits, final Collection< String > features, final Map< String, String > featureNames )
{
this.trackerName = trackerName;
this.spaceUnits = spaceUnits;
this.features = features;
this.featureNames = featureNames;
initGUI();
}

/*
* PUBLIC METHODS
*/

@Override
public Map< String, Object > getSettings()
{
return jPanelMain.getSettings();
}

@Override
public void setSettings( final Map< String, Object > settings )
{
jPanelMain.echoSettings( settings );
}

/*
* PRIVATE METHODS
*/

private void initGUI()
{
try
{
final BorderLayout thisLayout = new BorderLayout();
setPreferredSize( new Dimension( 300, 500 ) );
this.setLayout( thisLayout );
{
final JScrollPane jScrollPaneMain = new JScrollPane();
this.add( jScrollPaneMain, BorderLayout.CENTER );
jScrollPaneMain.setVerticalScrollBarPolicy( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
jScrollPaneMain.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
jScrollPaneMain.getVerticalScrollBar().setUnitIncrement( 24 );
{
jPanelMain = new JPanelLAPOverlapTrackerSettingsMain( trackerName, spaceUnits, features, featureNames );
jScrollPaneMain.setViewportView( jPanelMain );
}
}
}
catch ( final Exception e )
{
e.printStackTrace();
}
}

@Override
public void clean()
{}

}
47 changes: 47 additions & 0 deletions src/main/java/fiji/plugin/trackmate/tracking/TrackerKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,51 @@ public class TrackerKeys

/** A default value for the {@value #KEY_BLOCKING_VALUE} parameter. */
public static final double DEFAULT_BLOCKING_VALUE = Double.POSITIVE_INFINITY;

/**
* Key for the parameter specifying the minimum linking IoU. The
* expected value must be a Double.
*/
public static final String KEY_LINKING_MIN_IOU = "LINKING_MIN_IOU";

/** A default value for the {@value #KEY_LINKING_MIN_IOU} parameter. */
public static final double DEFAULT_LINKING_MIN_IOU = 0.0;

/**
* Key for the parameter specifying the min gap-closing IoU. Expected
* values are {@link Double}s. If two spots, candidate for a gap-closing
* event, are found separated by a IoU smaller than this parameter value,
* gap-closing will not occur.
*/
public static final String KEY_GAP_CLOSING_MIN_IOU = "GAP_CLOSING_MIN_IOU";

/**
* A default value for the {@value #KEY_GAP_CLOSING_MIN_IOU} parameter.
*/
public static final double DEFAULT_GAP_CLOSING_MIN_IOU = 0.0;

/**
* Key for the parameter specifying the min merging IoU. Expected
* values are {@link Double}s. If two spots, candidate for a merging
* event, are found separated by an IoU smaller than this parameter
* value, track merging will not occur.
*/
public static final String KEY_MERGING_MIN_IOU = "MERGING_MIN_IOU";

/** A default value for the {@value #KEY_MERGING_MIN_IOU} parameter. */
public static final double DEFAULT_MERGING_MIN_IOU = 0.0;

/**
* Key for the parameter specifying the min splitting IoU. Expected
* values are {@link Double}s. If two spots, candidate for a merging event,
* are found separated by an IoU smaller than this parameter value,
* track splitting will not occur.
*/
public static final String KEY_SPLITTING_MIN_IOU = "SPLITTING_MIN_IOU";

/**
* A default value for the {@link #KEY_SPLITTING_MIN_IOU} parameter.
*/
public static final double DEFAULT_SPLITTING_MIN_IOU = 0.0;

}
18 changes: 18 additions & 0 deletions src/main/java/fiji/plugin/trackmate/tracking/jaqaman/LAPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_CUTOFF_PERCENTILE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_GAP_CLOSING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_GAP_CLOSING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_GAP_CLOSING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_GAP_CLOSING_MAX_FRAME_GAP;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_MERGING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_MERGING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_MERGING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_SPLITTING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_SPLITTING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.DEFAULT_SPLITTING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_ALLOW_GAP_CLOSING;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_ALLOW_TRACK_MERGING;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_ALLOW_TRACK_SPLITTING;
Expand All @@ -42,13 +45,17 @@
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_CUTOFF_PERCENTILE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_GAP_CLOSING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_GAP_CLOSING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_GAP_CLOSING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_GAP_CLOSING_MAX_FRAME_GAP;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_LINKING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_LINKING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_LINKING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_MERGING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_MERGING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_MERGING_MIN_IOU;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_SPLITTING_FEATURE_PENALTIES;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_SPLITTING_MAX_DISTANCE;
import static fiji.plugin.trackmate.tracking.TrackerKeys.KEY_SPLITTING_MIN_IOU;
import static fiji.plugin.trackmate.util.TMUtils.checkMapKeys;
import static fiji.plugin.trackmate.util.TMUtils.checkParameter;

Expand Down Expand Up @@ -148,14 +155,17 @@ public static final Map< String, Object > getDefaultSegmentSettingsMap()
settings.put( KEY_ALLOW_GAP_CLOSING, DEFAULT_ALLOW_GAP_CLOSING );
settings.put( KEY_GAP_CLOSING_MAX_FRAME_GAP, DEFAULT_GAP_CLOSING_MAX_FRAME_GAP );
settings.put( KEY_GAP_CLOSING_MAX_DISTANCE, DEFAULT_GAP_CLOSING_MAX_DISTANCE );
settings.put( KEY_GAP_CLOSING_MIN_IOU, DEFAULT_GAP_CLOSING_MIN_IOU );
settings.put( KEY_GAP_CLOSING_FEATURE_PENALTIES, new HashMap<>( DEFAULT_GAP_CLOSING_FEATURE_PENALTIES ) );
// Track splitting
settings.put( KEY_ALLOW_TRACK_SPLITTING, DEFAULT_ALLOW_TRACK_SPLITTING );
settings.put( KEY_SPLITTING_MAX_DISTANCE, DEFAULT_SPLITTING_MAX_DISTANCE );
settings.put( KEY_SPLITTING_MIN_IOU, DEFAULT_SPLITTING_MIN_IOU );
settings.put( KEY_SPLITTING_FEATURE_PENALTIES, new HashMap<>( DEFAULT_SPLITTING_FEATURE_PENALTIES ) );
// Track merging
settings.put( KEY_ALLOW_TRACK_MERGING, DEFAULT_ALLOW_TRACK_MERGING );
settings.put( KEY_MERGING_MAX_DISTANCE, DEFAULT_MERGING_MAX_DISTANCE );
settings.put( KEY_MERGING_MIN_IOU, DEFAULT_MERGING_MIN_IOU );
settings.put( KEY_MERGING_FEATURE_PENALTIES, new HashMap<>( DEFAULT_MERGING_FEATURE_PENALTIES ) );
// Others
settings.put( KEY_BLOCKING_VALUE, DEFAULT_BLOCKING_VALUE );
Expand Down Expand Up @@ -257,20 +267,24 @@ public static final boolean checkSettingsValidity( final Map< String, Object > s
if (linking)
{
ok = ok & checkParameter( settings, KEY_LINKING_MAX_DISTANCE, Double.class, errorHolder );
ok = ok & checkParameter( settings, KEY_LINKING_MIN_IOU, Double.class, errorHolder );
ok = ok & checkFeatureMap( settings, KEY_LINKING_FEATURE_PENALTIES, errorHolder );
}
// Gap-closing
ok = ok & checkParameter( settings, KEY_ALLOW_GAP_CLOSING, Boolean.class, errorHolder );
ok = ok & checkParameter( settings, KEY_GAP_CLOSING_MAX_DISTANCE, Double.class, errorHolder );
ok = ok & checkParameter( settings, KEY_GAP_CLOSING_MIN_IOU, Double.class, errorHolder );
ok = ok & checkParameter( settings, KEY_GAP_CLOSING_MAX_FRAME_GAP, Integer.class, errorHolder );
ok = ok & checkFeatureMap( settings, KEY_GAP_CLOSING_FEATURE_PENALTIES, errorHolder );
// Splitting
ok = ok & checkParameter( settings, KEY_ALLOW_TRACK_SPLITTING, Boolean.class, errorHolder );
ok = ok & checkParameter( settings, KEY_SPLITTING_MAX_DISTANCE, Double.class, errorHolder );
ok = ok & checkParameter( settings, KEY_SPLITTING_MIN_IOU, Double.class, errorHolder );
ok = ok & checkFeatureMap( settings, KEY_SPLITTING_FEATURE_PENALTIES, errorHolder );
// Merging
ok = ok & checkParameter( settings, KEY_ALLOW_TRACK_MERGING, Boolean.class, errorHolder );
ok = ok & checkParameter( settings, KEY_MERGING_MAX_DISTANCE, Double.class, errorHolder );
ok = ok & checkParameter( settings, KEY_MERGING_MIN_IOU, Double.class, errorHolder );
ok = ok & checkFeatureMap( settings, KEY_MERGING_FEATURE_PENALTIES, errorHolder );
// Others
ok = ok & checkParameter( settings, KEY_CUTOFF_PERCENTILE, Double.class, errorHolder );
Expand All @@ -282,14 +296,18 @@ public static final boolean checkSettingsValidity( final Map< String, Object > s
if ( linking )
{
mandatoryKeys.add( KEY_LINKING_MAX_DISTANCE );
mandatoryKeys.add( KEY_LINKING_MIN_IOU );
}
mandatoryKeys.add( KEY_ALLOW_GAP_CLOSING );
mandatoryKeys.add( KEY_GAP_CLOSING_MAX_DISTANCE );
mandatoryKeys.add( KEY_GAP_CLOSING_MIN_IOU );
mandatoryKeys.add( KEY_GAP_CLOSING_MAX_FRAME_GAP );
mandatoryKeys.add( KEY_ALLOW_TRACK_SPLITTING );
mandatoryKeys.add( KEY_SPLITTING_MAX_DISTANCE );
mandatoryKeys.add( KEY_SPLITTING_MIN_IOU );
mandatoryKeys.add( KEY_ALLOW_TRACK_MERGING );
mandatoryKeys.add( KEY_MERGING_MAX_DISTANCE );
mandatoryKeys.add( KEY_MERGING_MIN_IOU );
mandatoryKeys.add( KEY_ALTERNATIVE_LINKING_COST_FACTOR );
mandatoryKeys.add( KEY_CUTOFF_PERCENTILE );
mandatoryKeys.add( KEY_BLOCKING_VALUE );
Expand Down
Loading