Package qupath.lib.color
Class ColorModelFactory
java.lang.Object
qupath.lib.color.ColorModelFactory
Factory methods to help create ColorModels for use with BufferedImages.
- Author:
- Pete Bankhead
-
Method Summary
Modifier and TypeMethodDescriptionstatic ColorModelcreateColorModel(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.static ColorModelcreateColorModel(PixelType type, List<ImageChannel> channels) Create a ColorModel for displaying an image with the specified channel colors.static ColorModelcreateColorModel(PixelType pixelType, ColorMaps.ColorMap map, int band) Create a color model from aColorMaps.ColorMap.static ColorModelcreateColorModel(PixelType pixelType, ColorMaps.ColorMap map, int band, double min, double max, int alphaChannel, DoubleToIntFunction alphaFun) Create a color model from aColorMaps.ColorMap, scaled within a defined range and with an optional additional alpha channel used to determine opacity.static DoubleToIntFunctioncreateGammaFunction(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.static DoubleToIntFunctioncreateGammaFunction(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.static ColorModelcreateIndexedColorModel(Map<Integer, Integer> labelColors, boolean includeAlpha) Create an indexed colormap for a labelled (indexed color) image.static IndexColorModelCreate an 8-bitIndexColorModelfrom aColorMaps.ColorMap.static IndexColorModelcreateIndexedColorModel8bit(ColorMaps.ColorMap map, int transparentPixel) Create an 8-bitIndexColorModelfrom aColorMaps.ColorMap, allowing for a transparent pixel to be set (e.g.static DoubleToIntFunctioncreateLinearFunction(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.static DoubleToIntFunctionCreate 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.static ColorModelgetDummyColorModel(int bpp) Get a dummy ColorModel instance.static IndexColorModelgetIndexedClassificationColorModel(Map<Integer, PathClass> channels) Get a ColorModel suitable for showing output pixel classifications, using an 8-bit or 16-bit labeled image.static ColorModelgetProbabilityColorModel32Bit(List<ImageChannel> channels) Get a ColorModel suitable for showing 32-bit (pseudo-)probabilities for multiple channels.static ColorModelgetProbabilityColorModel8Bit(List<ImageChannel> channels) Get a ColorModel suitable for showing 8-bit pseudo-probabilities for multiple channels.
-
Method Details
-
getIndexedClassificationColorModel
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
Create an 8-bitIndexColorModelfrom aColorMaps.ColorMap.- Parameters:
map-- Returns:
-
createIndexedColorModel8bit
public static IndexColorModel createIndexedColorModel8bit(ColorMaps.ColorMap map, int transparentPixel) Create an 8-bitIndexColorModelfrom aColorMaps.ColorMap, allowing for a transparent pixel to be set (e.g. 0).- Parameters:
map-transparentPixel-- Returns:
-
createColorModel
Create a color model from aColorMaps.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 aColorMaps.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
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
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
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
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
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
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
Get a dummy ColorModel instance.This isn't very highly recommended; it is here to help in cases where a
BufferedImageis 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,
alphaResidualcan be used to make 'unknown' pixels transparent/translucent rather than black.- Parameters:
type- type for individual pixelsnChannels- 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 toBACKGROUND_COLOR, which indicates that it is used directly to control the alpha values, overridingalphaResidual.- Returns:
-
createColorModel
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:
-