Trust the Image Where It Speaks: Contrast-Gated Shape Completion for Segmentation Under Scanner Shift

When a medical segmentation network meets a new scanner or protocol, its errors are not spread evenly. They pile up along the stretches of an organ's outline where the new images give little contrast: where the prostate meets the rectum, where a thin atrial wall fades into blood, where ultrasound signal drops out. A learned anatomical shape prior is a model of what plausible organ outlines look like, trained only on expert masks. Because it never sees image intensities, it does not care which scanner produced the image, and in principle it can fill in such stretches. In practice, existing methods apply the prior to the whole mask at once. That smooths away sharp, well-imaged borders together with the bad ones, and when it is used to adapt the network at test time, it can lock in the network's own mistakes.

We propose to split each predicted outline into two kinds of segments. Trusted segments are those where the target image itself shows a measurable intensity step across the predicted border. Untrusted segments are those where it does not. A shape-completion model, trained on masks alone to rebuild an outline from partial anchors, then redraws only the untrusted stretches and keeps the trusted ones fixed. The result is a single forward pass at test time, with no per-volume optimization. It keeps fine detail where the image supports it and imposes anatomy only where the image is silent. The contrast measurement it relies on is computed fresh on every target image, so it is not inherited from the source domain.

Core Claim

Shape priors fail to help under domain shift partly because they cannot tell where the image is still informative. We claim that gating the prior by a scanner-invariant, per-segment measure of boundary contrast, combined with a mask-only completion model that conditions on the trusted segments, will improve surface accuracy under scanner and protocol shift. The improvement should appear specifically in low-contrast boundary segments, without degrading high-contrast ones. Applying a shape prior everywhere, as in a denoising autoencoder (a network trained to map corrupted masks back to clean ones), should do worse on high-contrast segments and fine structures.

Prior Work and How This Differs

Three works establish that mask-only priors survive domain shift, and they motivate this proposal. Anatomical Priors in Convolutional Networks for Unsupervised Biomedical Segmentation trains a variational autoencoder on unpaired labels and uses it to segment across modalities, relying on geometry being appearance-invariant. Test-Time Adaptable Neural Networks for Robust Medical Image Segmentation adapts a shallow intensity normalizer per test volume so that the frozen segmenter's output agrees with a mask-trained denoising autoencoder. This lifts prostate Dice on PROMISE12 from 0.609 to 0.858, at about 12 minutes per volume. Domain and Geometry Agnostic CNNs for Left Atrium Segmentation in 3D Ultrasound adds a latent shape penalty and a vendor-adversarial classifier during training, reducing cross-vendor mean surface distance from 3.56 mm to 2.01 mm. All three apply the prior globally and weight every voxel equally, and the last works at 64³ resolution. None asks which parts of the outline the target image actually supports. Our proposal keeps their appearance-free prior but applies it only where the image is uninformative.

Two works use the prior as a reliability signal rather than a corrector, and they supply part of our method. Anatomically-aware uncertainty for semi-supervised image segmentation uses the residual between a prediction and its denoising-autoencoder reconstruction as a single-pass uncertainty map that beats Monte Carlo dropout, but only within a single domain. Improved post-hoc probability calibration for out-of-domain MRI segmentation feeds a similar shape signal into per-pixel temperature scaling under cardiac sequence shift. It improves calibration but never changes the mask, and it notes that its prior fails on irregular shapes. We reuse the residual idea as a competing gating signal. The difference is that our gate comes from the image rather than from the network or the prior. Under shift the network is overconfident, as Ouyang et al. document, and the prior cannot see the image at all.

Boundary-focused work under shift both motivates and constrains the design. Train Once, Deploy Anywhere: Edge-Guided Single-source Domain Generalization for Medical Image Segmentation feeds Sobel and Canny edge maps as inputs, arguing that edges are more domain-invariant than intensities. Its authors concede that in ultrasound and low-dose CT these edges are broken or spurious. Boundary-Aware Test-Time Adaptation for Zero-Shot Medical Image Segmentation aligns deep SAM attention with shallow Sobel edges at test time and reports a 12.4% average Dice gain over zero-shot SAM. It has no mechanism to reject edges that belong to artifacts or neighbouring organs. Boundary-weighted Domain Adaptive Neural Network for Prostate MR Image Segmentation weights adversarial alignment and a distance-transform loss toward borders, but it needs unlabeled target data at training time and has no prior for borders that vanish. These works tell us that raw edges cannot be trusted alone. They also tell us the right response is to measure edge evidence and fall back to anatomy when it is absent, not to discard edges.

On the shape-plus-boundary side, SPGNet and Structure Boundary Preserving Segmentation couple statistical skeletons or keypoint evaluators with boundary refinement. Both are trained and tested in-domain and entangle the prior with source-image features. Our prior never sees an image.

Research Program

The pipeline has three parts. The first is any source-trained segmenter, frozen; we use a 3D U-Net in the nnU-Net style.

The second part is the contrast gate. For each point $b$ on the predicted surface, we take thin bands of voxels just inside ($I_b$) and just outside ($O_b$) the surface along the local normal. We compute a separation score

$$ s_b = \frac{|\mu(I_b) - \mu(O_b)|}{\sqrt{\tfrac{1}{2}\left(\sigma^2(I_b) + \sigma^2(O_b)\right)}}, $$

where $\mu$ and $\sigma^2$ are band mean and variance. The score is unchanged by any affine rescaling of intensities, so gain and offset differences between scanners do not affect it. Points with $s_b$ above a threshold $\tau$ are trusted. We smooth along the surface so that the gate forms contiguous segments rather than isolated points. The threshold $\tau$ is set on source validation data only. We also study a version in which the band statistic is computed on the segmenter's early-layer features, to handle speckle-dominated ultrasound.

The third part is the completion model. It is trained only on ground-truth masks. Its input is a signed distance map of the mask in which random contiguous boundary segments, together with a band around them, are replaced by an "unknown" value. Its target is the full mask. This is boundary inpainting on shapes. Because inputs and outputs are masks, the model is appearance-free in the same sense as Dalca et al.'s prior. At test time it receives the segmenter's prediction with untrusted segments marked unknown. Its output is accepted only inside the unknown band; trusted segments pass through at native resolution. This addresses the over-smoothing problem noted for bottlenecked priors. A small consistency term during training penalizes the model for moving anchored boundary points, so it learns to respect anchors rather than regenerate the whole shape.

We will also test the completed mask as the target for Karani-style normalizer adaptation, with the loss restricted to untrusted segments. This shows whether gating also fixes test-time adaptation, separately from the faster single-pass correction.

Baselines

The naive reference is the frozen source U-Net trained with standard nnU-Net photometric and elastic augmentation, evaluated directly on target domains. The file shows this kind of model can be strong in-domain: 3D-UNet reaches 89.04% mDice on AMOS CT in AMOS. The same benchmark reports a drop of more than 20% mDice on unseen MRI scanners, and the unadapted U-Net in Karani et al. scores 0.609 Dice on PROMISE12. To pass, we must beat this model on target-domain HD95 and on surface distance in low-contrast segments.

The strongest existing method on our core question is the denoising-autoencoder-guided test-time adaptation of Test-Time Adaptable Neural Networks, which reports 0.858 Dice on PROMISE12. We will re-run it ourselves with the same segmenter, the same source data, and a denoising autoencoder trained on the same masks as our completion model, with its own iteration budget tuned on source validation. That way the comparison isolates gating and partial completion rather than differences in training data. Beating it means matching or exceeding its Dice while significantly lowering HD95 and low-contrast-segment surface distance, at under one-hundredth of its wall-clock time. A version that only matches Dice but is much faster would count as a partial result.

For the ultrasound and lesion settings, the comparisons are edge-input single-source generalization (EGSDG) and, where 2D foundation models apply, BA-TTA-SAM. Both are trained or adapted on identical source data. The file reports 64.78% Dice for EGSDG on BraTS'19. It reports no number for EGSDG on the six-center prostate data or MMWHS ("no reported result found on Lacuna" for those). We will report our own reproduction.

Three ablations isolate the key ingredient. The first is ungated whole-mask projection through a denoising autoencoder, which tests whether gating matters at all. The second replaces the image-contrast gate with gates based on softmax entropy and on the Adiga-style autoencoder residual, which tests whether the gate must come from the image. The third is an oracle gate defined by ground-truth error, which bounds what any gate could achieve.

Why not just…?

Why not just train the segmenter with boundary-local contrast-erasure augmentation, so it learns to complete shapes itself? This is the most serious threat, and we will run it. We apply the same random erasure of boundary bands that trains our completion model, but to source images, inside nnU-Net training. Our reason to expect a gap is that completion learned this way lives inside the segmenter's appearance features, and those features are exactly what shifts across scanners. The mask-only model cannot be affected by appearance. If this augmented baseline matches our pipeline on PROMISE12 and AMOS MRI, the separate completion model is unnecessary. The contribution would then reduce to the contrast gate as a diagnostic, and we would report that.

Why not just weight Karani's reconstruction loss by a boundary distance map? This is the obvious extension, joining BOWDA-Net's distance loss to test-time adaptation, and we include it. A distance weight emphasizes every boundary equally, including well-imaged segments where the global prior should not intervene. It keeps the 12-minute optimization. It still uses the prior's own reconstruction as the target, so confirmation bias remains. The contrast-stratified analysis below shows directly whether distance weighting helps low-contrast segments while hurting high-contrast ones.

Why not just project the whole prediction through the autoencoder, or apply largest-connected-component cleanup? Connected-component cleanup removes islands but cannot redraw a missing wall, which Degel et al.'s ultrasound dropout cases illustrate. Whole-mask projection is our first ablation. The bottleneck smoothing documented across autoencoder priors predicts that it will increase error on high-contrast segments and thin structures. If it does not, our gating claim is wrong.

Why not gate with network confidence or Monte Carlo dropout instead of image contrast? Adiga et al. show that dropout variance misses large geometric errors, and Ouyang et al. show that out-of-domain confidence is miscalibrated. Both point against network-derived gates. The gate ablation tests this directly.

Proposed Experiments

For prostate, we train on one center and test on PROMISE12 and the six-center prostate collection used by EGSDG. For cardiac MRI, we train on ACDC bSSFP and test on MS-CMRSeg LGE, where the file reports only calibration (ECE 15.37% for Ouyang et al.) and no Dice ("no reported result found on Lacuna" for segmentation accuracy there). For abdominal MRI, we train on AMOS CT and test on AMOS MRI, and train on one AMOS MRI scanner and test on others, focusing on pancreas and other ambiguous organs. Where accessible, we use the multi-vendor 3D echocardiography left-atrium cohort of Degel et al., whose 2.01 mm mean surface distance is the reference. Breast lesions, trained on BUS and tested on BUSI, serve as a deliberate negative control: shapes are irregular, so the prior should help little. A method that claims gains there should raise suspicion.

The metrics are Dice, HD95, mean surface distance, topological error counts (extra components and interior holes), and runtime per volume. The central measurement is surface distance stratified by the contrast score $s_b$ measured on the target image.

Three checks are decisive. First, our method must reduce surface error in the lowest-contrast bins while leaving the highest-contrast bins statistically unchanged. Ungated projection, by contrast, should worsen the high-contrast bins. Second, the image-contrast gate must beat the entropy and residual gates and close a meaningful fraction of the gap to the oracle gate. Third, the gain over the erasure-augmented segmenter must grow with the size of the domain shift, from cross-center prostate to bSSFP→LGE to CT→MRI, if the appearance-free argument holds. If none of these patterns appear, the hypothesis that the prior's job is to fill only what the image cannot say is refuted.