Class ColorModelFactory

java.lang.Object
qupath.lib.color.ColorModelFactory

public final class ColorModelFactory extends Object
Factory methods to help create ColorModels for use with BufferedImages.
Author:
Pete Bankhead
  • Method Details

    • getIndexedClassificationColorModel

      public static IndexColorModel getIndexedClassificationColorModel(Map<Integer,PathClass> channels)
      Get a ColorModel suitable for showing output pixel classifications, using an 8-bit or 16-bit labeled image.
      Parameters:
      channels -
      Returns:
    • createIndexedColorModel

      public static ColorModel createIndexedColorModel(Map<Integer,Integer> labelColors, boolean includeAlpha)
      Create an indexed colormap for a labelled (indexed color) image.
      Parameters:
      labelColors - map with integer labels as keys and packed (A)RGB colors as values.
      includeAlpha - if true, allow alpha values to be included in the colormap
      Returns:
    • createIndexedColorModel8bit

      public static IndexColorModel createIndexedColorModel8bit(ColorMaps.ColorMap map)
      Create an 8-bit IndexColorModel from a ColorMaps.ColorMap.
      Parameters:
      map -
      Returns:
    • createIndexedColorModel8bit

      public static IndexColorModel createIndexedColorModel8bit(ColorMaps.ColorMap map, int transparentPixel)
      Create an 8-bit IndexColorModel from a ColorMaps.ColorMap, allowing for a transparent pixel to be set (e.g. 0).
      Parameters:
      map -
      transparentPixel -
      Returns:
    • createColorModel

      public static ColorModel createColorModel(PixelType pixelType, ColorMaps.ColorMap map, int band)
      Create a color model from a ColorMaps.ColorMap. This is useful for heatmaps/density maps where lower values should be transparent.
      Parameters:
      pixelType -
      map -
      band -
      Returns:
    • createColorModel

      public static ColorModel createColorModel(PixelType pixelType, ColorMaps.ColorMap map, int band, double min, double max, int alphaChannel, DoubleToIntFunction alphaFun)
      Create a color model from a ColorMaps.ColorMap, scaled within a defined range and with an optional additional alpha channel used to determine opacity. This is useful for heatmaps/density maps where lower values should be transparent.
      Parameters:
      pixelType -
      map -
      band - the band of the image that defines the values used to index the color map (usually 0 for a single-channel image)
      min -
      max -
      alphaChannel -
      alphaFun -
      Returns:
    • createLinearFunction

      public static DoubleToIntFunction createLinearFunction(PixelType type)
      Create a linear function for a specific pixel type, which can be used to determine a suitable alpha value for an image that should have opacity based upon pixel values.
      Parameters:
      type -
      Returns:
      See Also:
    • createLinearFunction

      public static DoubleToIntFunction createLinearFunction(double min, double max)
      Create a linear function between a given range, which can be used to determine a suitable alpha value for an image that should have opacity based upon pixel values.
      Parameters:
      min -
      max -
      Returns:
      See Also:
    • createGammaFunction

      public static DoubleToIntFunction createGammaFunction(double gamma, PixelType type)
      Create a gamma function for a specific pixel type, which can be used to determine a suitable alpha value for an image that should have opacity based upon pixel values.
      Parameters:
      gamma -
      type -
      Returns:
      See Also:
    • createGammaFunction

      public static DoubleToIntFunction createGammaFunction(double gamma, double min, double max)
      Create a gamma function between a given range, which can be used to determine a suitable alpha value for an image that should have opacity based upon pixel values.
      Parameters:
      gamma -
      min -
      max -
      Returns:
      See Also:
    • getProbabilityColorModel8Bit

      public static ColorModel getProbabilityColorModel8Bit(List<ImageChannel> channels)
      Get a ColorModel suitable for showing 8-bit pseudo-probabilities for multiple channels.

      The range of values is assumed to be 0-255, treated as probabilities rescaled from 0-1. A cached model will be retrieved where possible, rather than generating a new one.

      Parameters:
      channels -
      Returns:
    • getProbabilityColorModel32Bit

      public static ColorModel getProbabilityColorModel32Bit(List<ImageChannel> channels)
      Get a ColorModel suitable for showing 32-bit (pseudo-)probabilities for multiple channels.

      The range of values is assumed to be 0-1. A cached model will be retrieved where possible, rather than generating a new one.

      Parameters:
      channels -
      Returns:
    • getDummyColorModel

      public static ColorModel getDummyColorModel(int bpp)
      Get a dummy ColorModel instance.

      This isn't very highly recommended; it is here to help in cases where a BufferedImage is required, but really only a raster is needed. The actual color used is undefined (but it will likely be black).

      Parameters:
      bpp -
      Returns:
    • createColorModel

      public static ColorModel createColorModel(PixelType type, int nChannels, boolean alphaResidual, int... colors)
      Create a new ColorModel that can be used to display an image where pixels per channel reflect probabilities, either as float or byte.

      It is assumed that the probabilities sum to 1; if they sum to less than 1, alphaResidual can be used to make 'unknown' pixels transparent/translucent rather than black.

      Parameters:
      type - type for individual pixels
      nChannels - Number of color channels.
      alphaResidual - If true, the alpha value is scaled according to the sum of the other probabilities. This makes pixels with low probabilities for all other channels appear transparent.
      colors - Packed RGB representations of each color, in order. A single channel can also be set to BACKGROUND_COLOR, which indicates that it is used directly to control the alpha values, overriding alphaResidual.
      Returns:
    • createColorModel

      public static ColorModel createColorModel(PixelType type, List<ImageChannel> channels)
      Create a ColorModel for displaying an image with the specified channel colors. Note that this currently does not provide any means to change the display range (e.g. for brightness/contrast) and therefore may not be sufficient on its own for generating a satisfactory (A)RGB image.
      Parameters:
      type -
      channels -
      Returns: