When Rotating a Label Map Breaks Its Topology

Segmentation pipelines rotate and shift label maps all the time. Data augmentation rotates the ground-truth mask alongside the image, and registration warps atlas labels into a new patient's frame. On a pixel grid, each of these steps ends with nearest-neighbor resampling: every output pixel copies the label of the closest source pixel. Digital topology has shown that this step can quietly change the shape's topology. One-pixel-wide vessels snap into pieces, narrow gaps between roads close, and small holes vanish (Digital shapes, digital boundaries and rigid transformations). That theory also gives exact local tests for when this cannot happen. But nearly all of it has been checked on synthetic disks, rings and ellipses. Meanwhile, topology-aware segmentation losses such as clDice and Betti matching are trained on real thin-structure datasets with rotation augmentation. Nobody seems to have asked whether the rotated targets those losses are fitting still have the right topology.

This note proposes to answer that question on real data, and to fix the problem with the smallest possible change. We will measure how often and where real ground-truth masks change topology under rigid resampling. We will test how conservative the exact local sufficient condition is on real masks. Then we will build a topology-preserving label resampler that edits only the pixels where a given transformation actually breaks topology. The standard alternative is to regularize the whole mask in advance, which necessarily thickens every one-pixel structure. The payoff is concrete: cleaner training targets for topology losses, and label warping that neither tears capillaries nor inflates vessel caliber.

Core Claim

We claim three things. First, on real thin-structure datasets (retinal vessels, roads, neuron membranes), nearest-neighbor rotation changes the Betti numbers of a non-trivial fraction of ground-truth masks. Betti numbers are counts of connected pieces ($\beta_0$) and enclosed holes ($\beta_1$). Topology losses trained with standard augmentation therefore learn partly from topologically wrong targets.

Second, the exact local guarantee is sufficient but not necessary. That guarantee is the lookup-table test over 20-pixel neighborhoods from Sufficient Conditions for Topological Invariance of 2D Images under Rigid Transformations. On real masks it will flag far more locations than actually break. This is the open "sufficiency vs. necessity" gap, now measured empirically rather than argued.

Third, the actual breaks under a specific transformation are few and localized. A resampler that repairs only those sites can therefore match the topological guarantee of full regularization at a fraction of its geometric cost. This targets the unresolved trade-off between rigid invariance and geometric fidelity that the file flags for one-pixel capillaries and road branches.

Research Program

The first component is a measurement benchmark built only from real masks. For each ground-truth mask in DRIVE, Massachusetts Roads, CREMI and ACDC, we apply rigid transformations on a dense grid: rotations in 0.5° steps over the full circle, combined with random sub-pixel translations. We resample with nearest neighbor and record whether topology changed.

"Changed" is defined with correspondence, not just by counting. Each output component is traced back through the inverse map to the source components it came from. This distinguishes a split, a merge and a vanished hole, even when the Betti numbers happen to balance out. Each defect is attributed to specific output pixels whose flipping would undo it. Following Topology-Preserving Conditions for 2D Digital Images Under Rigid Transformations, these are pixels that are not simple points: pixels whose flip changes topology.

Exhaustive search over all distinct digital outputs, the "discrete rigid transformation graph" of Phuc Ngo et al., scales as $O(N^9)$ and is out of reach for full images. Dense sampling therefore gives a lower bound on fragility. We will validate that bound on small windows where the exact graph can be enumerated.

On the same masks, we run the 4- and 8-adjacency lookup tables ($P_4$ with 10,643 safe patterns, $P_8$ with 19,446). We report each table's precision and recall as a predictor of actual breakage. This produces the first real-data quantification of how conservative the local-to-global condition is. It also tells us which forbidden patterns account for most real breaks.

The second component is the repair method, a targeted homotopic resampler. Given source mask $X$, transformation $T$ and nearest-neighbor output $Y$, it searches only an ambiguous band. The band contains output pixels whose preimage lies within half a pixel of a source boundary, and pixels flagged by the lookup table. Within the band, it greedily adds or removes pixels that are simple with respect to the target topology. Each edit is chosen to cancel an attributed defect, in order of how close the pixel's preimage lies to the source boundary. The resampler stops when the corresponded topology of the output matches $X$.

Formally, it approximates

$$Y^\star = \arg\min_{Y'} \, |Y' \,\triangle\, Y| \quad \text{subject to } Y' \simeq_T X,$$

where $|Y' \triangle Y|$ counts pixels that differ from the plain nearest-neighbor result. The symbol $\simeq_T$ means that $Y'$ has the same components and holes as $X$ under the correspondence induced by $T$.

This differs from three existing methods:

Our resampler is transformation-specific, restricted to a band, and exactly verifiable, because the output's corresponded topology is checked at the end.

The third component is downstream. We retrain topology-aware segmentation models with rotation augmentation, varying only how the label is resampled. This tests whether cleaner targets change what clDice and Betti matching learn.

Baselines

Naive reference. The do-nothing reference is plain nearest-neighbor label resampling, which is the default in augmentation and registration code. For measurement, it defines the defect rate we are trying to remove. Beating it means reducing the fraction of transformed masks with any corresponded topology change to zero. That zero must be verified per sample, not estimated.

Full regularization. This is the strongest guaranteed competitor: iterative homotopic regularization, and separately $2\times2$ up-sampling, both from Ngo et al. 2014. Each is applied once to the source mask, followed by nearest-neighbor resampling. Both provably preserve topology under any rigid motion, so they set the topological bar. The comparison is on geometry. We measure pixels added or removed relative to nearest neighbor, change in vessel caliber (twice the distance-transform value along the source skeleton), and Hausdorff distance, all on identical transformations and masks.

That paper reports only qualitative results on DRIVE; there is no reported result found on Lacuna for quantitative topology or geometry numbers of this regularization on real data. Beating it means equal topological correctness (zero verified defects) with significantly smaller caliber change and edit count on DRIVE and Roads.

Distance-field resampling. The strongest practical competitor is signed-distance-field interpolation. The binary mask is converted to a signed distance map, interpolated bilinearly or bicubically under $T$, and thresholded at zero. When a probability map is available, as with network predictions, we also include the analogous soft-map resampling. This method is cheap, widely used for label warping and geometrically faithful, so it is the most likely to make our method unnecessary. It gets the same transformations and no tuning beyond interpolation order. Beating it requires fewer topological defects at comparable geometric error.

Other comparisons. We include morphological closing after resampling, with a 3×3 cross, as the heuristic reference. We also include an rNCA-style learned refiner retrained on nearest-neighbor rotation artifacts, with a training budget matched to our method's development set.

Ablation. The ablation that isolates our key ingredient runs the identical greedy simple-point repair at every location flagged by the lookup table, rather than only at sites that actually break under the given $T$. If this prophylactic variant has the same geometric cost as ours, the transformation-specific attribution adds nothing.

Downstream reference. In the segmentation experiments, the strongest method baselines are U-Nets trained with clDice and with Betti matching. Both are trained with identical architecture, patch size (48×48 for Betti matching, as in its paper), schedule, image-side augmentation and seeds. Only the label resampler changes. The file gives no scalar Betti error for either loss on DRIVE or Massachusetts Roads: clDice reports "significantly lower Betti errors", Betti matching reports "significantly lower topological errors", and rNCA reports "2-3% gains in Dice/clDice" on DRIVE. We will therefore re-run both baselines ourselves and compare against those numbers. Beating them means lower Betti error and Betti-matching error on the unrotated test set, at Dice within one standard deviation across seeds.

Why not just…?

Why not just resample a signed distance field or the soft probability map and threshold? This is the real threat, and we treat it as the primary baseline rather than a straw man. Interpolating a smooth field is a reconstruction followed by resampling. The digitization result of Stelldinger and Köthe preserves topology only when features are thicker than the grid spacing plus the blur radius. One-pixel capillaries and diagonally touching road segments violate that condition, so we expect residual breaks exactly where the file says real data departs from $r$-regular synthetic shapes. The benchmark settles it directly. If distance-field resampling reaches near-zero verified defects on DRIVE and Roads at similar geometric error, the method contribution shrinks. The measurement study, together with a recommendation to use distance-field warping, then becomes the paper.

Why not just up-sample by 2×2 before transforming? Up-sampling is provably sufficient (Ngo et al. 2014). But it changes spatial scale and boundary geometry, and it quadruples memory, eight-fold in 3D. More to the point, downsampling back to the original grid, which augmentation and registration require, reintroduces the same fragility. Our geometry metrics quantify the cost at the original resolution.

Why not just rely on rotation augmentation with a topology loss and let the network learn invariance? This proposal is about the fact that augmentation itself corrupts the targets. If the nearest-neighbor rotation defect rate on ground-truth masks is substantial, the network is taught to reproduce broken vessels at some angles. The file also notes that U-Nets trained with standard augmentation still produce characteristic breaks on DRIVE (rNCA). The downstream experiment compares nearest-neighbor against topology-preserving label resampling under otherwise identical training, which tests this directly.

Why not just apply morphological closing? Closing fills gaps indiscriminately. In dense structures like CREMI membranes and parallel capillaries, it merges distinct components and fills true holes, which changes $\beta_1$ (Stucki et al.). In rNCA's CHAOS-CT comparison, morphology reached Dice 0.798 against 0.983 for learned local repair. We include closing so the merge errors are counted rather than asserted.

Proposed Experiments and Decisive Checks

The first check comes before any method work. On the benchmark masks, we compute the fraction of rotation–translation samples whose corresponded topology changes under nearest-neighbor resampling. We report it per dataset and per defect type (split, merge, lost hole). If this fraction is negligible on real ground truth (say below 1% of samples on DRIVE and Roads), the application motivation fails. We would then publish only the measurement and the lookup-table conservatism analysis.

The second check is the precision and recall of the $P_4$/$P_8$ tests against observed breaks, validated against exact graph enumeration on small windows. Low precision confirms that prophylactic regularization over-edits, and quantifies by how much.

The third check is the geometry-versus-topology comparison of our resampler against full regularization, distance-field resampling, closing, the learned refiner and the prophylactic ablation. It uses the same transformations, and we report defect rate, edit count, caliber change, Hausdorff distance and runtime. Synthetic disks and rings serve only as a sanity check that the Ngo et al. guarantees are reproduced.

The fourth check is downstream retraining of the clDice and Betti matching U-Nets with each label resampler. We report Dice, clDice, Betti error and Betti-matching error on the original test images. We also report a rotation-consistency score: the Betti error between predictions on rotated test images and the topology of the correspondingly rotated ground truth.

The decisive outcome is that topology-preserving targets lower test Betti error for both losses while Dice holds steady. If distance-field resampling matches that gain, it wins and we say so.

All experiments are 2D. The file is clear that exact local guarantees do not yet extend to 3D voxel grids (A Tutorial on Well-Composedness). The measurement protocol, though not the guarantee, could be run on Vessap as a follow-up.