Scanners Do Not Change Topology: Training Segmenters to Agree on Shape Across Appearance Shifts

Medical segmentation networks are usually trained with losses that score each pixel independently. Such losses can report high overlap while the predicted anatomy is impossible: a vessel tree cut into pieces, or a heart wall with a hole in it. Both failures get much worse when only a few labeled scans exist and the model is then deployed on a scanner it never saw. The idea here rests on one physical fact. A patient's anatomy has the same connectivity (how many pieces, how many loops, what encloses what) no matter which scanner imaged it. We propose to turn that fact into a training signal that needs no extra labels. Take an unlabeled image, distort its appearance the way a different scanner might, and require that the network's prediction on the distorted image have the same topology as its prediction on the clean image. The comparison uses an exact topology loss, not pixel agreement.

The bet is this. Teaching invariance of connectivity directly, during ordinary training on a small labeled set plus an unlabeled pool, should transfer to unseen sites better than two alternatives. One is supervised topology losses, which have only been tested on in-distribution splits. The other is pixel-level consistency, which cannot tell a harmless boundary wobble from a one-pixel break that cuts a vessel in two. If this works, it would give fragmentation-resistant segmenters without per-site test-time optimization. It would also cover non-tubular multi-class organs, where most existing topology-under-shift methods do not apply.

Core Claim

Under few labels and unseen-scanner evaluation, a cross-view topological consistency loss on unlabeled images should reduce topological errors on held-out sites more than two controls given identical augmentations. The first control is the same supervised topology loss applied to labeled data only. The second is the same consistency setup scored with pixel Dice. It should do so without lowering Dice. "Topological errors" here means wrong numbers of connected pieces and loops (Betti errors), plus failed topological success. The ingredient that makes this possible is a topology loss cheap and spatially faithful enough to run on every unlabeled image at every step.

Where This Sits in Prior Work

Several papers motivate the gap. The exact topology losses (Topograph, TopoMatch, the persistent-homology loss for cardiac MRI) all show that pixel losses miss topology. Topograph builds a graph of the components formed by overlaying prediction and target. It penalizes only the "critical" components whose error changes connectivity, at about 96 ms per loss evaluation versus about 327 ms for Betti Matching. TopoMatch shows that earlier persistent-homology losses match features in the wrong place, spatially incorrectly up to 99.4% of the time, and fixes this with induced matchings. The cost is a cubic worst case. Byrne et al. apply persistent homology to unions of cardiac classes, raising 2D topological success on ACDC from 85.3% to 98.7%. They use it only as slow fine-tuning, about 15 minutes per 3D volume on MM-WHS.

None of these three is evaluated under domain shift or with few labels. All three need a ground-truth mask as the target. We reuse Topograph as the method component because of its speed and spatial correctness. We change what it compares: two predictions of the same anatomy under different appearances, rather than a prediction and a label.

The closest competitors attack fragmentation under shift for retinal vessels. ErrorNet trains a variational autoencoder (a generative model of plausible masks) to inject realistic breaks, then trains a second network to repair them. That is a three-network 2D pipeline with no formal topological invariant. GraphSeg fits a deformable vessel atlas inside variational inference, but its atlas comes from heuristic offline skeletonization of the training masks. TopoTTA is the most direct relative, so it constrains our design. At test time, on each target domain, it injects pseudo-breaks into confident vessel regions and trains a student to reproduce the unbroken teacher prediction.

We differ from TopoTTA in three concrete ways. We act during training, so inference costs one forward pass. We score agreement with a homotopy-aware loss rather than pixel agreement. And we handle solid multi-class organs through class unions, where TopoTTA's directional convolutions for tubes do not apply.

Two semi-supervised methods sit nearby but answer different questions. B-MIM shows that biased masked pretraining on about 10,000 CT scans improves vessel continuity out of distribution, but it uses no explicit topology term. Multi-Constraint SSL enforces shape with adversarial discriminators on a single-center benchmark. Our proposal needs neither a large pretraining corpus nor a min-max game.

Research Program

The objective adds one unlabeled term to a standard supervised loss. Let $x_l, y_l$ be a labeled image and mask, and $x_u$ an unlabeled image. Let $f$ be the student network and $\bar f$ its exponential-moving-average teacher. Let $T$ be a random appearance transform, and $B$ a binarization of the teacher's prediction restricted to pixels where the teacher is confident. The loss is

$$ \mathcal{L} = \mathcal{L}_{\text{Dice+CE}}(f(x_l), y_l) + \lambda\, \mathcal{L}_{\text{topo}}(f(x_l), y_l) + \mu\, \mathcal{L}_{\text{topo}}\big(f(T(x_u)),\, B(\bar f(x_u))\big), $$

where $\mathcal{L}_{\text{topo}}$ is the Topograph loss, and $\lambda, \mu$ are weights. For multi-class anatomy, $\mathcal{L}_{\text{topo}}$ is applied to each class and to anatomically meaningful class unions, following Byrne et al. Because Topograph penalizes only critical components, the third term ignores boundary jitter between views. It fires only when the distortion causes a split, merge, or new hole. This is exactly the failure that scanner shift produces in thin structures.

The transforms $T$ are designed to break topology where real shifts do. They include global intensity-curve remapping, vendor-like noise and blur, and a fragmentation-targeted component. That component fades local contrast along the teacher's soft skeleton near thin segments and terminations, where clDice is known to struggle and where the mandibular-canal study saw dropouts.

The teacher's own topological mistakes are the main risk, the confirmation bias noted for pseudo-labeling. We contain it in three ways. The teacher always sees the clean view. Low-confidence pixels are excluded from $B$. And $\mu$ ramps up only after the supervised topology term has converged.

We will build the loss for 2D first and then run a 3D extension using Topograph's near-linear component graph. We will also log loss runtime per step, so the cost claim is measured rather than assumed.

Baselines

The naive reference point is a U-Net trained in the nnU-Net style with Dice plus cross-entropy and the full augmentation pipeline, including our appearance transforms applied to labeled images. This gives augmentation itself full credit. On AMOS this class of model reaches 89.04% CT mean Dice in distribution yet loses more than 20% on unseen MRI scanners (AMOS). That gap is what we aim to narrow for topology.

The most important competitor is the same network with the supervised Topograph loss and the same augmentations, but without the unlabeled consistency term ($\mu=0$). If it matches us, our ingredient adds nothing. A clDice-supervised variant (clDice) is run alongside it on vessels.

The pixel semi-supervised competitor is Mean Teacher with the identical teacher, perturbations, and unlabeled pool, scored with pixel Dice. On ACDC with 5% labels, Multi-Constraint SSL reports 0.654 DSC for Mean Teacher and 0.730 DSC for its own method. We will report against those, and against 0.801 at 10% labels. Beating it means at least matching 0.730 DSC while raising topological success, which Byrne et al. report as 85.3% for a plain U-Net and 98.7% with persistent-homology fine-tuning in the fully supervised setting.

For retinal cross-dataset transfer, the strongest existing systems are GraphSeg, ErrorNet, and TopoTTA. ErrorNet reports 71.0 average cross-domain Dice. GraphSeg reports +7.43% soft Dice and +6.46% F1 over the next-best method on CHASE→HRF; the absolute values are not given in the file. TopoTTA reports a 31.81% average clDice improvement across its suite and +4.66% clDice over CoTTA. We will rerun these with the same backbone, training images, and tuning budget where code allows. TopoTTA will be applied at test time on top of our naive baseline. We report its extra inference latency and also test whether stacking it on our model still helps. Beating these systems means higher clDice and lower Betti error on held-out datasets, at equal or lower inference cost than TopoTTA.

Two ablations isolate the key ingredient. The first swaps the consistency scorer from Topograph to soft clDice. The second removes the fragmentation-targeted fading and keeps only global appearance transforms. All arms get the same number of hyperparameter trials, chosen on a source-domain validation split only, never on target data.

Why not just…?

Why not just train a strong nnU-Net with heavy augmentation? It is the honest default, and our naive baseline already includes every transform we use. The evidence that it is not enough is indirect. A plain U-Net leaves 14.7% of ACDC slices topologically wrong (Byrne et al.), and nnU-Net trails clDice-augmented models on mandibular canal Dice (0.796 versus 0.844, Lv et al.). Whether this holds under unseen-site shift is exactly what our first comparison measures.

Why not just add a supervised topology loss and augmentations, without unlabeled consistency? This is the real threat. With 10 to 20 labeled images, the supervised term might already teach invariance once augmented views are included. We treat this arm as the falsifier. If it matches our method on held-out Betti error at every label budget, the claim fails. We would then report that supervised topology plus augmentation suffices, which nobody has yet shown out of distribution either. We expect the gap to be largest at the smallest label counts, where unlabeled images supply most of the views.

Why not just use clDice as the consistency term, since it is cheaper? clDice is restricted to tubular shapes, so it cannot express a hole in a myocardial ring or one chamber leaking into another. On vessels it is a live option, which is why it is an ablation rather than an assumption. Topograph is reported to beat clDice on strict topology metrics, but only in distribution. If clDice consistency matches Topograph consistency on retinal transfer, we will recommend it for tubes and keep Topograph only for multi-class organs.

Why not just run TopoTTA at deployment? It works, with large reported clDice gains. But it needs iterative optimization per target domain and is sensitive to its break-injection settings. It is also limited to tubular structures. We compare both accuracy and wall-clock cost, and test the combination. If TopoTTA on a plain model beats our training-time method, then test-time adaptation is the better tool, and our contribution narrows to multi-class organs.

Proposed Experiments

Retinal vessels. We train on one dataset (DRIVE or CHASE) with 5, 10, or all labeled images. The other retinal datasets (STARE, HRF, ARIA) serve as unlabeled pool and unseen test sites, in leave-one-site-out rotation. We report Dice, clDice, Betti-0 and Betti-1 errors, and Topograph's discrepancy between intersection and union.

Non-tubular multi-class anatomy. We use ACDC at 5% and 10% labels, with topological success and Betti error on the unions of left ventricle and myocardium and of right ventricle and myocardium. For shift, we train on MM-WHS in one modality and test on the other. Byrne et al. report Betti reductions but no Dice values there, so no reported Dice result was found on Lacuna for that transfer.

3D extension (secondary). We fine-tune on IRCAD hepatic vessels against B-MIM, whose LoRA variant reports 0.582 vessel clDice versus 0.491 for Swin-nnUNet. The question is whether our term adds continuity on top of, or instead of, large-scale pretraining.

Decisive checks. The decisive check is the gap between our method and the supervised-Topograph-plus-augmentation arm on held-out Betti error. We measure it across label budgets, with Dice held within one point. A second check is a stratified analysis of where breaks occur on unseen sites. If our gains concentrate at low-contrast terminations and junctions, the mechanism is confirmed. If they are uniform, augmentation strength rather than topological consistency is likely the cause. We will also report per-step training cost, to verify that exact topology on every unlabeled image remains practical.