Class StereoMutualInformation

java.lang.Object
boofcv.alg.disparity.sgm.cost.StereoMutualInformation

public class StereoMutualInformation extends Object

Computes the Mutual Information error metric from a rectified stereo pair. Mutual information between two images is defined as: MI(I1,I2) = HI1 + HI2 + HI1,I2. Where H is an entropy function, e.g. HI = -sum_i PI(i)log(PI(i)), where PI(i) is the probability of a pixel in image 'I' having that intensity. See [1] for details.

The following steps need to be followed to use this class.
  1. Specify the maximum number of gray values using randomHistogram(java.util.Random, int)
  2. Initialize the histogram. If the disparity is known that can be used. Otherwise it's recommended that diagonalHistogram(double, int) is used instead. Random initialization was suggested in the paper but that has been found to only work on simple scenes
  3. Call process(boofcv.struct.image.GrayU8, boofcv.struct.image.GrayU8, int, boofcv.struct.image.GrayU8, int) to compute the mutual information scores
  4. Then call precomputeScaledCost(int) to compute the scaled cost in a look up table
  5. To get the cost use costScaled(int, int)

It was noted in later works that MI does not scale well to gray scales images greater than 8-bits, such as the common 12-bit ones used today. This is because the distribution of values becomes too sparse.

[1] Hirschmuller, Heiko. "Stereo processing by semiglobal matching and mutual information." IEEE Transactions on pattern analysis and machine intelligence 30.2 (2007): 328-341.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    configureHistogram(int totalGrayLevels)
    Configures the histogram and how the input is scaled.
    void
    configureSmoothing(int radius)
    Amount of smooth that's applied to the kernels
    float
    cost(int leftValue, int rightValue)
    Computes the mutual information cost given pixel values from left and right images.
    int
    costScaled(int leftValue, int rightValue)
     
    void
    diagonalHistogram(double scaleLeftToRight, int maxCost)
    Creates a diagonal histogram.
    float
     
    void
    precomputeScaledCost(int maxCost)
    Precompute cost scaled to have a range of 0 to maxCost, inclusive
    void
    process(GrayU8 left, GrayU8 right, int minDisparity, GrayU8 disparity, int invalid)
    Process the images and compute the entropy terms which will be in turn used to compute mutual information
    void
    randomHistogram(Random rand, int maxCost)
    Computes random values for the cost between left and right values.
    void
    setEps(float eps)
     

    Methods inherited from class java.lang.Object

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

    • StereoMutualInformation

      public StereoMutualInformation()
  • Method Details

    • configureHistogram

      public void configureHistogram(int totalGrayLevels)
      Configures the histogram and how the input is scaled. For an 8-bit input image just pass in 0xFF for both values.
      Parameters:
      totalGrayLevels - Number of possible gray scale values. Typically 256 for 8-bit images.
    • randomHistogram

      public void randomHistogram(Random rand, int maxCost)
      Computes random values for the cost between left and right values. Not recommended since it only seems to work with simplistic images
      Parameters:
      rand - Random number generator
    • diagonalHistogram

      public void diagonalHistogram(double scaleLeftToRight, int maxCost)
      Creates a diagonal histogram. This assumes that the pixel values are within a scale factor of each other in the left and right images. You can specify the scale factor. Most of the time 1.0 works just fine Non diagonal elements are given a higher score.
      Parameters:
      scaleLeftToRight - Ratio of pixel intensity values from left to right image
      maxCost - The worst cost.
    • configureSmoothing

      public void configureSmoothing(int radius)
      Amount of smooth that's applied to the kernels
      Parameters:
      radius - A radius of 3 is recommended in the paper
    • process

      public void process(GrayU8 left, GrayU8 right, int minDisparity, GrayU8 disparity, int invalid)
      Process the images and compute the entropy terms which will be in turn used to compute mutual information
      Parameters:
      left - Left rectified image
      right - Right rectified image
      minDisparity - The minimum allowed disparity
      disparity - Disparity from left to right
      invalid - Value of disparity pixels which are invalid
    • cost

      public float cost(int leftValue, int rightValue)
      Computes the mutual information cost given pixel values from left and right images. Must call process(boofcv.struct.image.GrayU8, boofcv.struct.image.GrayU8, int, boofcv.struct.image.GrayU8, int) first.
      Parameters:
      leftValue - Value in left image. I(x,y)
      rightValue - Value of pixel in right image I(x-d,y)
      Returns:
      the mutual information score
    • costScaled

      public int costScaled(int leftValue, int rightValue)
    • precomputeScaledCost

      public void precomputeScaledCost(int maxCost)
      Precompute cost scaled to have a range of 0 to maxCost, inclusive
    • getEps

      public float getEps()
    • setEps

      public void setEps(float eps)