Package qupath.lib.color
Class ColorDeconvolutionStains
java.lang.Object
qupath.lib.color.ColorDeconvolutionStains
- All Implemented Interfaces:
Externalizable
,Serializable
Helper class for storing stain vectors and maximum channel values to be used for color deconvolution.
The maximum channel values are the RGB values corresponding to pixels that have no staining of any kind (i.e. all light has passed through... the pixel should look close to white). By default, these are 255.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum for common stain defaults. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, for Externalizable.ColorDeconvolutionStains
(String name, StainVector stain1, StainVector stain2, double maxRed, double maxGreen, double maxBlue) Constructor for ColorDeconvolutionStains with two stain vectors.ColorDeconvolutionStains
(String name, StainVector stain1, StainVector stain2, StainVector stain3, double maxRed, double maxGreen, double maxBlue) Constructor for ColorDeconvolutionStains with three stain vectors. -
Method Summary
Modifier and TypeMethodDescriptionchangeMaxValues
(double maxRed, double maxGreen, double maxBlue) Create a new stains object with the same StainVectors but new max (background) values.changeName
(String name) Create a new stains object with the same StainVectors but a new name.changeStain
(StainVector stainNew, int stainNumber) Create a new stains object, identical to this one but for one StainVector having been changed.boolean
Create a map containing information on the stain vectors and maximum RGB values of this object.static String
getColorDeconvolutionStainsAsString
(ColorDeconvolutionStains stains, int nDecimalPlaces) Get a String representation of the stains and background.double[][]
Get matrix inverse, as useful for color deconvolution.double
Get the maximum value for the blue channel (default = 255).double
Get the maximum value for the green channel (default = 255).double
Get the maximum value for the red channel (default = 255).getName()
Get the stains name.getStain
(int n) Get a specified color deconvolution stain vector, where n should be 1, 2 or 3 (because color deconvolution on a 3-channel image can recover [to some extent] up to 3 stains).int
getStainNumber
(StainVector stain) Get the number for a specific stain (1, 2 or 3).Get an unmodifiable list containing the 3 stains.getStains
(boolean includeResidual) Get a collection of all the stains.int
hashCode()
static boolean
isDAB
(StainVector stain) Check if the name of a StainVector is "dab" or "d" (ignoring case)static boolean
isEosin
(StainVector stain) Check if the name of a StainVector is "eosin", "eos" or "e" (ignoring case)boolean
isH_DAB()
Check if we have H-DAB staining, by checking the names of the first two stains and confirming that the third stain is a residual.boolean
isH_E()
Check if we have H&E staining, by checking the names of the first two stains and confirming that the third stain is a residual.static boolean
isHematoxylin
(StainVector stain) Check if the name of a StainVector is "haematoxylin", "hematoxylin", "haem" or "h" (ignoring case)static ColorDeconvolutionStains
makeDefaultColorDeconvolutionStains
(ColorDeconvolutionStains.DefaultColorDeconvolutionStains stains) Create a ColorDeconvolutionStains for a default stain combination, and default max values (255 for all channels).static ColorDeconvolutionStains
Create color deconvolution stains from the provided name and map.static ColorDeconvolutionStains
Parse color deconvolution stains from a JSON String, with keys 'Stain 1', 'Stain 2', (optionally) 'Stain 3' and 'Background'.static double[]
parseStainValues
(Locale locale, String s) Parses 3 values, suitable for use as a stain vectorvoid
toString()
void
-
Field Details
-
BACKGROUND_KEY
- See Also:
-
RESIDUAL_KEY
- See Also:
-
HEMATOXYLIN
Default name (and spelling) for hematoxylin stain- See Also:
-
EOSIN
Default name for eosin stain- See Also:
-
DAB
Default name for DAB stain- See Also:
-
-
Constructor Details
-
ColorDeconvolutionStains
public ColorDeconvolutionStains(String name, StainVector stain1, StainVector stain2, StainVector stain3, double maxRed, double maxGreen, double maxBlue) Constructor for ColorDeconvolutionStains with three stain vectors.- Parameters:
name
-stain1
-stain2
-stain3
-maxRed
- background (white) value for red channelmaxGreen
- background (white) value for green channelmaxBlue
- background (white) value for blue channel
-
ColorDeconvolutionStains
public ColorDeconvolutionStains(String name, StainVector stain1, StainVector stain2, double maxRed, double maxGreen, double maxBlue) Constructor for ColorDeconvolutionStains with two stain vectors.- Parameters:
name
-stain1
-stain2
-maxRed
- background (white) value for red channelmaxGreen
- background (white) value for green channelmaxBlue
- background (white) value for blue channel
-
ColorDeconvolutionStains
public ColorDeconvolutionStains()Default constructor, for Externalizable. Should not be used directly.
-
-
Method Details
-
makeDefaultColorDeconvolutionStains
public static ColorDeconvolutionStains makeDefaultColorDeconvolutionStains(ColorDeconvolutionStains.DefaultColorDeconvolutionStains stains) Create a ColorDeconvolutionStains for a default stain combination, and default max values (255 for all channels).- Parameters:
stains
-- Returns:
-
isHematoxylin
Check if the name of a StainVector is "haematoxylin", "hematoxylin", "haem" or "h" (ignoring case)- Parameters:
stain
-- Returns:
-
isEosin
Check if the name of a StainVector is "eosin", "eos" or "e" (ignoring case)- Parameters:
stain
-- Returns:
-
isDAB
Check if the name of a StainVector is "dab" or "d" (ignoring case)- Parameters:
stain
-- Returns:
-
isH_E
public boolean isH_E()Check if we have H&E staining, by checking the names of the first two stains and confirming that the third stain is a residual. Note the order of the stains must be 1-Hematoxylin, 2-Eosin, 3-residual (missing)- Returns:
-
isH_DAB
public boolean isH_DAB()Check if we have H-DAB staining, by checking the names of the first two stains and confirming that the third stain is a residual. Note the order of the stains must be 1-Hematoxylin, 2-DAB, 3-residual (missing)- Returns:
-
changeStain
Create a new stains object, identical to this one but for one StainVector having been changed.- Parameters:
stainNew
-stainNumber
-- Returns:
-
changeName
Create a new stains object with the same StainVectors but a new name.- Parameters:
name
-- Returns:
-
changeMaxValues
Create a new stains object with the same StainVectors but new max (background) values.- Parameters:
maxRed
-maxGreen
-maxBlue
-- Returns:
-
getStain
Get a specified color deconvolution stain vector, where n should be 1, 2 or 3 (because color deconvolution on a 3-channel image can recover [to some extent] up to 3 stains).If only 2 stains are set (i.e. stain1 and stain2), then a third stain is computed orthogonal to the first two, with the name 'residual'.
- Parameters:
n
-- Returns:
- The requested stain vector, or null if n is out of range or the stain was not set.
-
getStains
Get an unmodifiable list containing the 3 stains. This allows 0-based indexing (whilegetStain(int)
uses 1-based indexing).- Returns:
- a 3-element list of stains
-
getStains
Get a collection of all the stains.- Parameters:
includeResidual
- if true, include residual stains in the list. If false, only include non-residual stains.- Returns:
- a collection of stains.
-
getName
Get the stains name.- Returns:
-
getStainNumber
Get the number for a specific stain (1, 2 or 3).- Parameters:
stain
-- Returns:
-
getMaxRed
public double getMaxRed()Get the maximum value for the red channel (default = 255).- Returns:
-
getMaxGreen
public double getMaxGreen()Get the maximum value for the green channel (default = 255).- Returns:
-
getMaxBlue
public double getMaxBlue()Get the maximum value for the blue channel (default = 255).- Returns:
-
getMatrixInverse
public double[][] getMatrixInverse()Get matrix inverse, as useful for color deconvolution. See static ColorDeconvolution classes for usage.- Returns:
-
toString
-
hashCode
public int hashCode() -
equals
-
getColorDeconvolutionStainsAsString
public static String getColorDeconvolutionStainsAsString(ColorDeconvolutionStains stains, int nDecimalPlaces) Get a String representation of the stains and background.- Parameters:
stains
-nDecimalPlaces
-- Returns:
- See Also:
-
parseColorDeconvolutionStainsArg
Parse color deconvolution stains from a JSON String, with keys 'Stain 1', 'Stain 2', (optionally) 'Stain 3' and 'Background'.- Parameters:
s
-- Returns:
- See Also:
-
parseStainValues
Parses 3 values, suitable for use as a stain vector- Parameters:
locale
-s
-- Returns:
-
parseColorDeconvolutionStains
public static ColorDeconvolutionStains parseColorDeconvolutionStains(String name, Map<String, List<Number>> stains) Create color deconvolution stains from the provided name and map.This is the inverse operation of
getColorDeconvolutionStainsAsMap()
.- Parameters:
name
- the name of the color deconvolution stainsstains
- a map of stain name to stain values. Each stain value must be a list containing at least three elements (otherwise the value is skipped). A stain must be provided with the name defined byBACKGROUND_KEY
. A stain with the name defined byRESIDUAL_KEY
will be set asresidual
, others won't. The order of the map matters: the first entry will be the first stain (unless it's the background), and so on.- Returns:
- color deconvolution stains representing the provided map
- Throws:
IllegalArgumentException
- if the provided stains do not contain a stain with the name defined byBACKGROUND_KEY
and with at least three values, or if the provided stains do not contain at least two non-BACKGROUND_KEY
stains with at least three valuesNullPointerException
- if one of the parameter is null
-
getColorDeconvolutionStainsAsMap
Create a map containing information on the stain vectors and maximum RGB values of this object.This is the inverse operation of
parseColorDeconvolutionStains(String,Map)
(without thename
information).- Returns:
- a map of stain name to stain values. Each stain value is a list of three elements. A stain with the name
defined by
BACKGROUND_KEY
represents the maximum RGB values. The returned map is ordered: the first entry represents the first stain, and so on (theBACKGROUND_KEY
stain will be the last element)
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-