Package qupath.lib.color
Class ColorDeconvolutionHelper
java.lang.Object
qupath.lib.color.ColorDeconvolutionHelper
Static methods to assist with color deconvolution.
- Author:
- Pete Bankhead
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
convertPixelsToOpticalDensities
(float[] px, double maxValue, boolean use8BitLUT) For originally-8-bit images, optical densities can usually be computed faster by preallocating a LUT with the 0-255 required values.static double[]
estimateWhiteValues
(int[] rgb) Estimate white (background) values for a brightfield image.static StainVector
generateMedianStainVectorFromPixels
(String name, int[] rgb, double redMax, double greenMax, double blueMax) Determine median RGB optical densities for an array of pixels (packed RGB), and combine these into a StainVector with the specified name.static float[]
getBlueOpticalDensities
(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.static float[]
getGreenOpticalDensities
(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.static int
getMedianRGB
(int[] rgb) Determine median of RGB values.static float[]
getRedOpticalDensities
(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.static final double
makeOD
(double val, double max) Convert a single pixel value to an optical density asmax(0, -log10(val/max)
.static final double
makeODByLUT
(float val, double[] OD_LUT) Convert a float pixel to an optical density value using a pre-computed lookup table.static final double
makeODByLUT
(int val, double[] OD_LUT) Convert an int pixel to an optical density value using a pre-computed lookup table.static double[]
makeODLUT
(double maxValue) Create an optical density lookup table with 256 entries, normalizing to the specified background value.static double[]
makeODLUT
(double maxValue, int nValues) Create an optical density lookup table, normalizing to the specified background value.static ColorDeconvolutionStains
refineColorDeconvolutionStains
(int[] rgb, ColorDeconvolutionStains stains, double minStain, double percentageClipped) Attempt to automatically refine color deconvolution stains based upon pixel values.
-
Constructor Details
-
ColorDeconvolutionHelper
public ColorDeconvolutionHelper()
-
-
Method Details
-
makeOD
public static final double makeOD(double val, double max) Convert a single pixel value to an optical density asmax(0, -log10(val/max)
. whereval
is clipped to be >= 1.- Parameters:
val
-max
-- Returns:
-
makeODByLUT
public static final double makeODByLUT(int val, double[] OD_LUT) Convert an int pixel to an optical density value using a pre-computed lookup table. This is likely to be much faster than callingmakeOD(double, double)
.- Parameters:
val
-OD_LUT
-- Returns:
- See Also:
-
makeODByLUT
public static final double makeODByLUT(float val, double[] OD_LUT) Convert a float pixel to an optical density value using a pre-computed lookup table. This is likely to be much faster than callingmakeOD(double, double)
, but involves rounding the float first.- Parameters:
val
-OD_LUT
-- Returns:
- See Also:
-
makeODLUT
public static double[] makeODLUT(double maxValue) Create an optical density lookup table with 256 entries, normalizing to the specified background value.- Parameters:
maxValue
-- Returns:
- See Also:
-
makeODLUT
public static double[] makeODLUT(double maxValue, int nValues) Create an optical density lookup table, normalizing to the specified background value.- Parameters:
maxValue
- background (white value)nValues
- number of values to include in the lookup table- Returns:
-
convertPixelsToOpticalDensities
public static void convertPixelsToOpticalDensities(float[] px, double maxValue, boolean use8BitLUT) For originally-8-bit images, optical densities can usually be computed faster by preallocating a LUT with the 0-255 required values. Otherwise, log values need to be calculated for every pixel (which can be relatively slow).- Parameters:
px
-maxValue
-use8BitLUT
-
-
getRedOpticalDensities
public static float[] getRedOpticalDensities(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.- Parameters:
rgb
-maxValue
-px
- optional array used for output- Returns:
-
getGreenOpticalDensities
public static float[] getGreenOpticalDensities(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.- Parameters:
rgb
-maxValue
-px
- optional array used for output- Returns:
-
getBlueOpticalDensities
public static float[] getBlueOpticalDensities(int[] rgb, double maxValue, float[] px) Convert red channel of packed rgb pixel to optical density values, using a specified maximum value.- Parameters:
rgb
-maxValue
-px
- optional array used for output- Returns:
-
generateMedianStainVectorFromPixels
public static StainVector generateMedianStainVectorFromPixels(String name, int[] rgb, double redMax, double greenMax, double blueMax) Determine median RGB optical densities for an array of pixels (packed RGB), and combine these into a StainVector with the specified name.- Parameters:
name
-rgb
-redMax
-greenMax
-blueMax
-- Returns:
-
getMedianRGB
public static int getMedianRGB(int[] rgb) Determine median of RGB values. The median of each channel is computed separately.- Parameters:
rgb
- array of packed RGB values- Returns:
-
refineColorDeconvolutionStains
public static ColorDeconvolutionStains refineColorDeconvolutionStains(int[] rgb, ColorDeconvolutionStains stains, double minStain, double percentageClipped) Attempt to automatically refine color deconvolution stains based upon pixel values.Warning! This is really only for testing - it has not be very extensively validated.
The method used is based very loosely on that of Macenko et al. (2009), but avoids eigenvalue computations in favor of determining an initial stain inputs. TODO: Improve automatic stain vector refinement.
- Parameters:
rgb
-stains
-minStain
- minimum optical density for each RGB channel (default 0.15)percentageClipped
-- Returns:
-
estimateWhiteValues
public static double[] estimateWhiteValues(int[] rgb) Estimate white (background) values for a brightfield image.The algorithm computes histograms for each RGB channel, and takes the mode of the histogram in the region of the histogram > the mean value for that channel.
- Parameters:
rgb
- an array of packed RGB values- Returns:
- an array containing estimated [red, green and blue] background values
-