Class HistogramUtils

java.lang.Object
imagingbook.common.histogram.HistogramUtils

public abstract class HistogramUtils extends Object

This class defines static methods related to histograms. See Ch. 2 of [1] for additional details.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

Version:
2022/08/24
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    cdf(int[] h)
    Calculates and returns the cumulative distribution function (cdf) for the given histogram.
    static int
    count(int[] h)
    Calculates and returns the total population (sum of all bin counts) of a histogram.
    static int
    count(int[] h, int lo, int hi)
    Calculates and returns the population (sum of bin counts) of a histogram over the specified range of indexes.
    static int[]
    cumulate(int[] h)
    Calculates and returns the cumulative histogram from a given histogram.
    static int[]
    matchHistograms(int[] hA, int[] hR)
    Histogram matching.
    static int[]
    Histogram matching to a reference cumulative distribution function that is piecewise linear.
    static double
    max(double[] h)
    Returns the maximum bin value (count) of the given frequency distribution (histogram).
    static int
    max(int[] h)
    Returns the maximum bin value (count) of the given histogram.
    static double
    mean(int[] h)
    Calculates and returns the intensity mean (average) of the distribution represented by the given histogram.
    static double
    mean(int[] h, int lo, int hi)
    Calculates and returns the intensity mean (average) of the distribution represented by the given histogram, limited to the specified intensity range.
    static int
    median(int[] h)
    Calculates and returns the intensity median of the distribution represented by the given histogram.
    static double[]
    normalizeMax(double[] h)
    Returns a normalized frequency distribution for the given histogram whose maximum entry is 1 (double version).
    static double[]
    normalizeMax(int[] h)
    Returns a normalized frequency distribution for the given histogram whose maximum entry is 1 (int version).
    static double[]
    pdf(int[] h)
    Calculates and returns the probability distribution function (pdf) for the given histogram.
    static double
    variance(int[] h)
    Calculates and returns the intensity variance (σ2) of the distribution represented by the given histogram.
    static double
    variance(int[] h, int lo, int hi)
    Calculates and returns the intensity variance (σ2) of the distribution represented by the given histogram, limited to the specified intensity range (fast version).
    static double
    varianceSlow(int[] h, int lo, int hi)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • count

      public static int count(int[] h)
      Calculates and returns the total population (sum of all bin counts) of a histogram.
      Parameters:
      h - a histogram
      Returns:
      the histogram's total count
    • count

      public static int count(int[] h, int lo, int hi)
      Calculates and returns the population (sum of bin counts) of a histogram over the specified range of indexes. The range is automatically clipped.
      Parameters:
      h - a histogram
      lo - the lower index (inclusive)
      hi - the upper index (inclusive)
      Returns:
      the population count
    • max

      public static int max(int[] h)
      Returns the maximum bin value (count) of the given histogram.
      Parameters:
      h - a histogram
      Returns:
      the maximum bin value
    • max

      public static double max(double[] h)
      Returns the maximum bin value (count) of the given frequency distribution (histogram).
      Parameters:
      h - a histogram
      Returns:
      the maximum bin value
    • cumulate

      public static int[] cumulate(int[] h)
      Calculates and returns the cumulative histogram from a given histogram.
      Parameters:
      h - a histogram
      Returns:
      the cumulative histogram
    • pdf

      public static double[] pdf(int[] h)
      Calculates and returns the probability distribution function (pdf) for the given histogram. The resulting double array has the same length as the original histogram. Its values sum to 1.
      Parameters:
      h - a histogram
      Returns:
      the probability distribution function
    • cdf

      public static double[] cdf(int[] h)
      Calculates and returns the cumulative distribution function (cdf) for the given histogram. The resulting double array has the same length as the original histogram. Its maximum value is 1.
      Parameters:
      h - a histogram
      Returns:
      the cumulative distribution function
    • mean

      public static double mean(int[] h)
      Calculates and returns the intensity mean (average) of the distribution represented by the given histogram.
      Parameters:
      h - a histogram
      Returns:
      the mean intensity
    • mean

      public static double mean(int[] h, int lo, int hi)
      Calculates and returns the intensity mean (average) of the distribution represented by the given histogram, limited to the specified intensity range. The range is automatically clipped.
      Parameters:
      h - a histogram
      lo - the lower index (inclusive)
      hi - the upper index (inclusive)
      Returns:
      the mean intensity
    • variance

      public static double variance(int[] h)
      Calculates and returns the intensity variance (σ2) of the distribution represented by the given histogram.
      Parameters:
      h - a histogram
      Returns:
      the intensity variance
    • variance

      public static double variance(int[] h, int lo, int hi)
      Calculates and returns the intensity variance (σ2) of the distribution represented by the given histogram, limited to the specified intensity range (fast version). The range is automatically clipped.
      Parameters:
      h - a histogram
      lo - the lower index (inclusive)
      hi - the upper index (inclusive)
      Returns:
      the intensity variance
    • varianceSlow

      public static double varianceSlow(int[] h, int lo, int hi)
    • median

      public static int median(int[] h)
      Calculates and returns the intensity median of the distribution represented by the given histogram.
      Parameters:
      h - a histogram
      Returns:
      the intensity median
    • normalizeMax

      public static double[] normalizeMax(int[] h)
      Returns a normalized frequency distribution for the given histogram whose maximum entry is 1 (int version). Mainly intended for displaying histograms.
      Parameters:
      h - a histogram
      Returns:
      the max-normalized frequency distribution
    • normalizeMax

      public static double[] normalizeMax(double[] h)
      Returns a normalized frequency distribution for the given histogram whose maximum entry is 1 (double version). Mainly intended for displaying histograms.
      Parameters:
      h - a histogram
      Returns:
      the max-normalized frequency distribution
    • matchHistograms

      public static int[] matchHistograms(int[] hA, int[] hR)
      Histogram matching. Given are two histograms: the histogram hA of the target image IA and a reference histogram hR, both of size K. The result is a discrete mapping f which, when applied to the target image, produces a new image with a distribution function similar to the reference histogram.
      Parameters:
      hA - histogram of the target image
      hR - reference histogram (the same size as hA)
      Returns:
      a discrete mapping f to be applied to the values of a target image
    • matchHistograms

      public static int[] matchHistograms(int[] hA, PiecewiseLinearCdf PR)
      Histogram matching to a reference cumulative distribution function that is piecewise linear.
      Parameters:
      hA - histogram of the target image
      PR - a piecewise linear reference cumulative distribution function (PiecewiseLinearCdf)
      Returns:
      a discrete mapping f to be applied to the values of a target image
      See Also: