# Scalar Function Topology Divergence: Comparing Topology of 3D Objects

Ilya Trofimov, Daria Voronkova, Eduard Tulchinskii, Evgeny Burnaev, Serguei Barannikov

► To cite this version:

Ilya Trofimov, Daria Voronkova, Eduard Tulchinskii, Evgeny Burnaev, Serguei Barannikov. Scalar Function Topology Divergence: Comparing Topology of 3D Objects. Proceedings of the 18th European Conference on Computer Vision, ECCV, 2024, 2024, Lecture Notes in Computer Science, LNCS, volume 15059-15147. hal-04734108

HAL Id: hal-04734108

https://hal.science/hal-04734108v1

Submitted on 13 Oct 2024

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Scalar Function Topology Divergence: Comparing Topology of 3D Objects

Ilya Trofimov¹, Daria Voronkova¹,², Eduard Tulchinskii¹,⁴, Evgeny Burnaev¹,², and Serguei Barannikov¹,³

¹ Skolkovo Institute of Science and Technology, Moscow, Russia
{ilya.trofimov,darya.voronkova,eduard.tulchinskiy,e.burnaev,
s.barannikov}@skoltech.ru

² AIRI, Moscow, Russia

³ CNRS, IMJ, Paris Cité University, France

⁴ AI Foundation and Algorithm Lab, Moscow, Russia

**Abstract.** We propose a new topological tool for computer vision - Scalar Function Topology Divergence (SFTD), which measures the dis-similarity of multi-scale topology between sublevel sets of two functions having a common domain. Functions can be defined on an undirected graph or Euclidean space of any dimensionality. Most of the existing methods for comparing topology are based on Wasserstein distance be-tween persistence barcodes and they don't take into account the local-ization of topological features. The minimization of SFTD ensures that the corresponding topological features of scalar functions are located in the same places. The proposed tool provides useful visualizations de-picting areas where functions have topological dissimilarities. We pro-vide applications of the proposed method to 3D computer vision. In particular, experiments demonstrate that SFTD as an additional loss improves the reconstruction of cellular 3D shapes from 2D fluorescence microscopy images, and helps to identify topological errors in 3D seg-mentation. Additionally, we show that SFTD outperforms Betti match-ing loss in 2D segmentation problems. The code is publicly available: https://github.com/IlyaTrofimov/SFTD.

**Keywords:** Topological Data Analysis · 3D Computer Vision · Geomet-ric Deep Learning

## 1 Introduction

A common situation in computer vision is a structural prediction defined over $\mathbb{R}^n$. Examples include image segmentation [24, 25, 31, 32] and 3D shape reconstruc-tion [36, 37, 39] problems. However, in most of the cases the comparison be-tween the prediction and a ground truth is done pixel(voxel)-wise by metrics like Dice score, cross-entropy, etc. These metrics are not capable of providing de-tailed topological correctness, i.e. preserving multi-scale shape patterns: cavities, holes, connectivity patterns, etc. Typically, predictions involve scalar functions $f: \mathbb{R}^n \to \mathbb{R}$ and the final shape of an object is defined by thresholding $f(x)$.
There is a need for topological-aware comparison metrics for scalar functions, which take into account the topology of sublevel sets $f^{-1}((-\infty, \varepsilon])$ (the analysis for superlevel sets is similar). Existing tools for this problem don't take into account the localization of topological features [24,36] or are limited to 2D space [32]. Our contributions are as follows:

1. We introduce new topological tools: F-Cross-Barcodes and Scalar Function Topology Divergence (SFTD), for a multi-scale topology-aware comparison of scalar functions by tracking differences in their sublevel sets topology.

2. A distinctive feature of F-Cross-Barcodes and SFTD is that they takes into account the localization of topological features;

3. We describe a visualization technique for F-Cross-Barcodes: a technique highlights with points areas where differences in topological features are localized;

4. We propose an algorithm for SFTD differentiation;

5. By doing computational experiments, we show that SFTD as an additional loss term improves 3D shape reconstruction, and helps to identify topological errors in 3D segmentation.

6. We also show that SFTD outperforms Betti matching loss in terms of topological accuracy in 2D segmentation while being ≈ 35 times faster, see Appendix G.

## 2 Related work

Tools of topological data analysis find application in various machine learning problems: evaluation of deep generative models [8], comparison of neural representations [7], dimensionality reduction [29,34], graph neural networks [12,23,40], self-supervised learning [27], molecular data analysis [16], analysis of loss functions in deep learning [6,9], spatial-temporal graph neural network tasks [14,15], crowd localization [1], to name a few.

Several works used topological tools to enhance image segmentation [20, 24, 25, 32]. However, proposed algorithms for comparison ground truth and predicted images either don't take into account localization of topological features [24], or are limited to 2D [32]. A method by [25] highlights in images topologically critical and error-prone structures using discrete Morse theory, and [20] proposes a method for inferring structure-aware uncertainty. The importance of topological interactions for multi-class medical image segmentation is shown in [19].

## 3 Preliminaries

We study scalar functions $f: \mathbb{R}^n \to \mathbb{R}$ by assessing the topology of its sublevel sets. Consider a 1D function depicted in Figure 1. It has two local minima $y_1, y_2$ and a local maximum $y_3$, such that $y_1 < y_2 < y_3$. One can study sublevel sets

<figure><img src="image_2.png" /><figcaption>Fig. 1: 1D function and its sublevel sets.</figcaption></figure>
$X_ε = f^{-1}((-∞, ε])$. For the scalar function $f$, changes of $X_ε$ for increasing $ε$ can be intuitively understood as a “filling the pool”, see Figure 1. There are four distinct situations:

1. For $ε < y_1$, $X_ε = Ø$;

2. For $y_1 ≤ ε < y_2$, $X_ε$ is a single segment;

3. For $y_2 ≤ ε < y_3$, $S_ε$ consists of 2 segments;

4. Finally, for $ε ≥ y_3$, $X_ε$ is a single segment.

Note, that changes in topology of $X_ε$ happen when $ε$ is a critical point of $f$. In the general case, smooth scalar functions defined on smooth manifolds are studied by Morse theory [6]. In practice, we assess functions through their values on a finite set of points, e.g. a lattice (square grid graph) in $ℝ^n$.

## 3.1 Scalar functions defined on a graph

In the most general form, we are interested in topology-aware comparison of scalar functions $f: V → ℝ$ defined on vertices $V$ of an undirected graph $G = (V, E)$. Specifically, we study topological features of subgraphs $\{v ∈ V | f(v) ≤ ε\}$: connected components, cycles, etc.

For each clique $C$ in the graph $G$, we define a filtration function $T(C) = \max_{i∈C} f(i)$. By a clique complex $C$, we mean a set of cliques where each sub-clique also belongs to a complex<fnref n="5" />. For some $ε$, $T(C)$ defines a clique complex $C_j = \{C | T(C) ≤ ε\}$, where $f(j) = ε$. Topological features for a subgraph $\{v ∈ V | f(v) ≤ ε\}$ are precisely expressed by homology groups. Overall, the filtration function $T(C)$ defines the lower-star filtration of the graph's clique complex:

$$ \emptyset ⊆ C_0 ⊆ C_1 ⊆ \dots ⊆ C_n, $$

where $C_n$ is a clique complex of $G$. The filtration is said to be induced by the vertex function $f$.

A given topological feature “appears” at some $ε_1$ and “dies” at some $ε_2$. These topological features, together with their birth and death times can be calculated via tools of topological data analysis. The multi-set of the corresponding intervals ($ε_1, ε_2$) is called the *persistence barcode*, which depicts topological features of the graph for all scales. The whole theory is dubbed *persistent homology* [5, 13].

# 4 Method

## 4.1 Scalar functions defined on a graph

To compare topological features of sublevel sets of functions $f, g: G → ℝ$ we construct a graph $\tilde{G} = (\tilde{V}, \tilde{E})$ with doubled set of vertices from $G$ and one extra

<footnote n="5">⁵ Every clique complex is an abstract simplicial complex, but the reserve is not true.</footnote>
<figure><img src="image_3.png" /><figcaption>Fig. 2: A visualization of $\tilde{\mathcal{G}}$, $\tilde{\mathcal{L}}$.</figcaption></figure>

vertex O, see Figure 2a. Formally, $\tilde{\mathcal{V}} = \{A_1, \dots, A_n, A'_1, \dots, A'_n, O\}$. Edges $\tilde{\mathcal{E}}$ are defined as follows:

$$ (A_i, A_j) \in \tilde{\mathcal{E}} \Rightarrow (A_i, A_j) \in \tilde{\mathcal{E}}, (A'_i, A'_j) \in \tilde{\mathcal{E}} $$

$$ (A_i, A_j) \in \tilde{\mathcal{E}}, i < j \Rightarrow (A_i, A'_j) \in \tilde{\mathcal{E}} $$

$$ (O, A_i) \in \tilde{\mathcal{E}}, (A_i, A'_i) \in \tilde{\mathcal{E}} \text{ for all } i $$

The vertex function $\tilde{f}$ is defined as follows:

$$ \tilde{f}(A_i) = f(i) $$

$$ \tilde{f}(A'_i) = \min(f(i), g(i)), \tilde{f}(O) = \min_{f,g}, $$

where $\min_{f,g}$ is the minimum value of both $f, g$ in the nodes of the graph $\mathcal{G}$.

**Definition.** The $F-Cross-Barcode_k(f, g)$ for two scalar function $f, g$ defined on vertices of an undirected graph $\mathcal{G}$ is the $k$-th persistence barcode for the doubled graph $\tilde{\mathcal{G}}$ and the lower-star filtration induced by $\tilde{f}$.

To put it simply, each interval in the $F-Cross-Barcode_k(f, g)$ denotes a range of functions' sub-level sets where a given topological feature exists in the function $f$ but doesn't exist in the function $g$, see further Appendix A. Technically, the desired persistence barcode is calculated via giotto-ph library [30]. For this software, values of a filtration function must be defined on vertices and edges. Algorithm 1 summarizes the aforementioned.

## 4.2 Scalar functions defined on a lattice

A frequent situation is a function having a domain in $\mathbb{R}^n$. We assume that the function is approximated by its restriction on a sufficiently small grid. Algorithm 1 can also be applied in this case after a space triangulation. However, the number of simplices grows very quickly in high dimensions (see discussion in [35]), and Algorithm 1 has a high computational cost. That is why, we consider cubical complexes [26] instead of simplicial complexes. Specifically, we consider a regular square grid graph (n-dimensional lattice) and use values of functions
**Algorithm 1** F-Cross-Barcode<sub>k</sub> (scalar function k-th cross-barcode)

**Input:** Scalar functions f, g defined on vertices of a graph G = (V, E). |V| = n.

**Require:** PB<sub>k</sub>(·) - an algorithm to calculate k-th persistence barcode from a matrix containing values of a filtration function on graph: on vertices - on a diagonal, on edges - off a diagonal.

1. Create a $n \times n$ matrix F for the function f:
   F<sub>ij</sub> = f(i) for i = j, max(f(i), f(j)) for i ≠ j and (i, j) ∈ E, +∞ otherwise.

2. Create a $n \times n$ matrix G for the function g analogously;

3. Initialize $c_{+\infty}$ to a vector of n elements, all equal to +∞;

4. Create $F_+$, a matrix derived from F with a lower-diagonal part replaced by +∞;

5. Create $F_{diag}$, a vector containing the diagonal elements of F;

6. Compute min(F, G), the element-wise minimum of F and G;

7. Compute min<sub>F,G</sub>, the minimum value of all elements in F and G;

8. Compute the $(2n+1) \times (2n+1)$ block matrix m as follows:

$$m \leftarrow \begin{pmatrix} \min(F, G) & F_+^\top & c_{+\infty}^\top \\ F_+ & F & F_{diag}^\top \\ c_{+\infty} & F_{diag} & \min_{F,G} \end{pmatrix}$$

9. Compute: F-Cross-Barcode<sub>k</sub>(f, g) ← PB<sub>k</sub>(m)

**Return:** F-Cross-Barcode<sub>k</sub>(f, g), a multi-set of ("birth", "death") intervals.

in nodes of this grid: f(j<sub>1</sub>, ..., j<sub>n</sub>), g(j<sub>1</sub>, ..., j<sub>n</sub>). To compare two function f, g, we create an extended n + 1 dimensional lattice $\tilde{\mathcal{L}}$ with one extra dimension of size 3, see Figure 2b. The vertex function $\tilde{f}: \tilde{\mathcal{L}} \to \mathbb{R}$ is defined as follows:

$$\tilde{f}(i, j_1, \dots, j_n) = \begin{cases} \min_{f,g} & \text{for } i = 0 \\ f(j_1, \dots, j_n) & \text{for } i = 1 \\ \min(f(j_1, \dots, j_n), g(j_1, \dots, j_n)) & \text{for } i = 2 \end{cases}$$

Similarly to functions on graphs, F-Cross-Barcode<sub>k</sub>(f, g) for functions on lattices is defined as the k-th persistence barcode of the filtered cubical complex with the filtration induced by the vertex function $\tilde{f}$. We use the GUDHI<sup>6</sup> library which implements efficient algorithms for cubical complexes [35]. Note that F-Cross-Barcode<sub>k</sub>(f, g) for functions restricted on a lattice and a triangulation of the same space are not equivalent, but would be similar.

## 4.3 Scalar Function Topology Divergence

The F-Cross-Barcode<sub>k</sub>(f, g) depicts topological differences of functions' sublevel sets at multiple scales. The F-Cross-Barcode<sub>k</sub>(f, g), as a regular barcode, is a multi-set of intervals. One requires some vectorization technique to inject it into a machine learning pipeline. If one needs to describe a discrepancy between f, g

<footnote n="6"><sup>6</sup> https://gudhi.inria.fr/</footnote>
by an integral numerical characteristic, we propose a scalar function topology divergence:

$$SFTD_k(f,g) = \sum_{(b,d) \in \text{F-Cross-Barcode}_k(f,g)} ||d-b||^p, \quad (1)$$

that is the sum of lengths of intervals from the F-Cross-Barcode_k(f,g) to p-th power, where typically p = 1, 2. SFTD is not symmetric, and we often use an average of SFTD_k(f,g) and SFTD_k(g,f) in experiments below. For different dimensions k, SFTD_k(f,g) can be used either separately, or the sum can be taken to reflect discrepancies in all types of topological features (connected components, cycles, voids, etc.). Computational complexity of SFTD is discussed in Appendix C.

## 4.4 SFTD basic properties

**Proposition 1.** If SFTD_k(f,g) = SFTD_k(g,f) = 0 for all k ≥ 0, then the sub-level sets barcodes of functions f and g are the same in any degree. Moreover, in this case their topological features are located in the same places: the inclusions $f^{-1}((-\infty, \varepsilon]) \subseteq (\min(f,g))^{-1}((-\infty, \varepsilon])$, $g^{-1}((-\infty, \varepsilon]) \subseteq (\min(f,g))^{-1}((-\infty, \varepsilon])$, induce homology isomorphisms for any threshold $\varepsilon$.

**Proposition 2. (SFTD Stability)**

(a) For any scalar functions f, $\tilde{f}$, g, $\tilde{g}$ on a grid, or on a graph vertex set:

$$d_B(F\text{-Cross-Barcode}_k(f,g), F\text{-Cross-Barcode}_k(f', g')) \le \max(\max_i|f(i) - f'(i)|, \max_i|g(i) - g'(i)|).$$

(b) For any pair of scalar functions f, $\tilde{f}$:

$$\|F\text{-Cross-Barcode}_k(f, f')\|_B \le \max_i|f(i) - f'(i)|,$$

where $d_B$ denotes the bottleneck distance between persistence barcodes [13]. We give the proofs in Appendix A. As a consequence, SFTD is robust to noise.

## 4.5 Visualization of F-Cross-Barcodes

F-Cross-Barcodes can be used for localization and visualization of topological differences between scalar functions. Recall the filtered cubical$^7$ complex:

$$\emptyset \subseteq C_0 \subseteq C_1 \subseteq \dots \subseteq C_n.$$

Since the filtration is induced by a vertex function $\tilde{f}: \tilde{\mathcal{L}} \to \mathbb{R}$, the filtered cubical complex corresponds to the sequence:

$$\tilde{f}(i_0) \le \tilde{f}(i_1) \le \dots \le \tilde{f}(i_n).$$

<footnote>$^7$ For ease of presentation, we discuss only the visualization for cubical complexes. The visualization for clique complexes is analogous.</footnote>
If $\tilde{f}(i_k) = \tilde{f}(i_m)$, the order is defined by indexes $i_k, i_m$. Thus, each segment in the barcode - a birth/death pair - is associated with two vertices $v_b, v_d \in \tilde{\mathcal{L}}$. Recall that $\tilde{\mathcal{L}}$ is an extended $n+1$ dimensional lattice (see Section 4.2), where the first dimension is of size 3, and the rest of dimensions are of the same size as the lattice inside the domain of $f, g$. So, neglecting the first dimension, we can map the rest of indices $j_1, \dots, j_n$ of birth/death vertices $v_b, v_d$ right onto original $n$-dimensional lattice. Later, in the experimental section, we shall provide such visualizations, where birth/death events are depicted by orange/red dots.

## 4.6 SFTD differentiation

Calculation of SFTD$_k(f, g)$ involves a filtered simplicial(cubical) complex $\mathcal{C}$ with a vertex function $\tilde{f}(i), i \in \tilde{\mathcal{V}}$. Also, since we apply the sub-level set filtration, for every simplex(cube) $\sigma: T(\sigma) = \tilde{f}(i_\sigma)$, where $i_\sigma = \operatorname*{argmax}_{i \in \sigma} \tilde{f}(i)$. Each interval $(b, d)$ in a F-Cross-Barcode$_k$ corresponds to some pair of simplices(cubes) $(\sigma_1, \sigma_2)$ which join the simplicial(cubical) complex $\mathcal{C}$ at moments $b = T(\sigma_1), d = T(\sigma_2)$. Generally, we consider $f, g$ (and consequently $\tilde{f}$) to be parametric functions of $w$, for example, neural networks. By differentiating (1) we obtain:

$$ \frac{\partial \mathrm{SFTD}_k(f, g)}{\partial w} = \sum_{(\sigma_1, \sigma_2) \in \Sigma_k} p \left( \frac{\partial \tilde{f}(i_{\sigma_2})}{\partial w} - \frac{\partial \tilde{f}(i_{\sigma_2})}{\partial w} \right)^{p-1}, \quad (2) $$

where $\Sigma_k$ is a collection of “birth”, “death” simplex pairs corresponding to intervals in the F-Cross-Barcode$_k(f, g)$.

By construction, $\tilde{f}(i)$ can be either $f(i')$ or $g(i')$ for some mapping $i' = r(i)$. Formally, introducing a binary function $c(\cdot)$ for this choice:

$$ \tilde{f}(i) = c(i)f(r(i)) + (1 - c(i))g(r(i)), \quad (3) $$

and

$$ \frac{\partial \tilde{f}(i)}{\partial w} = b(i) \frac{\partial f(r(i))}{\partial w} + (1 - b(i)) \frac{\partial g(r(i))}{\partial w}. \quad (4) $$

Finally, the desirable gradient $\partial \mathrm{SFTD}_k(f, g)/\partial w$ can be calculated by combining (2), (4) via a chain rule. With a common assumption that all the $f(i), g(i)$ are distinct, functions $c, r$ don't change in a vicinity of $w$, and $\mathrm{SFTD}_i(f, g)$ is differentiable w.r.t. $w$ [11, 22]. On a high level, the differentiation is done similarly to [11, 34].

# 5 Experiments

In the experimental section, we are going to answer three research questions:

**Q1:** Does SFTD and F-Cross-Barcodes provide a better topologically-aware comparison of scalar functions than Wasserstein distance between regular persistence barcodes?

**Q2:** Does F-Cross-Barcodes help to visualize and localize topological differences?

**Q3:** Is SFTD, as a loss function, beneficial for computer vision problems?
<figure><img src="image_4.png" /><figcaption>**Fig. 3:** Two scalar functions (a), (b) are indistinguishable by their persistence barcodes (d), (e). At the same time, $SFTD_0(f_1, f_2) = 4.6$ see (f).</figcaption></figure>

## 5.1 Synthetic data

To illustrate the performance of the proposed tools, we start with synthetic data. Functions under comparison have coinciding persistence barcodes of all degrees and they are indistinguishable by standard Wasserstein matching.

**Functions with local minima in 2D.** First, we compare two scalar function on $64 \times 64$ grid, each of them having 3 local minima but in different locations, see Figure 3, (a), (b). Persistence barcodes of both functions are equal, see Figure 3, (d), (e): they contain two segments from $H_0$ corresponding to local minima. Here and further, essential segments (which die at $+\infty$) are omitted. The topology of the two functions is indistinguishable by standard persistence barcodes and their Wasserstein distance is zero. At the same time, *F-Cross-Barcode* between these scalar functions is non-empty for $H_0$, see Figure 3, (f). The visualization technique correctly points at places with different topology - the centers and borders of the distinguishing local minima.

**Lattices in 2D.** Next, we compare two lattice-style 2D scalar functions, see Figure 4, (a), (b). Lattices have defects in different places (top left and bottom right respectively). The persistence barcodes of both lattices are identical, see Figure 4, (d), (e): they contain 8 segments from $H_1$ corresponding to independent cycles. At the same time, *F-Cross-Barcode* between two scalar functions is non-empty, see Figure 4, (f). The visualization technique correctly points at places with defects.

**Concentric spheres in 3D.** Finally, we study the performance of the proposed method by comparing 3D scalar functions. We compare two scalar functions,
<figure><img src="image_5.png" /><figcaption>Fig. 4: Two scalar functions (a), (b) are indistinguishable by their persistence barcodes (c), (d). At the same time, $SFTD_1(f_1, f_2) = 1$, see (e).</figcaption></figure>

which equal $-1$ in a vicinity of two concentric spheres and a bridge connecting them, which is depicted in green. The bridge is located in different places (above or below of the smallest sphere). In other areas of space, the scalar functions equal 0. We sample a $32^3$ grid from the unit cube, see Figure 5 (a), (b) and compare functions restricted on this grid via *F-Cross-Barcode*. Again, regular persistence barcodes of two spheres with bridges are the same, see Figure 5, (d), (e): they contain 2 segments from $H_2$ corresponding to two cavities. But *F-Cross-Barcode* is non-empty, see Figure 5, (f). The visualization technique correctly highlights areas with topological differences, see Figure 5 (c), where the central vertical slice is shown.

## 5.2 Comparing Eigenvectors of Graph Laplacian

In the most general form, the proposed tools can compare scalar functions $f: \mathcal{V} \to \mathbb{R}$ defined on vertices $\mathcal{V}$ of an undirected graph $\mathcal{G} = (\mathcal{V}, \mathcal{E})$. The normalized graph Laplacian is the matrix $L = D^{-1/2}(D - A)D^{-1/2}$ where $A$ is an adjacency matrix and $D$ is a diagonal matrix of node degrees. Eigenvectors $e_i$ and eigenvalues $\lambda_i$ of $L$ describe intrinsic properties of the graph $\mathcal{G}$. Eigenvectors can be considered as scalar functions defined on graph's vertices $\mathcal{V}$. For eigenvectors: $(e_i, e_j) = 0$ and their norm is not defined; one can put $||e_i|| = 1$ for convenience. Thus, $e_i$ can't be distinguished by Euclidean distance or cosine distance. Alternatively, we can study $e_i$ as functions on vertices and compare them via SFTD.

We consider a random graph with 30 nodes, see Figure 6. Figure 7 presents symmetrized $\sum_{k=0,1} \text{SFTD}_k(e_i, e_j)$ via a heatmap, where $e_i, e_j$ are graph Laplacian eigenvectors ordered by eigenvalues. We observed the following interesting patterns: block structure, high topological similarity in the top left block, low
<figure><img src="image_6.png" /><figcaption>**Fig. 5:** Two scalar fields (a), (b) are indistinguishable by their persistence barcodes (d), (e). At the same time, $SFTD_1(f_1, f_2) = 1$, see (f).</figcaption></figure>

<table><caption>**Table 1:** Errors of 3D shape reconstruction for “Red blood cell” dataset.</caption><thead><tr><th>METHOD</th><th>1-IoU</th><th>VOLUME</th><th>SURFACE</th><th>ROUGH.</th><th>H<sub>0</sub></th><th>H<sub>1</sub></th><th>H<sub>2</sub></th></tr></thead><tbody><tr><td>SHAPR [37]</td><td>0.487</td><td>0.353</td><td>0.243</td><td>0.361</td><td>0.098</td><td>0.241</td><td>0.065</td></tr><tr><td>SHAPR+W.D. [36]</td><td>0.467</td><td>0.291</td><td>0.184</td><td>0.294</td><td>0.098</td><td>0.228</td><td>0.032</td></tr><tr><td>SHAPR+∑<sub>i=0,1,2</sub>SFTD<sub>i</sub></td><td><u>0.449</u></td><td>0.294</td><td><b>0.176</b></td><td>0.282</td><td><b>0.079</b></td><td>0.222</td><td>0.065</td></tr><tr><td>SHAPR+∑<sub>i=0,1,2,3</sub>SFTD<sub>i</sub></td><td>0.453</td><td><u>0.266</u></td><td>0.189</td><td><b>0.276</b></td><td><b>0.079</b></td><td><b>0.217</b></td><td><u>0.025</u></td></tr></tbody></table>

topological similarity in the bottom right block, and very interesting diagonal lines parallel to the main diagonal. Figure 8 shows two the most similar eigenvectors, Figure 9 - two the most dissimilar ones, while their *F-Cross-Barcodes* are shown on the right.

## 5.3 Enhancing 3D reconstruction

SHAPR (SHApe PRediction) [37] is a deep learning model for reconstructing cellular and nuclear 3D shapes from 2D fluorescence microscopy images. Correct reconstruction of structural patterns in 3D shapes is critical for this problem. However, such information is not captured by established pixel/voxel-wise loss terms, e.g. Dice loss. Later, [36] improved SHAPR by adding contextual information about the overall shape of an object. The work [36] proposed to augment SHAPR with a topological loss term - a Wasserstein-2 distance (W.D.) between
<figure><img src="image_7.png" /><figcaption>**Fig. 6:** A random Watts-Strogatz small-world graph [38] with 30 nodes.</figcaption></figure>

<figure><img src="image_8.png" /><figcaption>**Fig. 7:** Comparison of graph Laplacian eigenvectors via SFTD.</figcaption></figure>

<figure><img src="image_9.png" /><figcaption>(a) Eigenvector 1.</figcaption></figure>

<figure><img src="image_10.png" /><figcaption>(b) Eigenvector 4.</figcaption></figure>

<figure><img src="image_11.png" /><figcaption>(c) F-Cross-Barcode($e_1, e_4$).</figcaption></figure>

<figure><img src="image_12.png" /><figcaption>(d) F-Cross-Barcode($e_4, e_1$).</figcaption></figure>

<figure><img src="image_13.png" /><figcaption>(a) Eigenvector 0.</figcaption></figure>

<figure><img src="image_14.png" /><figcaption>(b) Eigenvector 22.</figcaption></figure>

<figure><img src="image_15.png" /><figcaption>(c) F-Cross-Barcode($e_0, e_{22}$).</figcaption></figure>

<figure><img src="image_16.png" /><figcaption>(d) F-Cross-Barcode($e_{22}, e_0$).</figcaption></figure>

<caption>**Fig. 9:** Comparison of $e_0$ and $e_{22}$.</caption>

<table><caption>**Table 2:** Errors of 3D shape reconstruction for “Cell nuclei” dataset.</caption><thead><tr><th>METHOD</th><th>1-IoU</th><th>VOLUME</th><th>SURFACE</th><th>ROUGH.</th><th>H<sub>0</sub></th><th>H<sub>1</sub></th><th>H<sub>2</sub></th></tr></thead><tbody><tr><td>SHAPR [37]</td><td>0.612</td><td>0.482</td><td>0.273</td><td>0.191</td><td><strong>0.000</strong></td><td><strong>0.007</strong></td><td>0.038</td></tr><tr><td>SHAPR+W.D. [36]</td><td>0.612</td><td>0.437</td><td>0.251</td><td>0.200</td><td><strong>0.000</strong></td><td>0.008</td><td>0.027</td></tr><tr><td>SHAPR+∑<sub>i=0,1,2</sub>SFTD<sub>i</sub></td><td>0.618</td><td><strong>0.432</strong></td><td><strong>0.244</strong></td><td><strong>0.187</strong></td><td><strong>0.000</strong></td><td>0.008</td><td>0.020</td></tr><tr><td>SHAPR+∑<sub>i=0,1,2,3</sub>SFTD<sub>i</sub></td><td>0.437</td><td>0.247</td><td>0.191</td><td><strong>0.000</strong></td><td>0.011</td><td><strong>0.011</strong></td><td></td></tr></tbody></table>
persistence barcodes of ground truth and predicted 3D objects and a total persis-
tence. However, as we discussed before, this loss term doesn't take into account
the localization of topological features. We replaced the topological loss term in
SHAPR with a symmetrized SFTD with $p = 2$ in two variants$^8$: dimensions up
to 2 and dimensions up to 3. Then, we carried out experiments with two datasets
from [37].

Table 1 shows experimental results for the “Red blood cell” dataset. We con-
clude that SHAPR augmented with the SFTD loss term is the best one in terms
of 3D shape matching errors : IoU error, volume error, surface error, and rough-
ness error (see details in [37]). Additionally, we calculated Wasserstein-2 dis-
tances between persistence barcodes ($H_0, H_1, H_2$) of ground truth and generated
3D objects. Statistically significant improvements are underlined. The proposed
SFTD topological loss term with 0-3 dimensions has the lowest Wasserstein-2
distances. This is the rare case of an application of higher homologies like $H_3$
for real-world applications.

For the “Cell nuclei” dataset results are presented in Table 2. Differences are
quite small and are statistically significant only for two metrics: IoU error and
W.D. $H_2$, where SHAPR with SFTD loss is the best model.

Figure 10 shows 3D visualizations of 2D → 3D reconstructions. We see that even with the topological regularization from [36], 3D reconstructions are sometimes erroneous and have serious topological defects: cavities, holes, and surface breaks. In experiments, the sublevel filtration was used and a density function equaled “1” inside the object and “0” in the ambient space. That is, a cavity inside a sphere corresponds to an extra bar in $H_0$ barcode, an extra connected component corresponds to an extra bar in $H_2$ barcode.

5.4 Identifying topological errors in 3D segmentation

Brain tumor 3D segmentation aims to reveal the sub-regions of tumor corre-
sponding to the enhancing tumor, the edematous/invaded tissue, the necrosis.
Availability of versatile similarity measures not only allows precise evaluation
of deep learning 3D segmentation models, but also assists monitoring disease
progression in clinical practice. As mentioned above, measuring the similarity
of the two 3D segmentations by comparing their persistence barcodes does not
account for localization of the topological features. In this section, we illustrate
the ability of SFTD to complement the existing metrics with this additional
information.

In order to investigate the applicability of the proposed SFTD as a metric
for 3D segmentation, we utilize the publicly available pretrained Swin UNETR
model [21,33] and BraTS 21 dataset [2–4,28]. Figures 11a, 11b demonstrate the
ground truth segmentation and model’s prediction. While each of these two 3D
segmentations has two voids inside, only two voids have the same localization

<footnote n="8">⁸ A 3D cubical complex has empty $H_3$ homologies. But during the calculation of SFTD for 3D scalar functions, a 4D cubical complex is created, where $H_3$ homologies can exist.</footnote>
<figure><img src="image_17.png" /><figcaption>**Fig. 10:** Examples of topological errors. Top, $H_0$: SHAPR+W.D. has a wrong cavity inside. Middle, $H_1$: SHAPR+W.D. has a wrong hole. Bottom, $H_2$: SHAPR+W.D. has a wrong surface break.</figcaption></figure>
<figure><img src="image_18.png" /><figcaption>**Fig. 11:** Examples of topological errors. Two 3D segmentations - (a) - ground truth and (b) - prediction - are indistinguishable by their persistence barcodes (c), (d). At the same time, SFTD between ground truth and prediction equals to 1, see (e). A pair of points inside each object in (a), (b) corresponds to the dissimilar topological features, voids, where birth/death events are depicted by red/green dots.</figcaption></figure>

which makes the two 3D segmentations different. As shown in Figures 11c, 11d, the two 3D segmentations are indistinguishable by their persistence barcodes. In contrary, SFTD is able to recognise the difference between these two cases as revealed by the F-Cross-Barcode in Figure 11e. In particular, SFTD indicates that the difference is precisely in locations of one pair of voids since the set of 1-dimensional topological features contains one segment.

# 6 Conclusions

In this paper, we have proposed new topological tools: F-Cross-Barcode and Scalar Function Topology Divergence (SFTD), which measure the dissimilarity of multi-scale topology between sublevel sets of two functions having a common domain. Functions can be defined on an undirected graph or Euclidean space of any dimensionality. We have shown that our tools outperform the standard approach: evaluating Wasserstein distance between persistence barcodes, calculated independently for sublevel sets of scalar functions. F-Cross-Barcode and SFTD take into account the localization of topological features. SFTD, as a loss function, is beneficial in computer vision, since it helps to enforce topological similarity at multiple scales. Also, the proposed tools provide useful visualizations of areas of topological dissimilarities. In the experimental section, we demonstrated that SFTD improved the reconstruction of cellular 3D shapes from 2D fluorescence microscopy images and identified topological errors in 3D segmentation. Additionally, we showed that SFTD outperforms Betti matching loss in 2D segmentation problems. We believe that the proposed tools will have more applications in computer vision and learning from graph data.
Acknowledgements

The work was supported by the Analytical center under the RF Government
(subsidy agreement 000000D730321P5Q0002, Grant No. 70-2021-00145 02.11.2021)

References

1. Abousamra, S., Hoai, M., Samaras, D., Chen, C.: Localization in the crowd with topological constraints. In: Proceedings of the AAAI Conference on Artificial Intelligence. vol. 35, pp. 872–881 (2021)

2. Baid, Ujjwal, e.a.: The rsna-asnr-miccai brats 2021 benchmark on brain tumor segmentation and radiogenomic classification. arXiv preprint arXiv:2107.02314 (2021)

3. Bakas, S., Akbari, H., Sotiras, A., Bilello, M., Rozycki, M., Kirby, J.S., Freymann, J.B., Farahani, K., Davatzikos, C.: Advancing the cancer genome atlas glioma mri collections with expert segmentation labels and radiomic features. Nature Scientific Data (2017)

4. Bakas, S., Akbari, H., Sotiras, A., Bilello, M., Rozycki, M., Kirby, J.S., Freymann, J.B., Farahani, K., Davatzikos, C.: Segmentation labels and radiomic features for the pre-operative scans of the tcga-gbm collection. The Cancer Imaging Archive (2017)

5. Barannikov, S.: The framed Morse complex and its invariants. Advances in Soviet Mathematics **21**, 93–116 (1994)

6. Barannikov, S., Korotin, A., Oganesyan, D., Emtsev, D., Burnaev, E.: Barcodes as summary of loss function topology. Doklady Rossijskoj akademii nauk. Matematika, informatika, processy upravleniâ **514**(2), 196–211 (2023)

7. Barannikov, S., Trofimov, I., Balabin, N., Burnaev, E.: Representation topology divergence: A method for comparing neural network representations. ICML 2022, arXiv:2201.00058 (2021)

8. Barannikov, S., Trofimov, I., Sotnikov, G., Trimbach, E., Korotin, A., Filippov, A., Burnaev, E.: Manifold topology divergence: a framework for comparing data manifolds. Advances in Neural Information Processing Systems **34**, 7294–7305 (2021)

9. Barannikov, S., Voronkova, D., Trofimov, I., Korotin, A., Sotnikov, G., Burnaev, E.: Topological obstructions in neural networks learning. arXiv preprint arXiv:2012.15834 (2020)

10. Carpenter, A.E., Jones, T.R., Lamprecht, M.R., Clarke, C., Kang, I.H., Friman, O., Guertin, D.A., Chang, J.H., Lindquist, R.A., Moffat, J., et al.: Cellprofiler: image analysis software for identifying and quantifying cell phenotypes. Genome biology **7**, 1–11 (2006)

11. Carrière, M., Chazal, F., Glisse, M., Ike, Y., Kannan, H., Umeda, Y.: Optimizing persistent homology based functions. In: International Conference on Machine Learning. pp. 1294–1303. PMLR (2021)

12. Carrière, M., Chazal, F., Ike, Y., Lacombe, T., Royer, M., Umeda, Y.: Perslay: A neural network layer for persistence diagrams and new graph topological signatures. In: International Conference on Artificial Intelligence and Statistics. pp. 2786–2796. PMLR (2020)

13. Chazal, F., Michel, B.: An introduction to topological data analysis: fundamental and practical aspects for data scientists. arXiv preprint arXiv:1710.04019 (2017)

14. Chen, Y., Segovia, I., Gel, Y.R.: Z-gcnets: Time zigzags at graph convolutional networks for time series forecasting. In: International Conference on Machine Learning. pp. 1684–1694. PMLR (2021)
15. Chen, Y., Segovia Dominguez, I., Coskunuzer, B., Gel, Y.: Tamp-s2gcnets: When time-aware multipersistence meets spatio-supra graph convolutional nets while forecasting time series. In: The International Conference on Learning Representations (ICLR) (2022)

16. Demir, A., Coskunuzer, B., Gel, Y., Segovia-Dominguez, I., Chen, Y., Kiziltan, B.: Todd: Topological compound fingerprinting in computer-aided drug discovery. Advances in Neural Information Processing Systems 35, 27978-27993 (2022)

17. Funke, J., Tschopp, F., Grisaitis, W., Sheridan, A., Singh, C., Saalfeld, S., Turaga, S.C.: Large scale image segmentation with structured loss based deep learning for connectome reconstruction. IEEE transactions on pattern analysis and machine intelligence 41(7), 1669-1680 (2018)

18. Gelfand, S.I., Manin, Y.I.: Methods of homological algebra. Springer Science & Business Media (2002)

19. Gupta, S., Hu, X., Kaan, J., Jin, M., Mpoy, M., Chung, K., Singh, G., Saltz, M., Kurc, T., Saltz, J., et al.: Learning topological interactions for multi-class medical image segmentation. In: European Conference on Computer Vision. pp. 701-718. Springer (2022)

20. Gupta, S., Zhang, Y., Hu, X., Prasanna, P., Chen, C.: Topology-aware uncertainty for image segmentation. Advances in Neural Information Processing Systems 36 (2024)

21. Hatamizadeh, A., Nath, V., Tang, Y., Yang, D., Roth, H.R., Xu, D.: Swin unetr: Swin transformers for semantic segmentation of brain tumors in mri images. arXiv preprint arXiv:2201.01266v1 (2022)

22. Hofer, C., Graf, F., Rieck, B., Niethammer, M., Kwitt, R.: Graph filtration learning. In: International Conference on Machine Learning. pp. 4314-4323. PMLR (2020)

23. Horn, M., De Brouwer, E., Moor, M., Moreau, Y., Rieck, B., Borgwardt, K.: Topological graph neural networks. arXiv preprint arXiv:2102.07835 (2021)

24. Hu, X., Li, F., Samaras, D., Chen, C.: Topology-preserving deep image segmentation. Advances in neural information processing systems 32 (2019)

25. Hu, X., Wang, Y., Fuxin, L., Samaras, D., Chen, C.: Topology-aware segmentation using discrete morse theory. arXiv preprint arXiv:2103.09992 (2021)

26. Kaczynski, T., Mischaikow, K.M., Mrozek, M.: Computational homology, vol. 3. Springer (2004)

27. Luo, Y., Shi, L., Thost, V.: Improving self-supervised molecular representation learning using persistent homology. arXiv preprint arXiv:2311.17327 (2023)

28. Menze, B.H., Jakab, A., Bauer, S., Kalpathy-Cramer, J., Farahani, K., Kirby, Justin, e.a.: The multimodal brain tumor image segmentation benchmark (brats). IEEE Transactions on Medical Imaging (2015)

29. Moor, M., Horn, M., Rieck, B., Borgwardt, K.: Topological autoencoders. In: International conference on machine learning. pp. 7045-7054. PMLR (2020)

30. Pérez, J.B., Hauke, S., Lupo, U., Caorsi, M., Dassatti, A.: giotto-ph: A python library for high-performance computation of persistent homology of vietoris-rips filtrations (2021)

31. Ronneberger, O., Fischer, P., Brox, T.: U-net: Convolutional networks for biomedical image segmentation. In: Medical Image Computing and Computer-Assisted Intervention-MICCAI 2015: 18th International Conference, Munich, Germany, October 5-9, 2015, Proceedings, Part III 18. pp. 234-241. Springer (2015)

32. Stucki, N., Paetzold, J.C., Shit, S., Menze, B., Bauer, U.: Topologically faithful image segmentation via induced matching of persistence barcodes. In: International Conference on Machine Learning. pp. 32698-32727. PMLR (2023)
33. Tang, Y., Yang, D., Li, W., Roth, H.R., Landman, B., Xu, D., Nath, V., Hatamizadeh, A.: Self-supervised pre-training of swin transformers for 3d medical image analysis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (2022)

34. Trofimov, I., Cherniavskii, D., Tulchinskii, E., Balabin, N., Burnaev, E., Baran-nikov, S.: Learning topology-preserving data representations. arXiv preprint arXiv:2302.00136 (2023)

35. Wagner, H., Chen, C., Vuçini, E.: Efficient computation of persistent homology for cubical data. In: Topological methods in data analysis and visualization II: theory, algorithms, and applications, pp. 91–106. Springer (2011)

36. Waibel, D.J., Atwell, S., Meier, M., Marr, C., Rieck, B.: Capturing shape information with multi-scale topological loss terms for 3d reconstruction. In: International Conference on Medical Image Computing and Computer-Assisted Intervention. pp. 150–159. Springer (2022)

37. Waibel, D.J., Kiermeyer, N., Atwell, S., Sadafi, A., Meier, M., Marr, C.: Shapr predicts 3d cell shapes from 2d microscopic images. Iscience 25(11) (2022)

38. Watts, D.J., Strogatz, S.H.: Collective dynamics of ‘small-world’networks. nature 393(6684), 440–442 (1998)

39. Wu, J., Wang, Y., Xue, T., Sun, X., Freeman, B., Tenenbaum, J.: Marrnet: 3d shape reconstruction via 2.5 d sketches. Advances in neural information processing systems 30 (2017)

40. Yan, Z., Ma, T., Gao, L., Tang, Z., Chen, C.: Link prediction with persistent homology: An interactive view. In: International conference on machine learning. pp. 11659–11669. PMLR (2021)
A Proof of SFTD basic properties

**Proposition 3. (SFTD Stability)** For any scalar functions f, f', g, g' on a grid, or on a graph vertex set:

$$
d_B(F\text{-}Cross\text{-}Barcode_k(f, g), F\text{-}Cross\text{-}Barcode_k(f', g')) \le \\
\max(\max_i|f(i) - f'(i)|, \max_i|g(i) - g'(i)|). \quad (5)
$$

Here $d_B$ denotes the bottleneck distance between persistence barcodes [13].

Proof. The proof is parallel in the simplicial and in the cubical cases. By con-
struction, F-Cross-Barcode$_k(f,g)$, F-Cross-Barcode$_k(f',g')$ are the $k$-th persis-
tence barcodes of the lower-star filtrations induced by the functions $\tilde{f}, \tilde{f}'$ on the
doubled graph $\tilde{\mathcal{G}}$ from section 4.1. If $\max(\max_i|f(i)-f'(i)|, \max_i|g(i)-g'(i)|) =
\varepsilon$, then $\max_{j \in \tilde{V}}|\tilde{f}(j)-\tilde{f}'(j)| \le \varepsilon$. Hence the filtration of each simplex in the lower
star filtration induced by $\tilde{f}$ on $\tilde{\mathcal{G}}$ changes at most by $\varepsilon$ under the perturbation
$\tilde{f}'$. It follows from e.g. the description of metamorphoses of canonical forms in [5]
that the birth or the death of each segment in the $k$-th barcode of $\tilde{\mathcal{G}}$ changes
under such perturbation at most by $\varepsilon$.

**Proposition 4.** For any scalar functions f, f':

$$
\| F\text{-}Cross\text{-}Barcode_k(f, f') \|_B \le \max_i |f(i) - f'(i)|.
$$

Proof. Apply equation (5) with $g = g' = f'$.

Let $C^{f \le \alpha}(\mathcal{G})$ denotes the simplicial (cubical) subcomplex of the simplicial (cubical) complex associated with graph (lattice) $\mathcal{G}$, containing all simplices (cells) on which $f \le \alpha$. The proof of proposition 1 follows from the exactness of the sequence in equation 6 below.

**Theorem 1.** *F-Cross-Barcode*<sub>*k*</sub>(*f*, *g*) *has the following properties:*

- if $f(i) = g(i)$ for any $i \in \mathcal{V}$, then $F\text{-}Cross\text{-}Barcode_k(f,g) = \emptyset$ for any $k \ge 0$;

- if $g(i) = \min_{j \in \mathcal{V}} f(j)$ for any $i$, then for all $k \ge 0$: $F\text{-}Cross\text{-}Barcode_{k+1}(f,g) = \text{Barcode}_k(f)$ the standard barcode of the lower star filtration induced by $f$ on graph $\mathcal{G}$;

- for any value of threshold $\alpha$, the following sequence of natural linear maps of
  homology groups

$$
\begin{align*}
\xrightarrow{r_{3i+3}} H_i(C^{f \le \alpha}(\mathcal{G})) &\xrightarrow{r_{3i+2}} H_i(C^{\min(f,g) \le \alpha}(\mathcal{G})) \xrightarrow{r_{3i+1}} \\
\xrightarrow{r_{3i+1}} H_i(C^{\tilde{f} \le \alpha}(\tilde{\mathcal{G}})) &\xrightarrow{r_{3i}} H_{i-1}(C^{f \le \alpha}(\mathcal{G})) \xrightarrow{r_{3i-1}} \dots \\
\dots \xrightarrow{r_1} H_0(C^{f \le \alpha}(\mathcal{G})) &\xrightarrow{r_0} H_0(C^{\min(f,g) \le \alpha}(\mathcal{G})) \xrightarrow{r_{-1}} H_0(C^{\tilde{f} \le \alpha}(\tilde{\mathcal{G}})) \xrightarrow{r_{-2}} 0 \quad (6)
\end{align*}
$$

is exact, i.e. for any j the kernel of the map r_j is the image of the map r_{j+1}.
*Proof.* The proof of the first two properties is immediate from the definition of F-Cross-Barcode$_k(f,g)$. The proof of the third property follows from the proposition 5.

**Proposition 5.** The embeddings of graphs $G^{f \le \alpha} \subseteq G^{\min(f,g) \le \alpha} \subset \tilde{G}^{f \le \alpha}$ give distinguished triangles, see [18], in the homotopy category of chain complexes:

$$C^{f \le \alpha}(\mathcal{G}) \to C^{\min(f,g) \le \alpha}(\mathcal{G}) \to C^{\tilde{f} \le \alpha}(\tilde{\mathcal{G}}) \to C^{f \le \alpha}(\mathcal{G})[-1]. \quad (7)$$

*Proof.* The proof is parallel to the proof of proposition A.3 from [7].

# B Connection to Representation Topology Divergence

Representation Topology Divergence (RTD) [7] is a tool to compare two representations $R_1, R_2$ of some set of objects $\mathcal{V}$. RTD measures the dissimilarity in multi-scale topology between two point clouds of equal size with a one-to-one correspondence. Here we establish connections between SFTD and RTD and highlight differences.

A unified view of SFTD and RTD involves two elements:

1. calculating a persistence barcode of a filtered simplicial complex derived from the double graph $\tilde{\mathcal{G}}$, see Fig. 2a;

2. usage of a specific filtration function $T: C(\tilde{\mathcal{G}}) \to \mathbb{R}$.

Theoretically, the only restriction for $T$ is that $T(C_1) \le T(C_2)$ when $C_1 \subseteq C_2$. For SFTD, the filtration function $T$ is defined in vertices by a vertex function $\tilde{f}$ (see Section 4) and extended to the rest of simplices by a formula $T(C) = \max_{v \in C} \tilde{f}(v)$. While for RTD, $T(C)$ conforms to the Vietoris-Rips filtration with distance-like weights and is defined on vertices and edges as follows:

$$ \begin{align*} T(A_i) &= T(A_j) = T(O) = 0 \\ T(A'_i, A'_j) &= \min(\mathrm{dist}(R_1(i), R_1(j)), \mathrm{dist}(R_2(i), R_2(j))), \\ T(A_i, A'_j) &= T(A_i, A_j) = \mathrm{dist}(R_1(i), R_1(j)), \\ T(A_i, A'_i) &= T(O, A_i) = 0. \end{align*} $$

Here, for two objects $i, j \in \mathcal{V}$ we have their representations $R_1(i), R_2(i)$ and a distance function $\mathrm{dist}(R_1(i), R_2(i))$. For the rest of the simplices, the filtration function is extended by a formula $T(C) = \max_{v_1, v_2 \in C, (v_1, v_2) \in \tilde{\mathcal{E}}} T((v_1, v_2))$.

# C Computational complexity of SFTD

The dominating step in SFTD computation is an evaluation of a persistence barcode. Generally, it is at worst cubic in the number of cubes/simplexes involved. In practice, the computation is faster since the boundary matrix is typically sparse for real datasets. SFTD for $512^2$ or $64^3$ lattices can be calculated in seconds.
## D Details on the experiment with SHAPR

For experiments, we used the official repository<fnref n="9" />. We closely followed the official pipeline and trained with the loss: $\mathcal{L}_{SHAPR} + \lambda \cdot \text{SFTD}$, where $\lambda$ was selected from the set {1.0, 0.5, 0.25, 0.125, 0.06} by Dice error on cross-validation. For baselines (SHAPR, SHAPR+W.D.) we used predictions from a zip-archive from the official repository.

## E Details on the experiment with 3D segmentation

For experiments, we used the repository<fnref n="10" /> with the implementation of Swin UN-ETR model pretrained on BraTS21 dataset of the MONAI Project framework <fnref n="11" />. The ground truth and predicted segmentations have three channels corresponding to NCR, ED, ET parts of tumor. In the experiments, we analyze and visualize the segmentations corresponding to each channel separately. To visualize the distinctive topological features provided by F-Cross-Barcode, we separately compute SFTD between ground truth and predicted segmentations and vice versa. Topological features provided by SFTD between the ground truth and prediction are depicted in the ground truth segmentation while SFTD between the prediction and ground truth are depicted in the predicted segmentation. In each example, the object's voxels have values of 1 while the background's voxels have values of 0. In the visualizations of the persistence barcodes and F-Cross-Barcodes, we omit the infinite half-line in $H_0$ for the ease of perception.

## F Additional results for 3D segmentation

In this section, we provide additional examples of topological errors between the ground truth and predicted 3D segmentations, see Figures 12, 13. The predicted segmentations in figures 12b, 13b have incorrect localization of clusters compared to the ground truth in figures 12a, 13a. In both cases, this difference is indistinguishable by persistence barcodes (see figures 12c, 12d, 13c, 13d) but is revealed by the F-Cross-Barcodes (see figures 12e, 13e).

## G Additional experiments for 2D segmentation

In 2D segmentation, optimizing loss functions based on pixel-overlap is often insufficient to capture the correct topology of segmented objects. Betti matching [32] is a topological metric and loss function for supervised image segmentation. When used as a loss function, Betti matching improves topological performance of segmentation models while preserving the volumetric quality.

<footnote n="9">⁹ https://github.com/marrlab/SHAPR_torch</footnote>

<footnote n="10">¹⁰ https://github.com/Project-MONAI/research-contributions/tree/main/SwinUNETR/BRATS21</footnote>

<footnote n="11">¹¹ https://github.com/Project-MONAI</footnote>
<figure><img src="image_19.png" /><figcaption>**Fig. 12:** Examples of topological errors in 3D segmentation. Predicted segmentation (b) has incorrect localization of one cluster compared to the ground truth (a). This difference is indistinguishable by persistence barcodes (c), (d) but is revealed by F-Cross-Barcode (e).</figcaption></figure>

<figure><img src="image_20.png" /><figcaption>**Fig. 13:** Examples of topological errors in 3D segmentation. The ground truth segmentation (a) has a tiny cluster that is incorrectly predicted by the model (b). This difference is indistinguishable by persistence barcodes (c), (d) but is revealed by F-Cross-Barcode (e).</figcaption></figure>
We strictly followed the experimental setup from [32] to compare SFTD with Betti matching loss on CREMI [17] and colon cancer cell (Colon) [10] datasets. We replaced the topological loss term in Betti matching with SFTD with $p = 2$ in up to 2 dimensions. Table 3 provides experimental results. Our method has similar segmentation quality (Dice, clDice, accuracy) and lower topological errors ($\tau^{\text{err}}$, $\beta^{\text{err}}$) - up to 35%. Also, evaluation of SFTD loss is ~ 35 times faster than Betti matching loss.

<table><caption>**Table 3:** Errors of 2D segmentation for CREMI and Colon datasets.</caption><thead><tr><th>METHOD</th><th>DICE ↑ CLDICE ↑ ACC. ↑ τ<sup>ERR</sup> ↓ β<sup>ERR</sup> ↓</th><th colspan="6">CREMI DATASET [17]</th></tr></thead><tbody><tr><td>BETTI MATCHING [32]</td><td>0.893</td><td>0.941</td><td>0.959</td><td>129.80</td><td>79.16</td><td></td><td></td></tr><tr><td>SFTD</td><td>0.885</td><td>0.941</td><td>0.955</td><td>126.48</td><td>62.64</td><td></td><td></td></tr><tr><td colspan="8">COLON DATASET [10]</td></tr><tr><td>BETTI MATCHING [32]</td><td>0.907</td><td>0.871</td><td>0.975</td><td>32.00</td><td>21.50</td><td></td><td></td></tr><tr><td>SFTD</td><td>0.901</td><td>0.889</td><td>0.971</td><td>21.50</td><td>14.00</td><td></td><td></td></tr></tbody></table>