Class ColorDeconvolutionStains

java.lang.Object
qupath.lib.color.ColorDeconvolutionStains
All Implemented Interfaces:
Externalizable, Serializable

public class ColorDeconvolutionStains extends Object implements Externalizable
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:
  • Field Details

  • 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 channel
      maxGreen - background (white) value for green channel
      maxBlue - 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 channel
      maxGreen - background (white) value for green channel
      maxBlue - 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

      public static boolean isHematoxylin(StainVector stain)
      Check if the name of a StainVector is "haematoxylin", "hematoxylin", "haem" or "h" (ignoring case)
      Parameters:
      stain -
      Returns:
    • isEosin

      public static boolean isEosin(StainVector stain)
      Check if the name of a StainVector is "eosin", "eos" or "e" (ignoring case)
      Parameters:
      stain -
      Returns:
    • isDAB

      public static boolean isDAB(StainVector stain)
      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

      public ColorDeconvolutionStains changeStain(StainVector stainNew, int stainNumber)
      Create a new stains object, identical to this one but for one StainVector having been changed.
      Parameters:
      stainNew -
      stainNumber -
      Returns:
    • changeName

      public ColorDeconvolutionStains changeName(String name)
      Create a new stains object with the same StainVectors but a new name.
      Parameters:
      name -
      Returns:
    • changeMaxValues

      public ColorDeconvolutionStains changeMaxValues(double maxRed, double maxGreen, double maxBlue)
      Create a new stains object with the same StainVectors but new max (background) values.
      Parameters:
      maxRed -
      maxGreen -
      maxBlue -
      Returns:
    • getStain

      public StainVector 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).

      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

      public Collection<StainVector> getStains(boolean includeResidual)
      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

      public String getName()
      Get the stains name.
      Returns:
    • getStainNumber

      public int getStainNumber(StainVector stain)
      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

      public String toString()
      Overrides:
      toString in class Object
    • 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

      public static ColorDeconvolutionStains parseColorDeconvolutionStainsArg(String s)
      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

      public static double[] parseStainValues(Locale locale, String s)
      Parses 3 values, suitable for use as a stain vector
      Parameters:
      locale -
      s -
      Returns:
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException