Class ColorMapper

java.lang.Object
sc.fiji.snt.analysis.ColorMapper
Direct Known Subclasses:
AnnotationMapper, GraphColorMapper, NodeColorMapper, TreeColorMapper

public class ColorMapper extends Object
Parent class for ColorMappers.
Author:
Tiago Ferreira
  • Field Details

    • lutService

      protected net.imagej.lut.LUTService lutService
    • luts

      protected Map<String,URL> luts
    • colorTable

      protected net.imglib2.display.ColorTable colorTable
    • integerScale

      protected boolean integerScale
    • min

      protected double min
    • max

      protected double max
  • Constructor Details

    • ColorMapper

      public ColorMapper()
  • Method Details

    • map

      public void map(String measurement, net.imglib2.display.ColorTable colorTable)
      Sets up the color mapping for the specified measurement using the given color table.

      This method configures the ColorMapper to use the specified measurement and color table for mapping values to colors. The actual mapping implementation is left to extending classes.

      Parameters:
      measurement - the measurement to be mapped
      colorTable - the color table to use for mapping
      Throws:
      IllegalArgumentException - if colorTable or measurement is null
    • getNaNColor

      public Color getNaNColor()
      Gets the color used for NaN (Not a Number) values.

      Returns the color that will be used when mapping NaN values, which cannot be mapped to the regular color scale.

      Returns:
      the color for NaN values
    • setNaNColor

      public void setNaNColor(Color nanColor)
      Sets the color to use for NaN (Not a Number) values.

      Specifies the color that should be used when mapping NaN values, which cannot be mapped to the regular color scale.

      Parameters:
      nanColor - the color to use for NaN values
    • getColor

      public Color getColor(double mappedValue)
      Gets the color corresponding to the specified mapped value.

      Maps the given value to a color using the current color table and mapping bounds. Returns the NaN color if the value is NaN.

      Parameters:
      mappedValue - the value to map to a color
      Returns:
      the corresponding color
    • getColorRGB

      public org.scijava.util.ColorRGB getColorRGB(double mappedValue)
      Gets the color corresponding to the specified mapped value as ColorRGB.
      Parameters:
      mappedValue - the value to map to a color
      Returns:
      the corresponding ColorRGB
      See Also:
    • setMinMax

      public void setMinMax(double min, double max)
      Sets the LUT mapping bounds.
      Parameters:
      min - the mapping lower bound (i.e., the highest measurement value for the LUT scale). It is automatically calculated (the default) when set to Double.NaN
      max - the mapping upper bound (i.e., the highest measurement value for the LUT scale).It is automatically calculated (the default) when set to Double.NaN.
    • setMinMaxPercentileClipped

      public void setMinMaxPercentileClipped(double[] values, double clipPercent)
      Sets the LUT mapping bounds to a percentile-clipped range of values, curbing the influence of long-tailed outliers on the color scale. Plain min-max bounds let a single extreme value (e.g. one path length far outside the rest of the arbor) stretch the whole range, crushing every other mapped value into a narrow, near-indistinguishable band. This clips both ends to a percentile window instead: values beyond it still render as the coldest/hottest color (clamped, not discarded -- see getColor(double)) but no longer decide where that window sits. Same convention as sc.fiji.snt.seed.SeedConfidence#percentileClipNormalize(double[], double), used throughout SNT's seed detectors for the identical long-tail problem.
      Parameters:
      values - the raw values driving this mapping (e.g., a metric read across every mapped node/path). NaN entries are ignored; null or all-NaN leaves the current bounds unchanged.
      clipPercent - percentile clip width, clamped to [0, 45] (0 recovers plain min-max)
    • setMinPercentileClipped

      public void setMinPercentileClipped(double[] values, double clipPercent)
      One-sided companion to setMinMaxPercentileClipped(double[], double): sets only the lower bound, to the clipPercentth percentile of values, leaving the upper bound untouched. Useful when only one end of the scale should adapt to the data -- e.g. pairing this with a fixed, caller-chosen upper bound (or setMaxPercentileClipped(double[], double) for the other combination). Unlike setMinMax(double, double), this does not validate against the current upper bound, since that bound may not have been set yet -- callers combining both ends should finish with a plain setMinMax(double, double) (or getMinMax()-checked call) once both are known.
      Parameters:
      values - as setMinMaxPercentileClipped(double[], double)
      clipPercent - percentile clip width, clamped to [0, 45] (0 = the plain minimum)
    • setMaxPercentileClipped

      public void setMaxPercentileClipped(double[] values, double clipPercent)
      One-sided companion to setMinMaxPercentileClipped(double[], double): sets only the upper bound, to the (100-clipPercent)th percentile of values, leaving the lower bound untouched. See setMinPercentileClipped(double[], double) for the other combination and the caveat about validating the final range once both bounds are known.
      Parameters:
      values - as setMinMaxPercentileClipped(double[], double)
      clipPercent - percentile clip width, clamped to [0, 45] (0 = the plain maximum)
    • isIntegerScale

      public boolean isIntegerScale()
      Checks if the color mapping uses an integer scale.

      Returns true if the mapping is configured to use discrete integer values rather than continuous floating-point values.

      Returns:
      true if using integer scale, false for continuous scale
    • getMinMax

      public double[] getMinMax()
      Returns the mapping bounds
      Returns:
      a two-element array with current {minimum, maximum} mapping bounds
    • getColorTable

      public net.imglib2.display.ColorTable getColorTable()
      Gets the current color table used for mapping.

      Returns the ColorTable instance that defines the color mapping from values to colors.

      Returns:
      the current color table
    • initLuts

      protected void initLuts()
    • getAvailableLuts

      public Set<String> getAvailableLuts()
      Gets the available LUTs, as recognized by getColorTable(String): every LUT bundled with Fiji (via LUTService), in addition to the handful of "core" names ColorMaps.get(String) resolves directly (e.g. "viridis", "fire", "ice") without needing the LUTService lookup.
      Returns:
      the set of keys, corresponding to the set of LUTs available
    • getAvailableHeatmapLuts

      public Set<String> getAvailableHeatmapLuts()
      Gets the subset of getAvailableLuts() recognized as heatmap LUTs, matched case-insensitively and loosely against a curated list of known heatmap names. Absent LUTs are simply not returned, since availability depends on the running Fiji install
      Returns:
      the heatmap subset of getAvailableLuts()
    • getColorTable

      public net.imglib2.display.ColorTable getColorTable(String lut)
      Resolves a LUT (color table) by name. Tries the small set of "core" names known to ColorMaps.get(String) first (e.g. "viridis", "fire", "ice" -- no LUTService round-trip needed), then falls back to a substring match against every LUT bundled with Fiji, as reported by getAvailableLuts().
      Parameters:
      lut - the LUT name, or a substring of one of getAvailableLuts()'s entries (e.g. "mpl-viridis.lut")
      Returns:
      the matching color table, or null if no match was found
    • unMap

      public static void unMap(Tree tree)
      Removes color mapping from all paths in the specified tree.

      Resets the color of all paths in the tree to their default state, effectively removing any color mapping that was previously applied.

      Parameters:
      tree - the tree whose paths should have color mapping removed
    • unMap

      public static void unMap(Collection<Path> paths)
      Removes color mapping from the specified collection of paths.

      Resets the color of all paths in the collection to their default state, effectively removing any color mapping that was previously applied. This includes both path-level and node-level color assignments.

      Parameters:
      paths - the collection of paths to have color mapping removed