Package boofcv.alg.disparity.sgm.cost
Class StereoMutualInformation
java.lang.Object
boofcv.alg.disparity.sgm.cost.StereoMutualInformation
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.- Specify the maximum number of gray values using
randomHistogram(java.util.Random, int)
- 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 - Call
process(boofcv.struct.image.GrayU8, boofcv.struct.image.GrayU8, int, boofcv.struct.image.GrayU8, int)
to compute the mutual information scores - Then call
precomputeScaledCost(int)
to compute the scaled cost in a look up table - 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configureHistogram
(int totalGrayLevels) Configures the histogram and how the input is scaled.void
configureSmoothing
(int radius) Amount of smooth that's applied to the kernelsfloat
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
getEps()
void
precomputeScaledCost
(int maxCost) Precompute cost scaled to have a range of 0 to maxCost, inclusivevoid
Process the images and compute the entropy terms which will be in turn used to compute mutual informationvoid
randomHistogram
(Random rand, int maxCost) Computes random values for the cost between left and right values.void
setEps
(float eps)
-
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
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 imagemaxCost
- 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
Process the images and compute the entropy terms which will be in turn used to compute mutual information- Parameters:
left
- Left rectified imageright
- Right rectified imageminDisparity
- The minimum allowed disparitydisparity
- Disparity from left to rightinvalid
- 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 callprocess(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)
-