Trimap as Compute Budget: Single-Pass Exemplar Video Matting with Uncertainty-Allocated Tokens

Video matting computes, for every pixel, how much of it belongs to a chosen foreground object. The answer is a fraction, not a yes/no, so hair, smoke, and glass can be composited onto new backgrounds. Classical matting needs a trimap: a hand-drawn map marking pixels as definitely foreground, definitely background, or unknown. Drawing one per frame is impractical for video. The alternative of tracking a user-chosen object from one click or box runs into two problems. Trackers that remember past frames come to treat the object as a solid shape. And attention, the operation that lets every image patch compare itself with every other, costs grows quadratically with the number of patches, which rules out full-resolution boundaries.

We propose to treat the trimap as an internal decision about where to spend computation, rather than as a user input or a separate pipeline stage. The approach is a Siamese network, meaning two branches with shared weights that compare a reference crop of the target against each new frame. The network first matches the frame against the reference using a few hundred coarse tokens. From that match it predicts a soft unknown-region map. Only the patches inside that region become full-resolution tokens, and those tokens alone regress fractional alpha. The fine tokens read from the reference crop and the coarse tokens, but never from the temporal memory of past masks. Read this way, a trimap fixes three things: which patches get fine tokens, how compute scales with resolution, and how far solid-object memory is allowed to reach.

Core Claim

A single forward pass can do three things together: select an arbitrary instance from one exemplar, avoid the solid-object bias of mask memory, and keep attention cost roughly proportional to boundary length rather than image area. It does this by routing two kinds of tokens separately. Object identity and temporal memory live only in a small coarse token set. Sub-pixel transparency lives only in a sparse set of fine tokens chosen by predicted uncertainty.

The closest work is Matting Anything 2. It found that mask memory causes "temporal collapse" on semi-transparent boundaries and fixed this with a Memory-Separable Siamese scheme. That scheme makes one pass with memory to get a mask, and a second, memory-free pass with that mask as a pseudo-prompt to produce a trimap. A separate matting module then turns the trimap into alpha. The whole pipeline runs at about 11 FPS with 256M parameters on top of unmodified SAM2 attention. We take its diagnosis as motivation but replace its remedy. Memory separation becomes a routing constraint inside one pass, and the trimap becomes a token-allocation map rather than an intermediate image handed to another network.

Research Program

The architecture has three stages.

Coarse stage. A shared encoder embeds the template crop (box- or mask-prompted, first frame only) and the search frame. The search frame is pooled to roughly $M$ coarse tokens, with $M$ in the low hundreds. The coarse tokens run full softmax attention jointly with the $T$ template tokens and $S$ memory tokens. This is the familiar template-search correlation of SiamRPN and its descendants, recast as attention, and it is where distractor rejection happens.

Allocation stage. The coarse tokens predict a three-way soft map: foreground, background, and unknown. Following Mask Guided Matting via Progressive Refinement Network, a coarse mask is enough to localize the uncertain band. The top-$K$ unknown patches at native resolution become fine tokens. This borrows salience-guided reallocation from SG-Former, which keeps dense tokens in important regions and merges the rest, but swaps its learned significance map for an uncertainty map supervised by ground-truth alpha.

Fine stage. The fine tokens attend to three sources: a small local window of neighboring fine tokens, the coarse tokens, and the template tokens. They never attend to memory. Coarse and fine tokens exchange information through bidirectional cross-attention, the mechanism LookupViT uses between its compressed and lookup tokens. LookupViT's authors explicitly left dense prediction open, fearing compression would destroy boundaries. Our design answers that concern directly by never compressing the boundary band.

Per frame, the attention cost is approximately

$$ C \approx (M+T+S)^2 d \;+\; K\,(M + T + w^2)\, d, $$

where $d$ is the channel width, $w$ is the side of the local window, and $K$ is the number of fine tokens. For a solid object with a boundary band of fixed pixel width, $K$ grows with the object's perimeter, that is, with the image side length rather than its area. Doubling resolution should therefore roughly double the fine-stage cost instead of the sixteenfold growth of global attention described for standard vision transformers. Wispy categories such as hair, smoke, and fire break this assumption. We will measure how $K$ actually scales on them rather than assume it.

Training. We supervise alpha with standard matting losses on the fine tokens and segmentation on the coarse tokens, using the video sources available in the matting literature (VideoMatte240K and the VideoMatting108 training split). To build multi-instance clips for exemplar selection, we composite several foregrounds into one clip. The goal is to teach the model to choose the instance the reference crop points to, which Video Instance Matting showed instance-unaware models cannot do.

Baselines

Naive reference. Robust High-Resolution Video Matting (RVM) is a prompt-free recurrent convolutional matter with guided-filter upsampling. It defines the speed ceiling: the file reports 104 FPS at HD on a 1080Ti. It also defines the floor for instance selection: adapted RVM scores 5.79 VIMQ on VIM50 (Video Instance Matting). We run the released model unchanged. Beating it means matching its accuracy on single-subject clips while far exceeding it on multi-instance clips.

Strongest end-to-end competitor. Matting Anything 2 is the main baseline. It reports 14.72 MAD on NOVM, against 39.44 for MatAnyone, and 1.16 MAD on YouTubeMatte. To compare fairly, we initialize our encoder from the same SAM2 image encoder, use identical box and point prompts, and report FPS on the same GPU class. Beating it means matching or improving NOVM MAD, particularly on the transparent categories (fire, bubbles, clouds, frost), at several times its throughput. If our method is faster but clearly worse on those categories, the claim fails.

First-frame-mask competitor. Object-Aware Video Matting with Cross-Frame Guidance reports 4.23 MAD, 0.31 MSE and 1.22 dtSSD on the RVM benchmark. We compare against these published numbers under its first-frame-mask protocol.

Other references. HSTSG reports MSE 5 on DVM. On VideoMatting108, the file gives only a relative 56.7% MSE gain for One-Trimap Video Matting; no absolute reported result was found on Lacuna for VM108, so we will rerun OTVM ourselves.

Ablations. Three ablations isolate the key ingredient. First, memory feeding fine tokens as well, which tests the routing constraint. Second, uniform token pooling at matched FLOPs, which tests uncertainty allocation. Third, fine tokens replaced by a convolutional patch refiner, described under the BGMv2 alternative below.

Why not just…?

Why not just run SAM2 or SiamRPN for a box or mask, then a trimap-free image matter on the crop? The evidence says decoupling hurts. OTVM attributes its 56.7% VM108 MSE gain to modeling propagation and alpha jointly rather than separately. Adapted per-crop matters score only 4–6 VIMQ on VIM50, against 70.74 for MSG-VIM. Matting each frame independently also flickers. We will still build this cascade from the same SAM2 encoder plus MatteFormer-style refinement and report dtSSD, because a strong cascade remains the most likely place to lose.

Why not just refine the top-$k$ uncertain patches with a small CNN, as BGMv2 does? This is the real threat. Real-Time High-Resolution Background Matting already reaches 4K at 30 FPS by refining only uncertain patches, so uncertainty-driven sparsity by itself is not new. What we add is that fine tokens see the exemplar and global coarse context. That should matter where local texture is ambiguous, such as a translucent region over a similarly colored distractor. Our third ablation keeps the allocation map and swaps fine attention for a BGMv2-style convolutional refiner at matched compute. If the refiner ties on NOVM's transparent categories and on VIM50, we will report that the attention component is unnecessary and that the contribution reduces to memory-isolated allocation.

Why not just use linear attention or windowed attention everywhere? The file notes that removing the softmax to linearize attention tends to weaken sharp boundary sensitivity, and that fixed windows lose global context. SG-Former, for example, beats Swin-B by 3.0 mIoU on ADE20K. Our second ablation replaces the fine stage with linear attention over all patches at matched FLOPs, which settles this directly for alpha rather than for classification.

Proposed Experiments

Transparency collapse. The first decisive test is the transparent-category split of NOVM, comparing three systems: memory routed to all tokens, our coarse-only memory routing, and MAM2's two-pass design. If coarse-only routing removes collapse in one pass, we expect MAD on fire, smoke, and bubbles to approach MAM2's while the memory-everywhere variant degrades over clip length.

Exemplar selection. The second is VIM50 VIMQ, prompted with a single first-frame box per instance, against MSG-VIM's 70.74. MSG-VIM relies on an external video instance segmentation model, while ours runs in one pass from one exemplar.

Scaling. The third runs the same clips at 512, 1080 and 2160 pixel heights, plotting fine-token count $K$, memory use, and MAD per category. The prediction that $K$ grows roughly linearly with side length for solid objects, and faster for wispy ones, is falsifiable. If $K$ approaches full patch counts on hair-heavy YouTubeMatte clips, the compute argument fails for exactly the content matting cares about, and we will report that boundary.

Standard benchmarks. We also report MAD, MSE, gradient error and dtSSD on VideoMatte240K (against VMFormer's 4.91 MAD), the RVM benchmark, DVM and VM108, with FPS and parameters on one GPU.