Class SNTColor

java.lang.Object
sc.fiji.snt.util.SNTColor

public class SNTColor extends Object
A simple class for handling Colors including the ability to map an AWT Color to a SWC type integer tag.
Author:
Tiago Ferreira
  • Field Details

  • Constructor Details

    • SNTColor

      public SNTColor(Color color, int swcType)
      Instantiates a new SNT color.
      Parameters:
      color - the AWT color
      swcType - the SWC type integer flag to be associated with color
    • SNTColor

      public SNTColor(Color color)
      Instantiates a new SNT color without SWC type association
      Parameters:
      color - the AWT color
  • Method Details

    • color

      public Color color()
      Retrieves the AWT color
      Returns:
      the AWT color
    • type

      public int type()
      Retrieves the SWC type
      Returns:
      the SWC type integer flag
    • isTypeDefined

      public boolean isTypeDefined()
      Checks if an SWC type has been defined.
      Returns:
      true, if an SWC integer flag has been specified
    • setAWTColor

      public void setAWTColor(Color color)
      Re-assigns an AWT color.
      Parameters:
      color - the new color
    • setSWCType

      public void setSWCType(int swcType)
      Re-assigns a SWC type integer flag
      Parameters:
      swcType - the new SWC type
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • colorToString

      public static String colorToString(Object color)
      Returns the color encoded as hex string with the format #rrggbbaa.
      Parameters:
      color - the input AWT color
      Returns:
      the converted string
    • fromString

      public static Color fromString(String colorName)
      Returns an AWT Color from any css-valid co
      Parameters:
      colorName - the input string
      Returns:
      the converted AWT color
    • fromHex

      public static Color fromHex(String hex)
      Returns an AWT Color from a (#)RRGGBB(AA) hex string.
      Parameters:
      hex - the input string
      Returns:
      the converted AWT color
    • average

      public static Color average(Collection<Color> colors)
      Averages a collection of colors
      Parameters:
      colors - the colors to be averaged
      Returns:
      the averaged color. Note that an average will never be accurate because the RGB space is not linear. Color.BLACK is returned if all colors in input collection are null;
    • mix

      public static Color mix(Color c1, Color c2, double weight)
      Linearly mixes two colors together based on a specified weight, using a gamma-corrected linear blend by squaring the individual color channels before mixing
      Parameters:
      c1 - the starting color (used completely when weight is 0.0)
      c2 - the target color (used completely when weight is 1.0)
      weight - the blend factor between 0.0 and 1.0; represents the proportion of c2 to include in the final mixture
      Returns:
      a new Color object representing the combined result
      Throws:
      NullPointerException - if c1 or c2 is null
    • interpolateNullEntries

      public static void interpolateNullEntries(Color[] colors)
      Replaces null colors in an array with the average of flanking non-null colors.
      Parameters:
      colors - the color array
    • alphaColor

      public static Color alphaColor(Color c, double percent)
      Adds an alpha component to an AWT color.
      Parameters:
      c - the input color
      percent - alpha value in percentage
      Returns:
      the color with an alpha component
    • contrastColor

      public static Color contrastColor(Color c)
      Returns a BW 'contrast' color
      Parameters:
      c - the input color
      Returns:
      Either white or black, as per hue of input color.
    • oppositeColor

      public static Color oppositeColor(Color c)
      Returns a suitable 'opposite' color.
      Parameters:
      c - the input color
      Returns:
      The opposite color
    • contrastHueColor

      public static Color contrastHueColor(Color c)
      Returns a 'contrasting' color using warm/cool contrast adjustments.
      Parameters:
      c - the input color
      Returns:
      The contrasting color
    • contrastHueColor

      public static Color contrastHueColor(Color c, Color reference)
      Returns a 'contrasting' color using warm/cool contrast adjustments relatively to a second color reference.
      Parameters:
      c - the input color
      reference - the reference color
      Returns:
      The contrasting color
    • okabeIto6Colors

      public static List<Color> okabeIto6Colors()
      Returns the 6-color Okabe-Ito colorblind-safe palette
      Returns:
      the 6 Okabe-Ito colors
    • okabeIto4Colors

      public static List<Color> okabeIto4Colors()
      Returns a 4-color subset of the Okabe-Ito colorblind-safe palette
      Returns:
      the 4 Okabe-Ito colors
    • colorBlindSafeBlue

      public static Color colorBlindSafeBlue()
      Returns the blue of the Okabe-Ito palette, safe against the most common forms of color blindness
      Returns:
      the colorblind-safe blue
    • colorBlindSafeYellow

      public static Color colorBlindSafeYellow()
      Returns the yellow of the Okabe-Ito palette, safe against the most common forms of color blindness
      Returns:
      the colorblind-safe yellow
    • getDistinctColors

      public static org.scijava.util.ColorRGB[] getDistinctColors(int nColors)
      Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded). More details on this SO discussion
      Parameters:
      nColors - the number of colors to be retrieved.
      Returns:
      the maximum contrast colors
    • getDistinctColors

      public static org.scijava.util.ColorRGB[] getDistinctColors(int nColors, String excludedHue)
      Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded). More details on this SO discussion
      Parameters:
      nColors - the number of colors to be retrieved
      excludedHue - an optional string defining a hue to be excluded. Either 'red', 'green', 'blue', or 'dim'
      Returns:
      the maximum contrast colors
    • getDistinctColorsColorblindSafe

      public static org.scijava.util.ColorRGB[] getDistinctColorsColorblindSafe(int nColors)
      Returns distinct colors from the Okabe-Ito colorblind-safe palette, cycling through its 6 hues once nColors exceeds that count
      Parameters:
      nColors - the number of colors to be retrieved
      Returns:
      the colorblind-safe colors
    • getDistinctColorsColorblindSafeAWT

      public static Color[] getDistinctColorsColorblindSafeAWT(int nColors)
      Parameters:
      nColors - the number of colors to be retrieved
      Returns:
      the colorblind-safe colors, as AWT colors
    • valueOf

      public static org.scijava.util.ColorRGB valueOf(String colorSpec)
      Parses a color from the given string.

      The following formats are supported: Hex format [HTML color codes starting with hash (#)], Color presets (e.g., 'blue', 'pink', 'silver', etc.), and integer triples of the form r,g,b, with each element in the range [0, 255].

      Parameters:
      colorSpec - string defining the color value
      Returns:
      the color
    • getDistinctColorsHex

      public static String[] getDistinctColorsHex(int nColors, String excludedHue)
      Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values. More details on this SO discussion
      Parameters:
      nColors - the number of colors to be retrieved
      excludedHue - an optional string defining a hue to be excluded. Either 'red', 'green', 'blue', or 'dim'
      Returns:
      the maximum contrast colors as hex color strings
    • getDistinctColorsHex

      public static String[] getDistinctColorsHex(int nColors)
      Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values. More details on this SO discussion
      Parameters:
      nColors - the number of colors to be retrieved
      Returns:
      the maximum contrast colors as hex color strings
    • getDistinctColorsAWT

      public static Color[] getDistinctColorsAWT(int nColors)