Techniquecore
Subpixel disparity refinement
Also called parabola fitting of matching cost.
Fit a curve to the costs at the best integer disparity and its two neighbors and take the minimum of the curve as a fractional disparity.
Subpixel disparity refinement turns the integer disparity chosen for a pixel into a fractional one by fitting a curve to the costs , and of the cost volume and taking the position of its minimum. With a parabola the offset is
Integer disparities give depth in layers, and by depth from disparity the gap between layers grows with the square of the depth, so far points need fractions of a pixel. The fit costs per pixel. It is not unbiased: the estimates are pulled toward integers, which is called pixel locking, and Shimizu and Okutomi (2005) analyzed this error and proposed a way to cancel it.
In plain words
A stereo matcher tries whole pixel shifts only, so it can say "the match is 20 pixels to the left" but not "20.3 pixels". The cost at shift 20 is the lowest, and the costs at 19 and 21 are higher. If the cost at 21 is only a little higher than at 20 while the cost at 19 is much higher, the true lowest point is probably a bit past 20, toward 21. Draw a smooth bowl through the three costs and read where its bottom is. That is the refined disparity.
When it applies
- A method has chosen an integer disparity with , so both neighbors exist, and is a strict local minimum of the cost column: or , and both.
- The costs near the minimum vary smoothly with the shift, which holds when the images are smooth enough at the scale of a pixel and the cost is aggregated over a window. This is an assumption about the data.
- The depth accuracy matters at a scale finer than one disparity step, as for far points, 3D models and measurements.
The template
SUBPIXEL(C, d, fit)- 1
if d = 0 or d = D - 1 then return d ▷ no neighbor on one side - 2
c₋ ← C(d - 1); c₀ ← C(d); c₊ ← C(d + 1) - 3
if fit = parabola then - 4
a ← c₋ - 2c₀ + c₊ - 5
if a ≤ 0 then return d ▷ flat or not a minimum - 6
δ ← (c₋ - c₊) / (2a) - 7
else ▷ equiangular lines - 8
m ← max(c₋, c₊) - c₀ - 9
if m ≤ 0 then return d - 10
δ ← (c₋ - c₊) / (2m) - 11
return d + δ
The hole is the curve. Two choices are common, and Shimizu and Okutomi (2005) relate each to a cost: the parabola fits SSD-like costs, which are quadratic in a small shift, and two lines of equal and opposite slope fit SAD-like costs, which are close to in a small shift.
Why the parabola formula. Put through , , . Then , and , so and . If , the minimum is at , which is . If and , then , so : the refined value stays within half a pixel of , and refinement never moves a pixel past a neighbor. The minimum value is .
Why the equiangular formula. Take the line through and when , with slope , and the line of slope through . They meet where , at since . The case is the mirror image, and both are the formula of line L10.
Classic examples
Check value. For the costs , , , the parabola gives and , with the minimum value . The equiangular lines give and . Both move toward , the side with the lower neighbor; the lines move further.
Pixel locking. A small experiment shows the bias. A 1D signal is a sum of sines; the right signal is the left one shifted by a known , evaluated exactly. Costs are summed over 7 pixels, and the estimates are averaged over 30 positions. For a smooth signal (frequencies up to 0.6 radian per pixel):
| true | SSD, parabola | SAD, parabola | SAD, lines |
|---|---|---|---|
| 0.10 | 0.101 | 0.058 | 0.101 |
| 0.25 | 0.246 | 0.168 | 0.249 |
| 0.40 | 0.395 | 0.333 | 0.398 |
Each cost fits its own curve well, and the parabola on SAD costs is pulled toward 0. For a rough signal (frequencies from 0.8 to 2.5 radians per pixel) every fit is pulled toward the integer: at the three columns give 0.182, 0.132 and 0.198. A histogram of the refined disparities of a real scene then shows peaks at the integers. These numbers come from this one experiment, not from a theorem.
In stereo methods. Semi-global matching fits a parabola to the summed path costs. Block matching in OpenCV refines its SAD costs the same way. The refined map is what depth from disparity converts, and it is where the error law of that page starts.
Variations
- Error cancellation. Shimizu and Okutomi (2005) match a second time with an image interpolated at half a pixel shift, so that the bias of the second estimate is roughly opposite to that of the first, and average the two.
- Other curves. Higher order polynomials through more costs, or the curve that the cost would have for a known signal model. A polynomial interpolation through five costs has its own bias.
- Direct refinement. Optimize the fractional disparity directly by minimizing the cost over a continuous shift, with images interpolated by bilinear interpolation or better, as in a 1D Lucas-Kanade step. This avoids the bias of the curve but costs more.
- Phase-based methods. The shift of a window can be read from the phase of its Fourier transform, as in phase correlation, which is fractional by nature.
- Soft argmin. Learned methods take the expected disparity under a softmax of the negative costs, which is fractional and differentiable but averages over all disparities.
Pitfalls
- Wrong curve for the cost. A parabola on SAD costs or on census costs is biased toward integers. Use the lines, or a cost that is quadratic near its minimum.
- Ends of the range. At or there is no neighbor on one side. Do not refine, and treat the disparity as unreliable, because the true minimum may be outside the range.
- Flat or non-convex triples. If , the parabola has no minimum, and the formula divides by zero or a negative number. Return the integer.
- Sign. belongs to . Swapping the neighbors flips and doubles the error.
- Refine after the check. A left-right consistency check with on refined maps rejects almost everything. Check on integer maps, or use .
- Smoothing before fitting. Smoothness terms, like the penalties of semi-global matching, change the shape of the cost near its minimum. The fit is then a heuristic.
References
- Masao Shimizu and Masatoshi Okutomi, Sub-pixel estimation error cancellation on area-based matching, International Journal of Computer Vision 63(3), 2005, 207-224, the analysis of the error of parabola and equiangular line fitting, its bias toward integer shifts, and the cancellation with a half pixel shifted image
- 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 subpixel refinement by fitting a curve to the aggregated costs
- 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 subpixel estimation by a quadratic curve through the neighboring costs
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 12, Depth estimation (subpixel estimation and refinement of disparities)
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 | W2 basic |
|
Tag 9V80CG Edit this page History Report an error Markdown