Topologically faithful image segmentation via induced matching of persistence barcodes

Nico Stucki, Johannes C. Paetzold, Suprosanna Shit, Bjoern Menze, Ulrich Bauer

TL;DR

Traditional image segmentation losses focus on pixel overlap, often ignoring the underlying structure and connectivity (topology). This paper introduces Betti matching, the first differentiable loss and metric that guarantees spatially accurate topological matching between predicted segmentations and ground truth. By leveraging induced matchings from algebraic topology, it significantly improves structural correctness across diverse datasets without sacrificing pixel-level accuracy.

What Problem Does This Paper Address?

Standard neural networks for image segmentation are usually trained on pixel-wise losses like Cross-Entropy or Dice. While excellent for maximizing overall pixel overlap, these objectives fail miserably at preserving topology—such as ensuring a blood vessel or road network is continuously connected, or preventing artificial holes in a cell wall.

To fix this, researchers previously turned to persistent homology (a tool from algebraic topology) to create topology-aware losses, most notably the Wasserstein loss. However, these methods have a glaring flaw: they match topological features based purely on their contrast or persistence, completely ignoring where they are in the image. As a result, a hole on the top-left of a prediction could be matched to a hole on the bottom-right of the ground truth. This spatial mismatch leads to unhelpful or even destructive gradients during training.

Dice and Betti number errors fail to detect spatial mismatches, whereas Betti matching error correctly identifies the superior segmentation.

Methods

The authors propose Betti Matching, a framework that ensures topological features (connected components and cycles) are only matched if they are spatially coincident.

  1. Ambient Space Comparison: Instead of comparing the prediction likelihood map ($L$) and the ground truth ($G$) independently, they construct a common "comparison image" $C = \max(L, G)$ (for superlevel sets). This acts as a shared space containing both filtrations.
  2. Induced Matchings: Using the algebraic concept of induced matchings between persistence barcodes, features from $L$ and $G$ are mapped into $C$. If a feature from the prediction and a feature from the ground truth map to the exact same feature in the comparison image, they are formally matched.
  3. Differentiable Loss: Because the birth and death times of these topological features correspond to specific pixel intensities, the Betti matching error is fully differentiable. This allows it to be combined with standard Dice loss for backpropagation: $$\mathcal{L}_{train} = \alpha \mathcal{L}_{BM} + \mathcal{L}_{dice}$$

Datasets

The method was validated across six datasets representing distinct structural and topological challenges:

  • CREMI (Neuron Segmentation): Curvilinear, network-like structures with a high number of cycles.
  • Massachusetts Roads: Complex road networks with frequent connectivity challenges.
  • C. elegans: Microscopy infection images consisting of a balanced number of components and cycles.
  • synMnist: A synthetic, noisy MNIST variant designed to test balanced topological features.
  • Colon Cancer Cell: Blob-like foreground structures primarily requiring dimension-0 (connected component) accuracy.
  • Massachusetts Buildings: Another blob-like dataset focusing on individual building footprints.

Key Insights and Ideas

  • The Spatial Blindspot of Wasserstein Loss: The authors discovered that on complex datasets like CREMI, the popular Wasserstein topological loss matches cycles incorrectly over 99% of the time early in training. Betti matching completely resolves this by forcing spatial correspondence.
  • Smart Gradients: When a predicted topological feature is correctly matched to the ground truth, Betti matching's gradient amplifies its local contrast. Conversely, if a predicted feature is unmatched (a false positive), the gradient suppresses it.
  • A Sharper Metric: Betti number error ($\beta^{err}$) only counts the number of features. Betti matching error ($\tau^{err}$) acts as a "sharpened" version that penalizes spatial displacement, making it a much more reliable evaluation metric for structural fidelity.
Figure 2: Comparison of our Betti matching and Wasserstein matching (Hu et al. (2019)). We match cycles between label and prediction for a CREMI image and highlight matched pairs in the same color. We visualize only six (randomly selected out of the total 23 matches for both methods) matched pairs for presentation clarity. Note that Betti matching always matches spatially correctly while the Wasserstein matching gets most matches wrong.

Key Results

  • Topological Superiority: Across all six datasets, Betti matching consistently achieved the lowest topological errors ($\tau^{err}$ and $\beta^{err}$) for both dimension-0 (components) and dimension-1 (loops) features compared to Dice, clDice, and Wasserstein baselines.
  • Preserved Volumetric Performance: Crucially, cleaning up the structure did not come at the cost of pixel accuracy; standard volumetric metrics like Dice and Accuracy remained competitive or superior to the baselines.
  • Qualitative Improvements: Visual inspections of the segmentations show significantly fewer broken connections in road networks and cleaner, more accurate cell boundaries with fewer hallucinated loops.

Limitations and Future Work

  • Computational Complexity: Computing persistent homology requires a matrix reduction step with a cubic time complexity ($O(n^3)$ relative to the number of pixels). While mitigated by Union-Find and clearing tricks, it remains significantly slower than standard pixel-wise losses.
  • 2D Constraint: The current implementation is restricted to 2D images. While the underlying mathematical guarantees theoretically extend to 3D volumes (such as medical CT or MRI scans), adapting the algorithm efficiently to 3D remains an open direction for future work.

Summary updated

Abstract

Image segmentation is a largely researched field where neural networks find vast applications in many facets of technology. Some of the most popular approaches to train segmentation networks employ loss functions optimizing pixel-overlap, an objective that is insufficient for many segmentation tasks. In recent years, their limitations fueled a growing interest in topology-aware methods, which aim to recover the correct topology of the segmented structures. However, so far, none of the existing approaches achieve a spatially correct matching between the topological features of ground truth and prediction. In this work, we propose the first topologically and feature-wise accurate metric and loss function for supervised image segmentation, which we term Betti matching. We show how induced matchings guarantee the spatially correct matching between barcodes in a segmentation setting. Furthermore, we propose an efficient algorithm to compute the Betti matching of images. We show that the Betti matching error is an interpretable metric to evaluate the topological correctness of segmentations, which is more sensitive than the well-established Betti number error. Moreover, the differentiability of the Betti matching loss enables its use as a loss function. It improves the topological performance of segmentation networks across six diverse datasets while preserving the volumetric performance. Our code is available in https://github.com/nstucki/Betti-matching.
BibTeX
@inproceedings{stucki2023topologically,
  author = {Nico Stucki and Johannes C. Paetzold and Suprosanna Shit and Bjoern Menze and Ulrich Bauer},
  title = {{Topologically faithful image segmentation via induced matching of persistence barcodes}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=vlaPdKdbGK},
}
Figure