Class EstimateStainVectors

java.lang.Object
qupath.lib.analysis.algorithms.EstimateStainVectors

public class EstimateStainVectors extends Object
Code for estimating stain vectors automatically from an image, or to launch an editor for visually/interactively modifying stain vectors.

Aspects of the automated method take inspiration from Macenko's 2009 paper 'A METHOD FOR NORMALIZING HISTOLOGY SLIDES FOR QUANTITATIVE ANALYSIS' although it also differs through its use of preprocessing and parameters, as well as its selection of an actual pixel value rather than projecting on the identified plane.

Author:
Pete Bankhead
  • Constructor Details

    • EstimateStainVectors

      public EstimateStainVectors()
  • Method Details

    • estimateStains

      public static ColorDeconvolutionStains estimateStains(BufferedImage img, ColorDeconvolutionStains stainsOriginal, boolean checkColors)
      Estimate two stains from a BufferedImage, with default parameter settings.
      Parameters:
      img - original RGB image
      stainsOriginal - original stains, including the background (white) values for red, green and blue and stain names
      checkColors - if true, avoid colors far from H&E
      Returns:
    • estimateStains

      public static ColorDeconvolutionStains estimateStains(BufferedImage img, ColorDeconvolutionStains stainsOriginal, double minStain, double maxStain, double ignorePercentage, boolean checkColors)
      Estimate two stains from a BufferedImage.
      Parameters:
      img - original RGB image
      stainsOriginal - original stains, including the background (white) values for red, green and blue and stain names
      minStain - minimum optical density to use
      maxStain - maximum optical density to use
      ignorePercentage - percentage of extrema pixels to ignore
      checkColors - if true, avoid colors far from H&E
      Returns:
    • estimateStains

      public static ColorDeconvolutionStains estimateStains(int[] rgbPacked, float[] redOD, float[] greenOD, float[] blueOD, ColorDeconvolutionStains stainsOriginal, double minStain, double maxStain, double ignorePercentage, boolean checkColors)
      Check colors only currently applies to H&E.
      Parameters:
      rgbPacked -
      redOD -
      greenOD -
      blueOD -
      stainsOriginal -
      minStain -
      maxStain -
      ignorePercentage -
      checkColors -
      Returns:
    • subsample

      public static int[] subsample(int[] arr, int maxEntries)
      Subsample an array so that it contains no more than maxEntries. No guarantee is made that the resulting array will contain *exactly* maxEntries, but rather equal spacing between entries will be used.

      If arr.length <= maxEntries, the array is returned unchanged.

      Parameters:
      arr -
      maxEntries -
      Returns:
    • smoothImage

      public static BufferedImage smoothImage(BufferedImage img)
      Smooth out compression artefacts by running 3x3 filter twice (roughly approximates a small Gaussian filter).
      Parameters:
      img -
      Returns:
    • getModeRGB

      public static int[] getModeRGB(int[] rgb)
      Get the mode from an array of (packed) RGB pixel values.
      Parameters:
      rgb -
      Returns:
      an array with 3 entries giving the Red, Green & Blue values (in order) corresponding to the mode of each channel from the packed RGB pixel array.