Coarse-to-Fine Search Along the Epipolar Line

Stereo transformers match pixels between a left and a right camera image. The usual shortcut is that, after the two images are rectified (warped so that matching points lie on the same horizontal row), each pixel only needs to compare itself against one row of the other image rather than the whole image. That shortcut removes one dimension of the search, but inside each row the model still compares every pixel with every other pixel. Cost therefore grows with the square of the image width, which becomes a real bottleneck at 2K and 4K resolution. We propose to treat the row as a one-dimensional search tree. Each pixel first scores coarse segments of the row, keeps the few most promising ones, and refines only those, down to single pixels. A thin band of neighbouring rows is included at every level so that small rectification errors do not break the search.

The method rests on a specific combination. One-dimensional coarse-to-fine search keeps exact softmax attention, which gives sharp, peaked matches. It also keeps the unbounded disparity range that made sequence-to-sequence stereo attractive: disparity is the horizontal shift between matching pixels, and closer objects have larger shifts. It cuts per-row cost from quadratic to roughly $W \log W$, where $W$ is the row width in tokens. And because candidates along a row are contiguous blocks of memory, the sparse search can run as small dense matrix multiplies, avoiding the scattered memory gathers that slow down two-dimensional sparse attention on GPUs.

Core Claim

Scanline attention is now the default way to put epipolar geometry into transformers. Epipolar geometry is the rule that a point seen in one camera must appear somewhere along a known line in the other camera; after rectification, that line is a row. Several systems use this rule, and all of them keep dense softmax attention within each row:

  • STTR alternates attention within a row and across matching rows, then applies optimal transport with an explicit "unmatched" slot (a dustbin) for occluded pixels.
  • NAFSSR uses a stereo cross-attention module for stereo super-resolution.
  • ECSIC applies stereo cross attention in the latent rows of a learned image codec.
  • Era3D uses row-wise cross-view attention in multi-view diffusion.

Each paper's own analysis leaves an $O(H \cdot W^2)$ cost, where $H$ is the image height in tokens.

On the efficiency side, Quadtree Attention shows that hierarchical top-K selection matches STTR's stereo accuracy with 50% fewer FLOPs and 40% less memory. However, its tree is two-dimensional and ignores geometry, and its custom sparse kernels underuse modern GPUs.

We claim that specializing hierarchical top-K attention to the epipolar line yields three things together:

  • the same matching accuracy and occlusion handling as dense scanline attention;
  • unbounded disparity search, unlike fixed windows;
  • real wall-clock savings that grow with resolution, which neither dense row attention nor 2D quadtree attention delivers.

The cost model is simple. Suppose each query densely scores $C$ coarse segments, then keeps the top $K$ segments at each level and splits each into two. The work per query is then

$$ c(W) = C + 2K \log_2 (W / C), $$

so a full row costs $O(W \log W)$ instead of $O(W^2)$. The logarithm comes from halving the segment length at each of the $\log_2(W/C)$ refinement levels. Adding a vertical band of $\pm b$ rows multiplies this cost by $(2b+1)$, a constant factor.

Research Program

We build the module as a drop-in replacement for STTR's within-row and cross-row attention, so that every other part of the pipeline stays fixed.

At the coarsest level, keys and values are average-pooled into $C$ segments per row. The query attends densely to these segments, and the top $K$ are kept. At each finer level, the children of the kept segments are scored and again pruned to $K$, with $K$ held constant across levels. The output is the softmax-weighted sum at the finest level plus the attention mass from coarser levels, as in Quadtree Attention.

Two design decisions are specific to stereo.

The first is occlusion. STTR's dustbin relies on optimal transport over a full $W \times W$ matrix, which is itself quadratic. We instead run Sinkhorn iterations only on the sparse support produced by the tree: each query has its $2K$ finest candidates plus one dustbin. Sinkhorn is the iterative row-and-column normalization that STTR uses to solve the transport problem. On this sparse support it costs $O(WK)$ per row. We compare it against plain softmax with a learned dustbin logit.

The second is calibration drift. The limitations noted for NAFSSR, ECSIC and CCNeXt are that they fail when epipolar lines leave image rows. We therefore let each tree node span $\pm b$ rows, so vertical misalignment of a few pixels stays inside the search.

On the engineering side, kept segments are contiguous along a row. Each level can therefore be expressed as a batched dense block attention over $K$ gathered tiles. We will benchmark wall-clock time and peak memory against dense FlashAttention-style row attention, not just FLOPs. This is the main practical difference from 2D Quadtree Attention, whose latency is limited by scattered gathers.

The same module also applies, as a secondary test of generality, to stereo super-resolution (NAFSSR's cross-attention block) and to unrectified multi-view stereo. In the multi-view case, the tree replaces MVSTER's $K$ uniform samples along each projected epipolar line. Its known weakness is that coarse sampling misses thin structures, while dense sampling costs linearly more.

Baselines

The naive reference point is STTR as published: dense softmax attention along full scanlines plus full Sinkhorn optimal transport. It sets the accuracy ceiling we must match. It also carries the two properties we must preserve. STTR reports an occlusion IoU of 0.92–0.98, and its unbounded search let a model trained on 192px disparities predict up to 458px zero-shot on Middlebury 2014 (STTR). We retrain it in our codebase with the same Scene Flow training schedule, crop sizes, and tuning budget as our model.

The strongest efficiency competitor is Quadtree Attention plugged into STTR. It is already a sub-quadratic hierarchical top-K method evaluated on stereo, reporting similar accuracy to STTR at 50% fewer FLOPs and 40% less memory. No reported Scene Flow EPE number was found on Lacuna for either Quadtree Attention or STTR, so we will reproduce both under identical settings. We will use the same $K$ and the same number of hierarchy levels where the two designs are comparable. To beat Quadtree Attention, our method must match its end-point error (EPE, the average pixel error in predicted disparity) within noise. It must also show lower measured latency and memory at widths of 1K tokens and above, and a better zero-shot large-disparity transfer. Matching its FLOPs alone does not count.

The bounded-window baseline is CCNeXt-style windowed epipolar cross-attention, which reports a 70.6% FLOP reduction. We run it inside the same STTR pipeline with the window size tuned on Scene Flow validation and given the same compute budget as our tree.

The linear-kernel baseline replaces softmax inside the row with QT-ViT's second-order Taylor kernel. This gives strict $O(W)$ cost per row.

Three ablations isolate the key ingredients:

  • $K=1$ at every level. This is a greedy single-hypothesis cascade and tests whether keeping multiple hypotheses matters.
  • $b=0$. This removes the vertical band and tests robustness to drift.
  • Softmax dustbin instead of sparse Sinkhorn. This tests whether optimal transport is worth its cost once the support is sparse.

Why not just…?

Why not just run dense row attention with a memory-efficient fused kernel? This is the most serious threat. FlashAttention-style kernels remove the $W \times W$ memory, and at moderate widths a dense row of a few hundred tokens may simply be faster than any tree. We do not argue around this. We measure wall-clock time and memory against fused dense row attention as $W$ grows from 256 to 4096 tokens, and report the crossover width. If no crossover occurs below 4K-width inputs, the efficiency claim fails, and the contribution narrows to robustness and accuracy.

Why not just use a fixed disparity window? Fixed windows give linear cost trivially, but they cap the disparity that can be found. GD-PoseMVS reports that range-dependent methods degrade sharply when the search range is expanded 5–10x, and STTR's 192→458px transfer is exactly what a window cannot do. Our Middlebury and SCARED zero-shot evaluation, scored separately for pixels whose true disparity exceeds the training window, settles this directly.

Why not just use linear attention in the row? Linear kernels spread attention too evenly. QT-ViT shows that first-order kernels lose focus. Quadtree Attention reports a 4.0-point higher AUC@20° than standard linear transformers on ScanNet feature matching, where AUC@20° is the area under the pose-error accuracy curve up to a 20° threshold. Stereo needs a single sharp peak per pixel. We include the second-order Taylor variant and expect it to blur disparity at depth edges. EPE restricted to edge pixels will show whether that happens.

Why not just use 2D Quadtree Attention unchanged? It already works for stereo. Our hypothesis is that its geometry-blind coarse levels spend budget on off-row regions and pay a hardware penalty for scattered gathers. The head-to-head comparison at matched $K$, using measured latency rather than FLOPs, tests whether specializing to one dimension actually helps.

Proposed Experiments

We train on the Scene Flow synthetic suite introduced in the FlyingThings3D/DispNet paper. We evaluate EPE, outlier percentage, and occlusion IoU on Scene Flow, and test zero-shot on Middlebury 2014 and SCARED, following STTR's protocol. We then fine-tune on KITTI 2015 and report D1-all, the percentage of pixels with large disparity error.

Efficiency is measured as latency and peak memory per stereo pair at four widths obtained by upsampling Middlebury: 960, 1920, 2880 and 3840 pixels. This produces a scaling curve for every baseline on the same GPU.

Robustness to drift is tested by perturbing the rectification of Scene Flow and KITTI test pairs with vertical shifts of 1–4 pixels and small roll angles. We then plot EPE against perturbation size for $b=0$, $b=1$, NAFSSR-style strict-row attention, and CCNeXt-style windows.

As secondary checks of generality, we swap the module into NAFSSR's cross-attention block on Flickr1024 ×4 super-resolution, scored by PSNR. NAFSSR-B is reported to beat SSRDE-FNet with 79% fewer parameters (NAFSSR), so any loss in PSNR there is a clear negative signal. We also swap the tree into MVSTER's epipolar sampler on DTU. MVSTER is reported as 14% better than CasMVSNet with 51% lower runtime, but absolute millimetre errors for MVSTER were not found on Lacuna, so we will reproduce them.

Three outcomes decide the proposal:

  1. Accuracy. Scene Flow EPE and occlusion IoU must stay within the run-to-run variance of retrained STTR.
  2. Efficiency. Measured latency must fall below fused dense row attention at some practical width, and the gap must widen with width at roughly the predicted $W \log W$ versus $W^2$ rate.
  3. Search range and robustness. Zero-shot large-disparity pixels on Middlebury must keep STTR-level accuracy while the window baseline fails on them, and $b=1$ must flatten the drift curve relative to strict-row attention.

If the first and third hold but the second does not, the honest conclusion is that within-row quadratic cost is not yet the binding constraint on current GPUs, and the method's value lies in robust, unbounded sparse matching.