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.
- Author:
- Pete Bankhead
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum for common stain defaults. -
Field Summary
-
Constructor Summary
ConstructorDescriptionDefault 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.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).getStains
(boolean includeResidual) Get a collection of all the stains.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
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
-
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 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
-
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:
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-