Skip to content

Commit

Permalink
Add an option to color spots and tracks by a random color.
Browse files Browse the repository at this point in the history
The random color for spots simply targets the GlasbeyLut class colors,
using the spot ID as index. This ensures the color does not 'move' when
the user edits it or change what is displayed.

For tracks, it simply reproduces the color for track index.
  • Loading branch information
tinevez committed Oct 6, 2023
1 parent 319d284 commit 619b03b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/main/java/fiji/plugin/trackmate/features/FeatureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import fiji.plugin.trackmate.features.manual.ManualSpotColorAnalyzerFactory;
import fiji.plugin.trackmate.features.spot.SpotAnalyzerFactoryBase;
import fiji.plugin.trackmate.features.track.TrackAnalyzer;
import fiji.plugin.trackmate.features.track.TrackIndexAnalyzer;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings;
import fiji.plugin.trackmate.gui.displaysettings.DisplaySettings.TrackMateObject;
import fiji.plugin.trackmate.visualization.FeatureColorGenerator;
Expand All @@ -51,6 +52,7 @@
import fiji.plugin.trackmate.visualization.PerEdgeFeatureColorGenerator;
import fiji.plugin.trackmate.visualization.PerSpotFeatureColorGenerator;
import fiji.plugin.trackmate.visualization.PerTrackFeatureColorGenerator;
import fiji.plugin.trackmate.visualization.RandomSpotColorGenerator;
import fiji.plugin.trackmate.visualization.SpotColorGenerator;
import fiji.plugin.trackmate.visualization.SpotColorGeneratorPerEdgeFeature;
import fiji.plugin.trackmate.visualization.SpotColorGeneratorPerTrackFeature;
Expand All @@ -65,6 +67,10 @@ public class FeatureUtils

public static final String USE_UNIFORM_COLOR_KEY = "UNIFORM_COLOR";

private static final String USE_RANDOM_COLOR_NAME = "Random color";

public static final String USE_RANDOM_COLOR_KEY = "RANDOM_COLOR";

public static final Map< String, String > collectFeatureKeys( final TrackMateObject target, final Model model, final Settings settings )
{
final Map< String, String > inverseMap = new HashMap<>();
Expand Down Expand Up @@ -131,6 +137,7 @@ public static final Map< String, String > collectFeatureKeys( final TrackMateObj
case DEFAULT:
{
inverseMap.put( USE_UNIFORM_COLOR_NAME, USE_UNIFORM_COLOR_KEY );
inverseMap.put( USE_RANDOM_COLOR_NAME, USE_RANDOM_COLOR_KEY );
break;
}

Expand Down Expand Up @@ -218,7 +225,14 @@ public static final FeatureColorGenerator< Spot > createSpotColorGenerator( fina
switch ( displaySettings.getSpotColorByType() )
{
case DEFAULT:
return new UniformSpotColorGenerator( displaySettings.getSpotUniformColor() );
switch ( displaySettings.getSpotColorByFeature() )
{
case FeatureUtils.USE_RANDOM_COLOR_KEY:
return new RandomSpotColorGenerator();
default:
case FeatureUtils.USE_UNIFORM_COLOR_KEY:
return new UniformSpotColorGenerator( displaySettings.getSpotUniformColor() );
}

case EDGES:

Expand Down Expand Up @@ -267,7 +281,21 @@ public static final FeatureColorGenerator< DefaultWeightedEdge > createTrackColo
switch ( displaySettings.getTrackColorByType() )
{
case DEFAULT:
return new UniformTrackColorGenerator( displaySettings.getTrackUniformColor() );
switch ( displaySettings.getTrackColorByFeature() )
{
case FeatureUtils.USE_RANDOM_COLOR_KEY:
return new PerTrackFeatureColorGenerator(
model,
TrackIndexAnalyzer.TRACK_INDEX,
displaySettings.getMissingValueColor(),
displaySettings.getUndefinedValueColor(),
displaySettings.getColormap(),
displaySettings.getTrackMin(),
displaySettings.getTrackMax() );
default:
case FeatureUtils.USE_UNIFORM_COLOR_KEY:
return new UniformTrackColorGenerator( displaySettings.getTrackUniformColor() );
}

case EDGES:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class FeatureDisplaySelector

private static final List< String > FEATURES_WITHOUT_MIN_MAX = Arrays.asList( new String[] {
FeatureUtils.USE_UNIFORM_COLOR_KEY,
FeatureUtils.USE_RANDOM_COLOR_KEY,
TrackIndexAnalyzer.TRACK_INDEX,
ManualEdgeColorAnalyzer.FEATURE,
ManualSpotColorAnalyzerFactory.FEATURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class GlasbeyLut
{

private static final Color[] colors = new Color[] {
public static final Color[] colors = new Color[] {
new Color( 255, 255, 255 ),
new Color( 20, 20, 255 ),
new Color( 255, 20, 20 ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fiji.plugin.trackmate.visualization;

import java.awt.Color;

import fiji.plugin.trackmate.Spot;

public class RandomSpotColorGenerator implements FeatureColorGenerator< Spot >
{

@Override
public Color color( final Spot spot )
{
final int i = spot.ID() % GlasbeyLut.colors.length;
return GlasbeyLut.colors[ i ];
}
}

0 comments on commit 619b03b

Please sign in to comment.