Any pixel-wise matching cost measure is generally ambiguous. Therefore, constraints such as the assumption of
a smooth surface need to be introduced and globally aggregated along with the cost. The Sobel-based cost c is
computed for all potential matches in a stereo pair, i.e., for each base image pixel p and for all disparities d that
provide the link to pair image locations. This results in cost vectors for each pixel and, in a cost cuboid for the entire
image. The energy function E(D) that has to be globally minimized consists of this cost and constraints on
smoothness. Hirschmüller (2005, 2008) proposes to use the penalties P1 for slight variations of one disparity and P2
for any larger changes, i.e. discontinuities, in-between neighboring pixels: