Polyp Boundaries as Surface Residuals: A Differentiable Wall-Fitting Layer for Low-Contrast Lesions

Flat and sessile colon polyps often have the same color and texture as the healthy wall around them. Segmentation networks that look only at pixel intensities therefore draw leaky or collapsed outlines exactly where the outline matters most. These lesions still differ from the wall in one respect: they bulge out of a surface that is otherwise smooth. This proposal defines the lesion boundary geometrically. A network predicts depth. A small least-squares solver, placed inside the network, fits a smooth "healthy wall" surface to the pixels the network believes are not lesion. The boundary is then where the depth leaves that fitted wall. Because the solver is differentiable, meaning gradients can pass back through it during training, the segmentation loss can correct both the mask and the depth representation that feeds it.

The second point concerns scale. A single camera cannot tell a small nearby object from a large distant one, so off-the-shelf depth networks give depth only up to an unknown scale and offset. The layer is built so that this ambiguity cancels out of the boundary exactly. The boundary needs no metric scale at all. Scale is needed only when the outline is converted into a diameter in millimeters. This separates two problems that current systems blur together, finding the edge and knowing the size, and it lets us measure how much of polyp-sizing error comes from each.

Core Claim

Polyp-DAM (Polyp-DAM) already shows that depth helps. It feeds relative depth from a frozen Depth Anything Model into a light segmentation network, and removing depth drops Kvasir-SEG Dice from 0.929 to 0.874. Polyp-DAM uses depth as an extra input channel and leaves the network to discover "protrusion" on its own. Its depth model is frozen, so segmentation errors cannot reshape the depth.

We claim that turning depth into a residual height above an explicitly fitted wall, jointly with the mask, is a better representation for low-contrast lesions than raw depth. We make three specific claims. The residual isolates the one geometric signal that separates a slightly raised lesion from mucosa. It is invariant to the scale-and-shift ambiguity of monocular depth by construction. Making the fit differentiable, with the mask setting which pixels count as wall, gives gains that a fit-then-threshold pipeline does not.

The claim is falsifiable. If a Polyp-DAM-style network given the same depth matches the residual layer on slightly raised (Paris 0-IIa) and sessile lesions, the idea is wrong.

Mechanism

Let $d(x)$ be the predicted disparity (inverse depth) at pixel $x$, and $m(x)\in[0,1]$ the current lesion probability. Within a region around a candidate lesion, we fit a low-order smooth surface $w_\theta(x)=\phi(x)^\top\theta$. Here $\phi$ is a fixed polynomial basis that includes a constant term, and $\theta$ holds its coefficients. The fit is a weighted, regularized least-squares problem:

$$\theta^\star=\arg\min_\theta \sum_x (1-m(x))\,\rho\big(d(x)-\phi(x)^\top\theta\big)+\lambda\|\theta\|^2,$$

In this problem, $\rho$ is a robust penalty solved by a few reweighted iterations, and $\lambda$ is a small damping term. The residual $r(x)=d(x)-w_{\theta^\star}(x)$ is passed back to the segmentation head alongside RGB features. The update of $m$ and the refit are unrolled two or three times.

Monocular disparity is known only up to $d\mapsto a\,d+b$ with $a>0$. Two properties follow because the basis contains a constant and the weighted fit is linear in $d$. The optimal fit transforms the same way as $d$. The residual therefore becomes $a\,r(x)$. Its sign, and hence the zero-crossing that defines the boundary, is unchanged.

Gradients pass through the solver by implicit differentiation of the normal equations. These equations are small (tens of unknowns). The damping $\lambda$ keeps them well conditioned, which avoids the ill-conditioning problems that affect differentiable pose solvers.

Gradients also flow into a low-rank adapter on the depth backbone, in the style of Surgical-DINO, which adapts DINOv2 with LoRA for endoscopic depth. This removes Polyp-DAM's one-way dependency. It also creates a risk: the depth adapter could simply learn to "draw the mask" as a fake bump. We guard against this with a consistency loss to the frozen depth prediction. We also check directly on phantom ground-truth depth that depth accuracy does not degrade (see the decisive checks).

The limitation is honest and scoped. Completely flat 0-IIb lesions have no residual, so the layer cannot help them. Depressed 0-IIc lesions give a negative residual, which the sign handles. We report results by Paris type rather than hiding the failure case.

Relation to Prior Work

Three groups of prior work frame the proposal.

Work that motivates it shows that 2D cues run out at low contrast. Boundary-attention and reverse-attention networks (PraNet-style reverse attention, CaraNet, boundary attention) all refine edges from image features alone. The research file notes that this approach fails when photometric contrast vanishes and is fooled by specular glints and folds. Polyp-DAM supplies the evidence that 3D structure carries the missing information.

Work that supplies the method comes from hybrid neural-geometric pipelines. There, a network produces dense estimates and a classical solver enforces structure. Examples are Deep Two-View SfM Revisited, where networks give correspondences and 5-point RANSAC recovers pose, and Wei et al., who fit instrument geometry by least squares to recover scale. Wei et al. is the closest hybrid work on endoscopy. However, their solver is open-loop and post-hoc. It needs a visible tool of known radius, and it touches only high-contrast metal edges. Our solver is closed-loop, needs no tool, and is aimed at the lesion boundary itself.

Work that constrains the design concerns scale. Metric3D v2 obtains metric depth only given focal length. PPSNet obtains endoscopic depth from the near-field inverse-square lighting law, but assumes uniform albedo, and that assumption breaks at vascular lesion margins. From Generalist to Specialist sizes polyps by retrieval with a frozen vision-language model and states that tool-free metric sizing is unresolved. These papers are why the boundary is designed to be scale-free, and why metric sizing is treated as a separate, measured stage rather than claimed as solved.

Research Program

We build the layer on top of a Depth-Anything or DINOv2 depth backbone with a LoRA adapter, plus a light segmentation head matched in size to Polyp-DAM's 0.47M trainable parameters.

The analysis has three parts. First, we test the invariance property empirically. We apply random scale and shift to the input disparity and confirm that the mask does not change. Raw-depth-channel networks give no such guarantee, so we test them the same way.

Second, we study conditioning and basis order. Candidates are planar, quadratic, and cylindrical-in-disparity walls. We measure how often the fit locks onto a fold instead of the wall, since folds are the main geometric confounder.

Third, we build a sizing stage. The diameter in millimeters is computed from the predicted outline, the endoscope focal length (known per device), and metric depth at the boundary ring. Metric depth comes from a PPSNet-style photometric model or from Metric3D v2 with known intrinsics. This stage lets us break sizing error into two parts. Boundary error is estimated by substituting ground-truth masks. Scale error is estimated by substituting ground-truth depth where it exists.

Baselines

The naive reference is an RGB-only network of the same size and training budget, equivalent to Polyp-DAM with depth removed. That reference reports Dice 0.874 on Kvasir-SEG (Polyp-DAM). PraNet on ETIS (Dice 0.628, as reported in Polyp-DAM) is a second, older 2D reference.

The strongest competitor is Polyp-DAM itself. It reports Dice 0.929 on Kvasir-SEG, 0.941 on CVC-ClinicDB, and 0.891 on ETIS. It is the strongest because it already uses exactly the 3D protrusion cue we rely on. It is also the most likely method to capture our gains without any geometry.

We will retrain Polyp-DAM with its public design on identical splits. It will use the same depth backbone as our method, so the only difference is how depth enters the model. It will get the same number of epochs and the same hyperparameter-search budget. Beating it means a statistically significant Dice gain on the pooled 0-IIa and sessile subsets across three seeds, with no loss on protruding polyps. A gain only on easy protruding polyps would not count.

Two ablations isolate the key ingredients. The first is a non-differentiable wall fit. It fits the surface once to frozen depth, thresholds the residual, and feeds the result as a channel. This separates "the residual representation" from "closed-loop differentiability." The second freezes the depth adapter while keeping the differentiable layer. This isolates whether letting segmentation reshape the depth helps.

For sizing, the strongest baseline is the retrieval-based vision-language model, which reports diameter MAE of 0.200 cm on the EndoVL polyp reporting subset (From Generalist to Specialist). Beating it means a lower MAE on the same subset, with the scale source stated explicitly.

For depth, we check against PPSNet's reported RMSE of 2.06 on C3VD. The aim is not to beat it but to confirm that the adapter does not degrade depth.

Why not just…?

Why not just feed depth as an input channel, as Polyp-DAM does? This is the real threat. Polyp-DAM's jump from 0.874 to 0.929 Dice shows that a network can learn much of the protrusion cue implicitly. Our argument is narrower. An implicit channel has to rediscover wall-fitting from limited data. It gives no invariance to the depth backbone's arbitrary scale and shift. It should therefore degrade on out-of-distribution scopes such as ETIS and on slightly raised lesions, where the bump is small relative to wall curvature. If the head-to-head comparison and the scale-shift perturbation test show no difference, we will report that the explicit layer is unnecessary.

Why not just fine-tune SAM on RGB, or on RGB plus depth? Polyp-DAM argues that SAM-scale models are costly for real-time use. More basically, when a lesion has no photometric step edge, a larger 2D model still has nothing to latch onto. We will include a medical-SAM fine-tune on the Paris-stratified test set. If it matches us on 0-IIa lesions, geometry is not the bottleneck.

Why not just fit the wall post-hoc, without backpropagation? This is exactly our first ablation. Our hypothesis is that post-hoc fitting fails because the fit is contaminated by lesion pixels whenever the initial mask is wrong. The closed loop corrects this: the mask sets the inlier weights and the refit sharpens the mask. If the post-hoc version matches the differentiable one, the contribution reduces to a feature-engineering result, and we will say so.

Why not just use multi-view SfM from the video? Non-rigid tissue, a moving co-located light, and specularity break classical multi-view geometry in endoscopy (EndoSLAM). Monocular SfM also has no metric scale, so it would not remove the sizing problem either.

Proposed Experiments and Decisive Checks

We train on Kvasir-SEG and CVC-ClinicDB, and test on these plus ETIS, ColonDB, and Endoscene for cross-center generalization. The metrics are Dice, IoU, and a boundary-band F-score. Because none of these datasets report per-morphology results (no reported result found on Lacuna for Paris-stratified segmentation), we will have test polyps labeled by Paris type and report results per type. The 0-IIa and sessile subsets are the primary endpoint. Protruding polyps are a control, and 0-IIb lesions are an expected-failure case.

The first decisive check is invariance. Under random disparity scale in [0.2, 5] and arbitrary shift, our masks should not change. We will measure the Dice drop of the Polyp-DAM baseline under the same perturbation.

The second decisive check is depth integrity. On C3VD, whose ground-truth depth allows it, the LoRA-adapted depth must stay within noise of the frozen backbone's RMSE. The reference point is PPSNet's reported 2.06. A large drop in depth accuracy alongside better Dice would mean the adapter learned to fake bumps, and would invalidate the claimed mechanism.

The third decisive check is the sizing budget on EndoVL. We report diameter MAE for predicted mask with predicted metric depth, and for ground-truth-derived mask with predicted depth. The comparison is against the 0.200 cm retrieval baseline. This shows whether residual sizing error is dominated by boundary quality, which our layer addresses, or by monocular scale, which remains open without per-device photometric calibration. Either result is informative. The second would state concretely what the scale-ambiguity community still needs to deliver for tool-free polyp sizing.