Algorithm Search⌘K

Problemcore

Stereo matching

Also called stereo correspondence, dense stereo.

For each pixel of one rectified image, find the disparity of the matching pixel in the other image of a stereo pair.

Stereo matching is the problem of finding, for each pixel of one image of a rectified stereo pair, the disparity of the pixel in the other image that sees the same scene point. After rectification the match lies in the same row, so the search is one dimensional, over a range of DD disparities. The result is a dense disparity map, which depth from disparity turns into depths. The problem is hard because many pixels look alike (textureless areas, repeated patterns), because some pixels have no match at all (occlusions), and because the two cameras see a surface under slightly different light and shape.

In plain words

You have two photos taken side by side, already lined up so that each row of one photo shows the same strip of the scene as the same row of the other. For each pixel of the left photo, find where the same spot of the scene is in the right photo. It is somewhere to the left in the same row, and the distance is the disparity. Comparing single pixels does not work well, because many pixels have the same color. So every method compares small areas, or asks that neighbors have similar disparities, or both. Some pixels see a part of the scene that the other camera cannot see, and they have no correct answer.

Definition

Input. Two rectified images ILI_L and IRI_R of W×HW \times H pixels, with the right camera at the baseline b>0b > 0 along +X+X of the left one, and a disparity range 0≤d<D0 \le d < D (or dmin⁡≤d≤dmax⁡d_{\min} \le d \le d_{\max}). Pixel (u,v)(u, v) is in column uu and row vv.

Output. A disparity map dLd_L that gives each pixel (u,v)(u, v) of the left image a disparity dL(u,v)d_L(u, v), so that (u,v)(u, v) in ILI_L and (u−dL(u,v),v)(u - d_L(u, v), v) in IRI_R see the same scene point. The map can also mark pixels as invalid. Disparities are integers or, after refinement, real numbers.

What counts as correct. The problem is an estimation problem: the true disparity is a property of the scene, and the images do not determine it. Benchmarks compare dLd_L with a ground truth map and count the bad pixels, the pixels with ∣dL−dtrue∣>δ\lvert d_L - d_{\text{true}} \rvert > \delta for a threshold δ\delta such as 1 pixel, in all areas, in textureless areas and near depth edges (Scharstein and Szeliski 2002).

Energy form. Most methods choose dd to make an energy small:

E(d)=∑pC(p,dp)+∑(p,q)∈NV(dp,dq),E(d) = \sum_{p} C(p, d_p) + \sum_{(p, q) \in \mathcal N} V(d_p, d_q),

where C(p,d)C(p, d) is the matching cost of pixel pp at disparity dd, stored in a cost volume, N\mathcal N is the set of neighbor pairs, and VV is a smoothness term such as the Potts term V=λ[dp≠dq]V = \lambda [d_p \ne d_q] or a truncated linear term. Local methods drop the second sum and use an aggregated cost in the first. The energy is a model, not the definition of correct: the minimum of EE is not always the true map.

Variants

  • Sparse matching. Match only distinctive points, as in feature matching. Dense matching, the subject here, gives every pixel a value or marks it invalid.
  • Integer or subpixel. Integer disparities, then subpixel refinement to a fraction of a pixel.
  • With occlusions. Mark each pixel as matched or occluded, often by a left-right consistency check or inside the energy.
  • Unrectified or many views. Search along epipolar lines that are not rows, or use many cameras: plane sweep stereo and multi-view stereo.
  • Motion. Without rectification and with moving objects, the match is a 2D vector: optical flow, and with depth, scene flow.

Examples

One row. Let the right row be IR=(10,50,90,10,10,10)I_R = (10, 50, 90, 10, 10, 10) and the left row its shift by one pixel, IL=(10,10,50,90,10,10)I_L = (10, 10, 50, 90, 10, 10), so the true disparity is 1 everywhere. With the cost ∣IL(u)−IR(u−d)∣|I_L(u) - I_R(u - d)| and 0≤d≤20 \le d \le 2:

  • At u=2u = 2 (IL=50I_L = 50) the costs for d=0,1,2d = 0, 1, 2 are 40,0,4040, 0, 40. The match is clear: d=1d = 1.
  • At u=3u = 3 (IL=90I_L = 90) the costs are 80,0,4080, 0, 40: again d=1d = 1.
  • At u=5u = 5 (IL=10I_L = 10) the costs are 0,0,00, 0, 0, because IRI_R is 1010 at columns 5, 4 and 3. Each disparity fits, and one pixel cannot decide.
  • At u=4u = 4 the costs of the pixel alone are 0,0,800, 0, 80, a tie between d=0d = 0 and d=1d = 1. The window of columns 3 to 5 gives the sums 80,0,12080, 0, 120, because it contains the textured pixel at u=3u = 3, and the tie is gone. At u=5u = 5 the window of columns 4 and 5 still gives 0,0,800, 0, 80: it is too far from the texture.

This is the problem of textureless areas: the answer must come from neighbors, by a larger window, by aggregation or by a smoothness term.

Occlusion. In the left image, the background just left of a near object is hidden from the right camera. Those pixels have no true match, and any method that gives every pixel a disparity is wrong there.

Known algorithms

The taxonomy of Scharstein and Szeliski (2002) splits a stereo method into four steps: matching cost, aggregation, disparity computation or optimization, and refinement. The pages of this area follow it.

method step it is about time model
block matching box aggregation and winner-takes-all Θ(WHD)\Theta(W H D) local
census transform a matching cost robust to light changes Θ(WHD)\Theta(W H D) for the costs local
adaptive support weights aggregation with edge-aware weights O(WHDr2)O(W H D r^2) local
guided filter aggregation (Hosni et al. 2013), see cost aggregation edge-aware aggregation in time independent of rr Θ(WHD)\Theta(W H D) local
scanline dynamic programming exact minimum of EE on each row alone O(WD)O(W D) per row for simple VV global on a row
semi-global matching sums of 1D minimizations along 8 or 16 paths Θ(WHD)\Theta(W H D) per path semi-global
graph cut stereo, alpha expansion approximate minimum of EE on the 2D grid a min cut per move global
belief propagation approximate minimum by messages on the grid O(WHD)O(W H D) per iteration with fast messages global
PatchMatch stereo random search over slanted planes independent of DD local with propagation
AlgorithmTimeSpacePropertiesCode
Adaptive support weightsΘ(W H D r^2) worst · average · bestΘ(W H r^2) extradeterministicnot exactofflineiterative1 language
Block matching stereoΘ(W H D) worst · average · bestΘ(W H) extradeterministicexactofflineiterative1 language
Graph cut stereoO(k D (F + n)) worst · averageO(n) extradeterministicnot exactofflineiterative1 language
PatchMatch stereoΘ(T W H s log D) worst · average · bestΘ(W H) extrarandomizednot exactofflineiterative1 language
Plane sweep stereoΘ(D N W H) worst · average · bestΘ(W H) extradeterministicnot exactofflineiterative1 language
Dynamic programming stereoΘ(W H D) worst · average · bestΘ(W D) extradeterministicexactofflineiterative1 language
Semi-global matchingΘ(W H D R) worst · average · bestΘ(W H D) extradeterministicnot exactofflineiterative1 language

Bounds

  • Output size. Any method writes WHW H values, so it takes Ω(WH)\Omega(W H) time. A method that looks at every disparity of every pixel, as a full cost volume does, takes Ω(WHD)\Omega(W H D). PatchMatch avoids the factor DD by sampling.
  • Local methods. With box aggregation by running sums or an integral image, winner-takes-all takes Θ(WHD)\Theta(W H D) time, independent of the window size.
  • One row. The energy EE restricted to one row is a chain, and dynamic programming finds its exact minimum in O(WD2)O(W D^2) time, or O(WD)O(W D) for the Potts and linear terms.
  • The full grid. Minimizing EE on the 2D grid with the Potts term is NP-hard (Boykov, Veksler and Zabih 2001), by a reduction from multiway cut. For a convex VV of dp−dqd_p - d_q, an exact minimum is computable by one minimum cut on a graph of WHDW H D nodes (Ishikawa 2003). In practice the methods above are approximations, and their quality is measured on benchmarks, not proved.

Reductions

  • To labeling. Stereo matching with the energy EE is a labeling problem on a Markov random field with DD labels per pixel. Any MRF method applies, which is why graph cuts and belief propagation entered stereo.
  • From general camera pairs. An unrectified pair reduces to this problem by stereo rectification, as long as the epipoles are outside the images.
  • To optical flow. Stereo matching is optical flow with the vertical component fixed at zero and the horizontal one at most zero. A flow method can solve it, with more work and less accuracy.
  • To depth. A disparity map gives a depth map by Z=fb/dZ = f b / d, see depth from disparity.

Applications

Depth for robots, cars and drones from a pair of cameras; 3D models of buildings and terrain from aerial images; depth for view synthesis and refocusing in phone cameras; and the first step of depth map fusion in 3D scanning.

References

  1. 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 whole paper (the four steps of matching cost, aggregation, optimization and refinement, the taxonomy of methods, and the evaluation by the percentage of bad pixels)
  2. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 12, Depth estimation (dense correspondence, local methods and global optimization)
  3. Yuri Boykov, Olga Veksler and Ramin Zabih, Fast approximate energy minimization via graph cuts, IEEE Transactions on Pattern Analysis and Machine Intelligence 23(11), 2001, the proof that minimizing the energy with the Potts smoothness term is NP-hard, and the expansion and swap moves

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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml