Exact Whole-Canvas Connectivity Losses for Tiled Segmentation of Thin Structures

Whole-slide pathology images and large aerial mosaics are far too big for a GPU, so segmentation networks see them only as thousands of small tiles. For thin, branching structures such as capillaries, alveolar walls, ducts or roads, this tiling breaks the property that matters most: whether things are connected. A vessel that crosses a tile border can be predicted as two stubs that almost meet. Pixel-overlap scores barely register the error, but the network the vessel belongs to is now severed. Topology-aware training losses exist, but they are computed inside a single crop. Methods that avoid seams exist too, but they optimize pixel overlap or visual coherence, never connectivity.

We propose to train a tile-level segmenter with a loss computed on the connectivity of the entire canvas, obtained exactly and at near-linear cost. The key observation is that in 2D the two topological quantities that matter can both be computed by merging regions as the confidence threshold is lowered. These quantities are connected components, and loops, which by duality are components of the background. That merging process, a maximum spanning tree over pixel confidences, decomposes cleanly over tiles. Each tile can be compressed into a small tree over its border pixels, and gluing these trees reproduces the global answer exactly. This yields, for every wrongly split or wrongly merged structure anywhere on a gigapixel canvas, the single pixel whose confidence decides the error, often at a seam far from any one crop. A second, cheap pass then pushes gradient into only those pixels.

Core Claim

Topological losses have been "trapped in small patches" because general persistent homology, which tracks when components and loops appear and disappear as a threshold sweeps, costs $O(n^3)$, as noted for Topologically Faithful Image Segmentation via Induced Matching of Persistence Barcodes. The research file treats whole-slide persistence as infeasible. For 2D images and the two homology dimensions that matter, that conclusion is too pessimistic. Zero-dimensional persistence of the superlevel sets of a probability map is exactly the maximin structure of a maximum spanning tree, and one-dimensional persistence is the same computation on the complemented map. Maximum spanning trees satisfy an exact merge property: the tree of a union equals the tree of the union of per-tile trees plus the edges that cross tile borders. Interior vertices of a per-tile tree can be contracted away while keeping the maximin value between every pair of border pixels. What remains is a tree whose size scales with the tile perimeter. Global persistence of a $10^{10}$-pixel prediction therefore needs one streaming, no-gradient pass over tiles and a merge whose memory scales with the total length of tile borders.

The claim to test is that a segmenter trained with this exact global connectivity signal produces predictions whose whole-canvas topology is correct and stable when the tile grid moves. Tile-local topology losses, overlap-averaged stitching and larger context windows fail at this in a measurable, seam-concentrated way.

How This Relates to Prior Work

Three groups of prior work motivate the proposal by exposing the gap. Tile-local topology losses supply the training signal we generalize. clDice matches thinned centerlines using differentiable min/max-pooling. TopoMatch pairs predicted and true components and loops only when they physically overlap, showing that spatially blind matching assigns features wrongly most of the time. A Persistent Homology-Based Topological Loss for CNN-Based Multiclass Segmentation of CMR brings Betti priors to cardiac slices in about 7 seconds each. All three see only what lies inside one crop. We keep their idea of spatially grounded matching but make the thing being matched the whole canvas.

Gigapixel segmenters attack tiling with context rather than topology. HoloHisto enlarges the tile to 4096 pixels with a pretrained tokenizer and linear attention. WSI-INR replaces tiles with a continuous coordinate field and inference-time optimization of about 6 minutes per slide. Both train with Dice-style losses on blob-like targets (glomeruli, metastases). A 4K window still has seams across a slide, and a continuous field removes seams without guaranteeing connectivity.

Seam-removal methods from diffusion synthesis show that cross-window agreement can be enforced at linear cost. SyncDiffusion uses perceptual gradients from an anchor window, and SyncSDE casts synchronization as conditional score estimation. Their notion of agreement is texture and appearance, which says nothing about whether a curve continues. We borrow only their lesson that local windows need an explicit coupling term, and replace appearance with exact connectivity.

Multi-scale work enters as context and as a constraint on evaluation. MAMILNet averages predictions across magnifications, and MINER fits orthogonal frequency bands. Neither asks whether connectivity visible at low magnification survives at high magnification. The fixed-resolution direction enters as a stress test. WSI-INR reports that U-Net and TransUNet lose 54.28% and 36.18% Dice when moved from base resolution to base/4. We ask the analogous topological question: does connectivity survive changes in tile size, grid offset and magnification?

Research Program

Exact decomposable persistence. The first component is an algorithm and library. In the forward pass, each tile's probability map is reduced by union-find to its maximum spanning forest. The forest is then contracted to a border tree that preserves maximin values between border pixels and records, for each merge event, the interior pixel responsible. A merge step glues border trees along shared edges. It recovers global 0- and 1-dimensional persistence pairs, each tagged with the image location of its critical pixel. We will prove exactness against a direct computation on canvases up to the size where the direct computation fits in memory, and report wall-clock time and memory on synthetic canvases from $10^7$ to $10^{10}$ pixels.

Matching against ground truth on the whole canvas. The ground-truth mask is decomposed the same way. Following TopoMatch's insistence on spatial correspondence, but at canvas scale, a predicted feature is matched to a true feature only when their component footprints overlap. We implement this cheaply with component labels propagated through the same border trees, rather than with TopoMatch's full induced matching, whose cost we cannot afford at this size. A simpler variant that we will also report samples point pairs across the canvas. It penalizes the maximin edge between two points when its value disagrees with whether the points share a true component. This is a pair-connectivity loss in the spirit of older maximin-affinity methods, now made exact at gigapixel scale. With $p_c$ the predicted probability at critical pixel $c$ and $y_c \in \{0,1\}$ whether that pixel should be foreground to repair the matched error, the global term is

$$ \mathcal{L}_{\text{glob}} = \sum_{c \in \mathcal{C}} w_c \, \big(p_c - y_c\big)^2, $$

where $\mathcal{C}$ is the set of critical pixels of unmatched or mismatched persistence pairs and $w_c$ is the pair's persistence. The total loss adds this to the usual tile-level Dice and cross-entropy.

Two-pass training. Pass one runs the network without gradients over a large region, for example a 32k×32k window of a slide, to find $\mathcal{C}$. Pass two re-runs with gradients only the tiles that contain critical pixels. The cost of the global term therefore scales with the number of topological errors, not with the canvas area. We will measure what fraction of critical pixels lie within a few pixels of a tile border. If this is low, the seam story is wrong and the project reduces to a tile-local loss.

Cross-scale consistency as a cheap extension. The same machinery runs on a coarse prediction at low magnification. Components that are connected at coarse scale but split in the glued fine-scale structure become an additional set of critical pixels. This is the only multi-scale ingredient, and it is ablated separately.

Baselines

The naive reference point is a U-Net trained with Dice and cross-entropy on fixed tiles, run with 50% overlap and Gaussian-weighted averaging at inference. This is the standard overlap-add pipeline. HoloHisto reports that plain U-Net patch-and-stitch reaches 62.19% whole-slide Dice on the Kidney Pathology Image Segmentation (KPIS) dataset. This baseline shows how much connectivity is lost when nothing addresses it.

The strongest competitor on the precise question is the same backbone and overlap-add inference trained with a tile-local topology loss: soft-clDice mixed with Dice, as in clDice, and separately TopoMatch applied inside each tile. It is the strongest because it already optimizes connectivity, costs little (clDice adds under 10% training time at 1024×1024), and overlap averaging may repair many seam breaks unaided. The file has no reported clDice or TopoMatch numbers on the benchmarks we use (no reported result found on Lacuna for clDice or TopoMatch Betti error on DRIVE, Massachusetts Roads or CREMI), so we will run both ourselves. Backbone, tile size, training images, number of gradient steps and hyperparameter search budget will match those of our method, with the loss weight tuned on the same validation split. Beating it means a lower whole-canvas Betti error and higher pair-connectivity accuracy, with non-overlapping confidence intervals across three seeds, at Dice no more than one point lower.

The large-context competitor is a HoloHisto-style 4K-window model, which reports 84.54% whole-slide Dice on KPIS against 77.24% for SAM-ViT-H. We will reproduce it on KPIS to calibrate our pipeline against that number, then train it on the thin-structure tasks. It tests whether enlarging the window alone removes the problem. On the lesion task we will include WSI-INR as the continuous-coordinate competitor. Its evaluation there is only a "does no harm" check, because its targets are not thin.

Two ablations isolate the key ingredient. The first uses our decomposition but drops the gluing step, so persistence is computed per tile with identical code and budget. This separates exact global structure from simply having a persistence loss. The second restricts gluing to a fixed radius of neighboring tiles, which tests whether truly long-range connectivity matters or whether local seam repair is enough. A third removes the cross-scale term.

Why not just…?

Why not just use overlap-add stitching with a clDice-trained tile model? This is the real threat, and we treat it as the main hypothesis to beat rather than something to argue away. Overlap averaging repairs breaks that both overlapping tiles see. It cannot repair a vessel that fades inside the overlap for both tiles, or a merge between two structures that only becomes visible several tiles away. Evidence that averaging is not enough for global structure comes from SyncDiffusion's comparison with plain window averaging, where users preferred the synchronized result for coherence 66.35% of the time. That evidence concerns appearance, not topology, so it only suggests the risk. The seam-localization analysis and the no-gluing ablation settle the question. If critical pixels are rarely near seams, or if clDice with overlap-add matches our whole-canvas Betti error, the global term adds nothing and we will report that.

Why not just close gaps with morphology or path-tracing after segmentation? ErrorNet reports that heuristic post-processing such as conditional random fields needs dataset-specific tuning and loses to learned correction across domains. The treelike-structure review Human Treelike Tubular Structure Segmentation notes that dilation leaks into neighboring tissue at bifurcations and faint distal branches. Post-processing also cannot un-merge falsely connected structures without a model of which link is weakest, and that weakest link is exactly what our critical pixels provide. We will include morphological closing and minimum-cost gap bridging, tuned on validation data, applied to the clDice baseline, and compare Betti error and false-merge rate.

Why not just use a bigger window or downsample the whole image? A 4K window moves the seams but does not remove them. At full magnification a slide is roughly 25×25 such windows. Downsampling a 100k-pixel slide to 2k shrinks structures 50-fold, erasing walls a few pixels wide. The file's multi-scale screening work, Multi-Context Deep Network for Angle-Closure Glaucoma Screening, documents the analogous loss of fine boundaries. The HoloHisto baseline and a coarse-only baseline, upsampled and evaluated at full resolution, test this directly.

Proposed Experiments

We are candid that the file contains no public gigapixel benchmark with dense labels for thin structures, so evaluation combines a controlled proxy with the closest real histology. For the proxy, we use Massachusetts Roads and CREMI from the TopoMatch evaluation, plus high-resolution fundus images (HRF) and DRIVE from the retinal suite. On these we force tiles to be small relative to the image, for example 128-pixel tiles on 1500-pixel road images, so that a single road network spans on the order of a hundred tiles. The images still fit in memory, so the exact global ground truth and a no-tiling upper bound can both be computed. For real histology, we use HuBMAP lung alveoli, the one functional tissue unit where top competition models reach only about 0.72 Dice against a 0.835 mean (Segmenting functional tissue units across human organs). Alveolar walls form a mesh whose loops are the alveoli, a natural target for one-dimensional topology. We also use KPIS and CAMELYON16 as controls where the targets are blobs and our loss should neither help much nor hurt.

Metrics are Dice and clDice for overlap; whole-canvas Betti-0 and Betti-1 error, computed after stitching rather than per tile; pair-connectivity accuracy on randomly sampled foreground point pairs, stratified by distance in tile units; and false-merge and false-split counts. We also measure grid-shift instability: the change in whole-canvas Betti numbers when the inference tile grid is offset by half a tile, or when tile size at inference differs from training. This last metric links the proposal to the fixed-resolution direction, because a model whose topology depends on where the grid falls has learned the grid.

Three checks decide the project. The first is exactness and scaling: the decomposed persistence must match direct computation exactly, and on 32k to 100k-pixel canvases the pass-one cost must stay within a small constant of an inference pass. The second is the seam test: pair-connectivity accuracy for point pairs more than five tiles apart must improve over tile-local clDice and TopoMatch, and the no-gluing ablation must lose most of that gain. The third is the invariance test: grid-shift instability must drop relative to all baselines while Dice on KPIS and CAMELYON16 stays within a point of the Dice-only model. The persistent-homology loss for cardiac MR reports a trade-off in which topology constraints cost some pixel overlap, so we will report that trade-off explicitly rather than hide it. If the global term improves long-range connectivity on the road and fundus proxies but not on alveoli, we will report the result as specific to elongated networks rather than meshes.