Conceptcore
Stereo matching cost
Also called data cost, pixel dissimilarity.
A number that says how badly a left pixel matches a right pixel at a given disparity, such as an absolute difference, a census Hamming distance or mutual information.
A stereo matching cost is a number that says how badly the pixel of the left image matches the pixel of the right image of a rectified pair: small for a good match, large for a bad one. It is the first of the four steps of stereo matching in the taxonomy of Scharstein and Szeliski (2002), and its values for all pixels and disparities fill the cost volume. The choice of cost decides which differences between the two images the method ignores: noise, the position of the pixel grid, a change of gain or offset, or any change that keeps the order of intensities. This page compares the common costs. The census transform page gives one of them as an algorithm with code.
In plain words
To find the match of a pixel, a stereo program tries each possible shift and asks: how different do the two pixels look at this shift? The answer is the matching cost. The simplest answer subtracts the two brightness values. That fails when one camera makes everything a bit brighter, so other costs compare small patches after removing their mean, or after scaling them to the same contrast, or only compare which neighbors are darker. A cost that ignores more differences between the cameras also ignores some real differences between surfaces, so there is no single best cost.
The idea
Setting. and are a rectified pair with the right camera to the right, so the true match of is for the true disparity . A cost is a function . A pixel cost uses only the two pixels; a window cost uses a window around each of them. Window costs already do some aggregation; the line between the two steps is not sharp.
Pixel costs.
- Absolute and squared difference. and . For color, sum over the channels. The squared difference is the negative log likelihood of Gaussian noise, up to constants; the absolute difference is less hurt by single outliers.
- Truncated costs. for a threshold . A wrong pixel, from an occlusion or a highlight, then adds at most to any sum, so it cannot dominate.
- Birchfield and Tomasi (1998). Let be the values half a pixel to each side, and , the least and the largest of , , . Then , the distance of the left value to the range of the right signal near , and the cost is with the roles of the images swapped in the second term. It is zero when the two samples come from the same linear signal sampled at positions up to half a pixel apart, so it does not punish a disparity that is not an integer.
- Gradient costs. Compare the image gradients, for example of the Sobel operator, instead of the intensities. A gradient does not change when a constant is added to the image.
- Mutual information. Hirschmüller (2008) builds the joint histogram of the intensities of matched pixels, from a first disparity map, and sets the cost of a pair of intensities to minus their pointwise mutual information. It handles any fixed mapping of intensities between the cameras, even one that is not monotone, and it is computed per pixel.
Window costs.
- SAD and SSD. The sums of and over the window. Block matching uses them.
- Zero mean costs. ZSAD and ZSSD subtract the mean of each window first. They are unchanged by an offset .
- Normalized cross-correlation. NCC of the two windows, usually with the cost . It is unchanged by an affine change with , on each window.
- Rank and census. Zabih and Woodfill (1994): the rank transform counts the neighbors darker than the center, and the census transform writes one bit for each, compared with the Hamming distance. Both are unchanged by any strictly increasing change of the intensities on each window.
- Learned costs. Zbontar and LeCun (2016) trained a network to say whether two patches match and used its output as the cost, inside a classical pipeline. Most later learned methods build a cost volume of learned features.
What each cost ignores. The invariances are theorems about the formulas:
| cost | unchanged by |
|---|---|
| AD, SD, SAD, SSD | nothing but equal changes of both images |
| Birchfield-Tomasi | a shift of the sampling grid by up to half a pixel, on linear signals |
| gradient | an offset |
| ZSAD, ZSSD | an offset on each window |
| NCC | an affine change , , on each window |
| rank, census | any strictly increasing change, on each window |
| mutual information | any fixed one to one mapping of intensities over the image |
Which cost works best on real images is an empirical question. In the evaluation of Hirschmüller and Scharstein (2009), on images with changes of exposure and light, census was among the most robust costs overall, and the pixelwise costs were poor without a correction of the radiometry.
Examples
An offset and a gain. Take the left window and the right window , which is of the left one, so the two windows show the same surface under different camera settings.
| cost | value | why |
|---|---|---|
| SAD | 75 | |
| SSD | 2075 | |
| ZSAD | 20 | means 20 and 45; against |
| 0 | the windows are affinely related, so NCC | |
| census at the center | 0 | in both windows the left neighbor is darker and the right one is brighter |
Only the last two costs see that this is a perfect match.
Sampling. A left row and a right row show an edge sampled at different positions. At the middle pixels, . For Birchfield-Tomasi, the right values half a pixel to the sides are 50 and 85, so the right range is and the left value 50 is in it: . The other term is , because the left range is . The cost is : the two samples are consistent with one edge seen at a fractional shift.
Truncation. With , a window of nine pixels where eight match with and one is occluded with has the truncated sum instead of 216.
Where it is used
- Every dense stereo method. Block matching, adaptive support weights, semi-global matching, graph cut stereo and plane sweep stereo differ in what they do with the costs, but each starts with one of them. Census is the usual cost of semi-global matching in cars and robots.
- Multi-view stereo. Multi-view stereo and PatchMatch stereo compare a patch of a reference image with several other images, mostly with NCC, because the views differ more in light and exposure than a stereo pair.
- Other matching problems. The same costs appear in template matching, optical flow and image registration, where the search is in two dimensions instead of along a row.
References
- Daniel Scharstein and Richard Szeliski, A taxonomy and evaluation of dense two-frame stereo correspondence algorithms, International Journal of Computer Vision 47(1-3), 2002, 7-42, the part on matching cost computation (absolute and squared differences, truncated costs, sampling-insensitive costs, and normalized and non-parametric measures)
- Stan Birchfield and Carlo Tomasi, A pixel dissimilarity measure that is insensitive to image sampling, IEEE Transactions on Pattern Analysis and Machine Intelligence 20(4), 1998, 401-406, the whole paper (the dissimilarity from the linearly interpolated intensity range of the neighbors)
- Ramin Zabih and John Woodfill, Non-parametric local transforms for computing visual correspondence, Computer Vision, ECCV '94, Lecture Notes in Computer Science 801, Springer, 1994, 151-158, the rank and census transforms as matching costs
- Heiko Hirschmüller and Daniel Scharstein, Evaluation of stereo matching costs on images with radiometric differences, IEEE Transactions on Pattern Analysis and Machine Intelligence 31(9), 2009, the comparison of pixel, window and filter based costs under changes of exposure and light
- Heiko Hirschmüller, Stereo processing by semiglobal matching and mutual information, IEEE Transactions on Pattern Analysis and Machine Intelligence 30(2), 2008, 328-341, the part on the pixelwise cost from mutual information
- Jure Zbontar and Yann LeCun, Stereo matching by training a convolutional neural network to compare image patches, Journal of Machine Learning Research 17, 2016, the learned matching cost and its use inside a classical stereo pipeline
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 12, Depth estimation (the matching costs of dense correspondence)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag RQ2T2Y Edit this page History Report an error Markdown