E(D) is the energy for disparity image, D
p, q represent indices for pixels in the image
Np is the neighborhood of the pixel p
C(p, Dp) is the cost of pixel matching with disparity in Dp
P1 is the penalty passed by the user for a change in disparity values of 1 between neighboring pixels
P2 is the penalty passed by the user for a change in disparity values greater than 1 between neighboring pixels
I[.] is the function which returns 1 if the argument is true and 0 otherwise
The minimized function produces a perfect disparity map with smoothing governed by parameters P1 and P2; however, minimizing the function for a 2D image space is an NP-complete problem. The semi-global matching function approximates the 2D minimization by performing multiple 1D, or linear, minimizations. The matching function aggregates costs on multiple paths which converge on the pixel under examination. Cost is computed for the disparity range specified by the minimum disparity and number of disparities parameters. By default, the matching algorithm aggregates costs for 5 directions. You can set the full dynamic programming parameter to true to force the algorithm to aggregate costs for 8 directions.
r is a direction used for converging to the pixel p
Lr(p, d) is the minimum cost of the path taken in direction r from pixel (p for disparity d
IL and IR are left and right rectified images, respectively
The value of C is aggregated over a window of a user-defined size1. After computing S(p, d) for each pixel p for each disparity d, the algorithm chooses the disparity which provides the minimum cost for that pixel.
w equals the width of the rectified image
h equals the height of the rectified image
n equals the number of disparities