Class Histogram

java.lang.Object
qupath.lib.analysis.stats.Histogram

public class Histogram extends Object
Class for storing histogram data & basic statistics.

TODO: Document int check - if all values are integers, the bin size cannot be < 1.

Author:
Pete Bankhead
  • Constructor Summary

    Constructors
    Constructor
    Description
    Histogram(double[] values, int nBins)
    Create histogram from a double array, using a specified number of bins and the data min/max as the min/max edges.
    Histogram(double[] valuesArray, int nBins, double minEdge, double maxEdge)
    Create a histogram from an array of values, optionally specifying the minimum & maximum values to include.
    Histogram(float[] values, int nBins)
    Create histogram from a float array, using a specified number of bins and the data min/max as the min/max edges.
    Histogram(float[] valuesArray, int nBins, double minEdge, double maxEdge)
    Create a histogram from an array of values, optionally specifying the minimum & maximum values to include.
    Histogram(int[] valuesArray, int nBins, double minEdge, double maxEdge)
    Create a histogram from an array of values, optionally specifying the minimum & maximum values to include.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    getBinIndexForValue(double value, double binWidth)
    Get the index of the bin that should contain the specified value.
    double
    getBinLeftEdge(int ind)
    Get the lower edge for a specified bin.
    double
    getBinRightEdge(int ind)
    Get the upper edge for a specified bin.
    double
    getBinWidth(int ind)
    Get the width of a bin, which is the difference between its upper and lower edges.
    long
    getCountsForBin(int ind)
    Get the histogram counts for the specified bin.
    long
    Sum of all histogram counts.
    double
    Get the maximum edge of the histogram.
    double
    Get the minimum edge of the histogram.
    double
    Get the histogram edge range, defined as the maximum edge - the minimum edge.
    long
    Get the highest count found for any bin.
    double
    Get the highest count found for any bin, divided by the total counts across the entire histogram.
    double
    Get the maximum of all the values being histogrammed.
    double
    Get the mean of all the values being histogrammed.
    static double[]
    getMeasurementValues(Collection<PathObject> pathObjects, String measurementName)
    Extract a specific measurement for each PathObject in a collection, storing the result in an array.
    double
    Get the minimum of all the values being histogrammed.
    double
    Get the normalized histogram count for the specified bin.
    double
    Get the standard deviation of all the values being histogrammed.
    double
    Get the sum of all the values being histogrammed.
    double
    Get the variance of all the values being histogrammed.
    boolean
    Check if the histogram has been generated from integer values only.
    static Histogram
    makeMeasurementHistogram(Collection<PathObject> pathObjects, String measurementName, int nBins)
    Create a histogram depicting values of a specific measurement extracted from a collection of PathObjects.
    int
    Total number of histogram bins.
    long
    Number of NaNs in the input array.
    long
    Number of values represented in the histogram (i.e.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Histogram

      public Histogram(double[] valuesArray, int nBins, double minEdge, double maxEdge)
      Create a histogram from an array of values, optionally specifying the minimum & maximum values to include. NaNs will be ignored from the histogram.
      Parameters:
      valuesArray - the data values from which the histogram should be computed
      nBins - number of histogram bins (will be number of edges - 1)
      minEdge - the minimum (edge) value to include in the histogram, or Double.NaN (to use the data minimum)
      maxEdge - the maximum (edge) value to include in the histogram, or Double.NaN (to use the data maximum)
    • Histogram

      public Histogram(float[] valuesArray, int nBins, double minEdge, double maxEdge)
      Create a histogram from an array of values, optionally specifying the minimum & maximum values to include. NaNs will be ignored from the histogram.
      Parameters:
      valuesArray - the data values from which the histogram should be computed
      nBins - number of histogram bins (will be number of edges - 1)
      minEdge - the minimum (edge) value to include in the histogram, or Double.NaN (to use the data minimum)
      maxEdge - the maximum (edge) value to include in the histogram, or Double.NaN (to use the data maximum)
    • Histogram

      public Histogram(int[] valuesArray, int nBins, double minEdge, double maxEdge)
      Create a histogram from an array of values, optionally specifying the minimum & maximum values to include. NaNs will be ignored from the histogram.
      Parameters:
      valuesArray - The data values from which the histogram should be computed
      nBins - Number of histogram bins (will be number of edges - 1)
      minEdge - The minimum (edge) value to include in the histogram, or Double.NaN (to use the data minimum)
      maxEdge - The maximum (edge) value to include in the histogram, or Double.NaN (to use the data maximum)
    • Histogram

      public Histogram(double[] values, int nBins)
      Create histogram from a double array, using a specified number of bins and the data min/max as the min/max edges.
      Parameters:
      values -
      nBins -
    • Histogram

      public Histogram(float[] values, int nBins)
      Create histogram from a float array, using a specified number of bins and the data min/max as the min/max edges.
      Parameters:
      values -
      nBins -
  • Method Details

    • getEdgeMin

      public double getEdgeMin()
      Get the minimum edge of the histogram.
      Returns:
    • getEdgeMax

      public double getEdgeMax()
      Get the maximum edge of the histogram.
      Returns:
    • getEdgeRange

      public double getEdgeRange()
      Get the histogram edge range, defined as the maximum edge - the minimum edge.
      Returns:
    • getBinLeftEdge

      public double getBinLeftEdge(int ind)
      Get the lower edge for a specified bin.
      Parameters:
      ind - index of the bin
      Returns:
    • getBinRightEdge

      public double getBinRightEdge(int ind)
      Get the upper edge for a specified bin.
      Parameters:
      ind - index of the bin
      Returns:
    • getBinWidth

      public double getBinWidth(int ind)
      Get the width of a bin, which is the difference between its upper and lower edges.
      Parameters:
      ind - index of the bin
      Returns:
    • getCountsForBin

      public long getCountsForBin(int ind)
      Get the histogram counts for the specified bin.
      Parameters:
      ind - index of the bin
      Returns:
    • getNormalizedCountsForBin

      public double getNormalizedCountsForBin(int ind)
      Get the normalized histogram count for the specified bin.

      This is the count for the bin divided by the sum of all counts.

      Parameters:
      ind -
      Returns:
    • isInteger

      public boolean isInteger()
      Check if the histogram has been generated from integer values only.
      Returns:
    • getMinValue

      public double getMinValue()
      Get the minimum of all the values being histogrammed.
      Returns:
    • getMaxValue

      public double getMaxValue()
      Get the maximum of all the values being histogrammed.
      Returns:
    • getMeanValue

      public double getMeanValue()
      Get the mean of all the values being histogrammed.
      Returns:
    • getVariance

      public double getVariance()
      Get the variance of all the values being histogrammed.
      Returns:
    • getStdDev

      public double getStdDev()
      Get the standard deviation of all the values being histogrammed.
      Returns:
    • getSum

      public double getSum()
      Get the sum of all the values being histogrammed.
      Returns:
    • nValues

      public long nValues()
      Number of values represented in the histogram (i.e. the length of the input array).
      Returns:
    • nMissingValues

      public long nMissingValues()
      Number of NaNs in the input array.
      Returns:
    • getBinIndexForValue

      public int getBinIndexForValue(double value, double binWidth)
      Get the index of the bin that should contain the specified value.

      This assumes that all bins have the same width (binWidth).

      Parameters:
      value -
      binWidth -
      Returns:
      bin index
      See Also:
      • getBinIndexForValue(double)
    • getMaxCount

      public long getMaxCount()
      Get the highest count found for any bin.
      Returns:
      getMaxNormalizedCount()
    • getMaxNormalizedCount

      public double getMaxNormalizedCount()
      Get the highest count found for any bin, divided by the total counts across the entire histogram.
      Returns:
      getMaxCount()
    • nBins

      public int nBins()
      Total number of histogram bins.
      Returns:
    • getCountSum

      public long getCountSum()
      Sum of all histogram counts.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getMeasurementValues

      public static double[] getMeasurementValues(Collection<PathObject> pathObjects, String measurementName)
      Extract a specific measurement for each PathObject in a collection, storing the result in an array.

      The order of entries in the array will depend upon the iteration order of the collection (usually a list).

      Parameters:
      pathObjects -
      measurementName -
      Returns:
      See Also:
    • makeMeasurementHistogram

      public static Histogram makeMeasurementHistogram(Collection<PathObject> pathObjects, String measurementName, int nBins)
      Create a histogram depicting values of a specific measurement extracted from a collection of PathObjects.
      Parameters:
      pathObjects -
      measurementName -
      nBins -
      Returns:
      See Also: