Keywords

1 Introduction

figure a

The minimum barrier (MB) distance [20] is defined as the minimal interval of gray-level values in an image along a path between two points.

For instance, the image of Fig. 1(a) can be seen as a graph depicted in Fig. 1(b), and the path between the red points which is depicted in blue is minimal: the sequence of values is \(\langle 1,0,0,0,2 \rangle \) so the interval is [0, 2] and the distance is 2. Note that, in general, for an image and a couple of points, many minimal paths exist (here the straight path with the sequence of values \(\langle 1,3,2 \rangle \) gives the interval [1, 3], which also gives the MB distance of 2). If we consider that the discrete function describes a surface such as the one of Fig. 1(c), the blue path depicted in this figure is such that the MB-like distance between the two red dots is now 1. This paper elaborates on how to define properly this variant of the MB distance which considers that the elevation map is a continuous function.

Fig. 1.
figure 1

Two different minimal barrier distances: (b) gives 2, while (c) gives 1. (Color figure online)

The MB distance is interesting for several reasons. First, it is an “original” distance which contrasts with classical path-length distances, because it only relies on the dynamics of the function. Second, it has already successfully been applied to perform salient object segmentation [21, 25]. Last, as we will see, its continuous version presented here is related to mathematical morphology. In the example of Fig. 1(c), considering an image as a landscape, we can see that a path can be defined on a steep hillside. We thus have decided to name this particular distance after the legendary (or not [18]) Dahu creature: a mountain goat-like animal with legs of different sides having differing lengths to fit the craggy mountain’s side.

To be able to define this continuous version of the MB distance, and to show how to compute it efficiently, we will rely on several tools: set-valued maps, cubical complexes, and the morphological tree of shapes (ToS for short), described in Sect. 2. In Sect. 3, we will start by giving a naive definition of this distance; we will see that it raises some digital topology issue, and we will propose a definition (closely related to the discrete set-valued continuity setting [17]) that overcomes this issue.

Although the definition of the Dahu distance is highly combinatorial, we will see in Sect. 4 that this distance can be efficiently computed thanks to the tree of shapes of an interval-valued map. A remarkable property is that we can efficiently compute the exact distance, whereas the only efficient computation of the MB distance remains approximate. We also illustrate the use of the Dahu distance on document image segmentation in Sect. 4.3.

Actually, this paper mainly focus on the new distance definition, on the discrete topology issues related to this distance, and on a method to compute it efficiently. These three subjects are the main contributions detailed hereafterFootnote 1.

2 Theoretical Background

This section gives a short tour on the theoretical tools needed in Sects. 3 and 4.

2.1 Basic Notions

Let us consider a discrete finite set X. The set of all subsets of X is denoted by \({\mathcal {P}} (X)\), so \(E \in {\mathcal {P}} (X)\) means \(E \subseteq X\). X is endowed with a discrete neighborhood relation; the set of neighbors of \(x \in X\) is denoted by \({\mathcal {N}} _X(x) \subset X\), and satisfies: \(x' \in {\mathcal {N}} _X(x)\) iff \(x' \ne x\) and \(x \in {\mathcal {N}} _X(x')\).

A discrete path \(\pi \) of X is a sequence \(\pi = \langle \pi _1,..,\pi _i,..,\pi _k\rangle \), where k is the length of the sequence, such as \(\pi _i \in X\) and \(\pi _{i+1} \in {\mathcal {N}} _X(\pi _i)\). A sequence \(\langle x,..,x'\rangle \) is called a path between x and \(x'\); the set of all paths between x and \(x'\) is denoted by \(\varPi (x,x')\), and we use \(\pi (x,x')\) to denote an element of \(\varPi (x,x')\).

A connected component \(\varGamma \) of \(E \subset X\) is a subset of E which is path-connected (\(\forall \, x \ne x' \in \varGamma ,\, \varPi (x,x') \ne \emptyset \)) and maximal (\(\forall \, x \in \varGamma ,\, \forall \, x' \in E\!\setminus \!\varGamma ,\, \varPi (x,x') = \emptyset \)). The set of the connected components of E is denoted by \(\mathcal {CC} (E)\), and given \(x \in X\), the connected component of E containing x is denoted by \({\mathcal {C}} (E,x) \in \mathcal {CC} (E)\)—by convention, if \(x \not \in E\) then \({\mathcal {C}} (E,x)=\emptyset \). Given a particular element \(x_\infty \in X\), the cavity-fill-in operator (in 2D, hole-filling operator) is denoted by \(\mathrm {Sat}\) and defined by: \(\mathrm {Sat} (E, x_\infty ) = X \setminus \, {\mathcal {C}} (X\!\setminus \! E,\, x_\infty )\).

Throughout this paper, we will only consider functions having for domain a set X being discrete, finite, and path-connected.

2.2 Scalar vs. Set-Valued Maps

A gray-level image is typically a bounded scalar function such as X is a subset \({\mathcal {D}} \subset {\mathbb {Z}} ^n\) with \(n \ge 2\), and its codomain is \({\mathbb {Z}} \) or \({\mathbb {R}} \). It is the case of the image depicted in Fig. 1(a). Now, if we look at the surface of Fig. 1(c), its elevation cannot be defined by a scalar function. Yet it can be a mapping in \({\mathbb {R}} ^2 \rightarrow {\mathbb {I}} _{\mathbb {R}} \), where \({\mathbb {I}} _Y\) denotes the space of the intervals of Y. Given two intervals \(a=[y_a,y'_a]\) and \(b=[y_b,y'_b]\), the interval \([\min (y_a,y_b),\max (y'_a,y'_b)]\) is denoted by \(\mathrm {span} \{a,b\}\). Now let us recall some definitions related to set-valued maps.

A set-valued map \(\, \textsc {u}: X \rightarrow {\mathcal {P}} (Y)\,\) is characterized by its graph, \(\, \mathrm {Gra} (\textsc {u}) = \{ (x, y) \in X \times Y;\, y \in \textsc {u} (x) \}\) [1]. One definition of the inverse by a set-valued map \(\textsc {u} \) of a subset \(M \subset Y\) is \(\, \textsc {u} ^{\ominus }(M) = \{ x \in X;\, \textsc {u} (x) \subset M \}\), and it is called the core of M by \(\textsc {u} \). Let us assume that X and Y are metric spaces. The “natural” extension of the continuity of single-valued functions to set-valued maps is characterized by the following property: \(\textsc {u} \) is continuous iff the core of any open subset of Y is an open set of X.

In [14], the authors have defined the notion of level sets for set-valued maps; at \(\lambda \in Y\), the lower and upper level sets of \(\textsc {u} \) are respectively:

$$\begin{aligned}{}[\textsc {u} \lhd \lambda ] = \{ x \in X;\, \forall \, y \in \textsc {u} (x),\, y < \lambda \} \text { and } [\textsc {u} \rhd \lambda ] = \{ x \in X;\, \forall \, y \in \textsc {u} (x),\, y > \lambda \}. \end{aligned}$$
(1)

Such definitions are fundamental because they are some means to build some morphological tools on set-valued maps (we will use them later in this paper in Sects. 2.4 and 4.1).

A scalar function \(u : X \rightarrow Y\) can be simply translated into a set-valued map with . Between set-valued maps of \(X \rightarrow {\mathcal {P}} (Y)\) we can define the relation by: . By abuse of notation, we will write to state that , meaning that we have \(\forall \, x\in X,\, u(x) \in \textsc {u} (x)\). An illustration can be seen later: the map \({\overline{u}} \) of Fig. 3(d) and the map \(\widetilde{u} \) of Fig. 3(c) are such that . In the following, we will only consider interval-valued maps, that is, maps of \(X \rightarrow {\mathbb {I}} _Y\).

2.3 Cubical Complexes

From the sets \(\,H^1_0 = \{ \{a\};\, a \in {\mathbb {Z}} \}\,\) and \(\,H^1_1 = \{ \{a,a+1\};\, a \in {\mathbb {Z}} \}\), we can define \(\,{\mathbb {H}} ^1 = H^1_0 \cup H^1_1\,\) and the set \({\mathbb {H}} ^n \) as the n-ary Cartesian power of \({\mathbb {H}} ^1\). If an element \(h \subset {\mathbb {Z}} ^n\) is the Cartesian product of d elements of \(H^1_1\) and \(n - d\) elements of \(H^1_0\), we say that h is a d-face of \({\mathbb {H}} ^n \) and that d is the dimension of h; it is denoted \(\dim (h)\). The set of all faces, \({\mathbb {H}} ^n \), is called the nD space of cubical complexes. Figure 2(a) depicts a set of faces \(\{h,h',h''\} \subset {\mathbb {H}} ^2\) where \(h=\{0\} {} \times {} \{1\} \), \(h'=\{1\} {} \times {} \{0,1\} \), and \(h''=\{0,1\} {} \times {} \{0,1\} \), the dimension of these faces being respectively 0, 1, and 2; they are depicted as subsets of \({\mathbb {Z}} ^2\) (left) and as geometrical objects (right).

Fig. 2.
figure 2

A cubical complex for space X (left) and a tree of shapes for u (right). (Color figure online)

Fig. 3.
figure 3

From a gray-scale image (a) to a discrete but continuous representation (c). (Color figure online)

The pair \(({\mathbb {H}} ^n,\subseteq )\) forms a poset, from which can be derived a T0-Alexandroff topology on \({\mathbb {H}} ^n \). The closure operator on subsets of \({\mathbb {H}} ^n \) is denoted by \( cl \). The n-faces are the minimal open sets of \({\mathbb {H}} ^n \), and the set of n-faces, denoted by \(H^n_1\), is the n-Cartesian product of \(H_1\). The faces of \({\mathbb {H}} ^n \) can be arranged onto a grid, called Khalimsky’s grid, and the inclusion between faces leads to a neighborhood relationship between them, depicted in orange in Fig. 2(a) (right). This neighborhood relationship will be used in Sect. 3.2 in order to define paths in \({\mathbb {H}} ^n\).

2.4 Tree of Shapes

Given a gray-level image \(u : X \rightarrow Y\) and any scalar \(\lambda \in Y\), the lower level sets are defined as \(\,[u< \lambda ] = \{x \in X;\, u(x) < \lambda \},\) and the upper level sets as \(\,[u \ge \lambda ] = \{x \in X;\, u(x) \ge \lambda \}\). Considering the connected components of these sets, and using the cavity-fill-in operator, the tree of shapes (ToS) of an image u is classically [16] defined by:

$$\begin{aligned} {\mathfrak {S}} (u) \;=\; \{\, \mathrm {Sat} (\varGamma ) ;\; \varGamma \in \, \mathcal {CC} ([u < \lambda ]) \,\cup \, \mathcal {CC} ([u \ge \lambda ]) \,\}_\lambda . \end{aligned}$$
(2)

An image and its tree of shapes are depicted in Fig. 2. An element of \({\mathfrak {S}} (u)\) is called a shape; it is a connected component of X with no cavity, and its boundary is a level line of u. Every shape corresponds to a node of the tree; for instance, in Fig. 2(b) (right), the sub-tree rooted at node “\(\textsf {B}\)” corresponds to the shape \(\,\textsf {B}\, \cup \, \textsf {D}\, \cup \,\textsf {E}\). Keeping the level of every node—such as displayed in Fig. 2(b) (right)—allows to reconstruct the image from its tree. The tree of shapes of an image u is a morphological representation of u which makes it easier to deal with the image contents [10]. Storing [6] and computing [11, 14] the tree of shapes can be done very efficiently. Last, let us mention that the tree of shapes is a versatile tool to perform image filtering [23], and a very relevant structure to perform some computer vision tasks [5, 9, 22].

Let us now recall some results from [17] about defining the tree of shapes on set-valued maps. Given an interval-valued map \(\textsc {u}: {\mathbb {H}} ^n \rightarrow {\mathbb {I}} _Y\), using Eq. 1, its set of level sets is defined by \(\,{\mathfrak {T}}(\textsc {u}) \,=\, \bigcup _\lambda \, \mathcal {CC} ([\textsc {u} \lhd \lambda ]) \,\cup \, \mathcal {CC} ([\textsc {u} \rhd \lambda ])\). The set of connected components of X defined by:

$$\begin{aligned} {\mathfrak {S}} (\textsc {u}) \;=\; \{\, \mathrm {Sat} (\varGamma ) ;\; \varGamma \in {\mathfrak {T}}(\textsc {u}) \,\} \end{aligned}$$
(3)

can be arranged into a tree for some very particular maps \(\textsc {u}\). Every interval-valued maps \(\textsc {u}\) does not have a tree of shapes. Yet, if all the level sets of \(\textsc {u}\) are “well-composed” [3], then the tree exists.

2.5 Minimum Barrier Distance

As defined in [20], the barrier of a path \(\pi \) in a gray-level image u is \(\,\tau _u(\pi ) = \max _{\pi _i\in \pi } u(\pi _i) \,-\, \min _{\pi _i\in \pi } u(\pi _i)\), and the minimum barrier distance between x and \(x'\) in u is:

$$\begin{aligned} d^{\mathrm {\tiny MB}} _u(x,x') = \min _{\pi \in \varPi (x,x')} \tau _u(\pi ). \end{aligned}$$
(4)

It is actually a pseudo-distance since, \(\forall \, u\) and \(\forall \, x,x',x'' \in X\), it verifies: \(d^{\mathrm {\tiny MB}} _u(x) \ge 0\) (non-negativity); \(d^{\mathrm {\tiny MB}} _u(x,x) = 0\) (identity); \(d^{\mathrm {\tiny MB}} _u(x,x') = d^{\mathrm {\tiny MB}} _u(x',x)\) (symmetry); and \(d^{\mathrm {\tiny MB}} _u(x,x'') \le d^{\mathrm {\tiny MB}} _u(x,x') + d^{\mathrm {\tiny MB}} _u(x',x'')\) (subadditivity). Yet it is not a distance because the positivity property (\(x'\ne x\Rightarrow d^{\mathrm {\tiny MB}} _u(x,x') > 0\)) does not hold. Indeed we can have \(d^{\mathrm {\tiny MB}} _u(x,x') = 0\) for some \(x \ne x'\), e.g., in flat zones.

This pseudo-distance have been recently used in [25] and [21] to perform salient object segmentation, and it allows to achieve some leading performance (in terms of efficiency and accuracy) as compared to state-of-the-art methods.

3 The Dahu Pseudo-Distance

To tackle the issue explained in the introduction, we need to map a discrete image into a continuous representation such as Fig. 1(c); yet for computations to remain tractable we want to stay in a discrete setting.

3.1 A Convenient Continuous Yet Discrete Representation

This section explain how to represent a gray-value image \(\,u : {\mathcal {D}} \subset {\mathbb {Z}} ^n \rightarrow Y\) by an interval-valued map \(\,\widetilde{u}: {\mathcal {D}}_{\!H} \subset {\mathbb {H}} ^n \rightarrow {\mathbb {I}} _Y\), and by a new tree of shapes \({\mathfrak {S}} (\widetilde{u})\).

First, to every \(x=(x_{(1)},...,x_{(n)}) \in {\mathcal {D}} \), let us associate the n-face \(\,h_x = \{(x_{(1)},x_{(1)}+1) \times ... \times (x_{(n)},x_{(n)}+1) \} \in H^n_1\). \(\,{\mathcal {D}}_{\!H} \subset {\mathbb {H}} ^n \) is the domain defined by \({\mathcal {D}}_{\!H} = cl (\{h_x;\, x \in {\mathcal {D}} \}) \), which will correspond to \({\mathcal {D}} \) in \({\mathbb {H}} ^n \). From u we define \(\widetilde{u} \) by:

$$\begin{aligned} \forall \, h \in {\mathcal {D}}_{\!H}, \;\, \widetilde{u} (h) \;=\; \mathrm {span} \{\, u(x) ;\; x \in {\mathcal {D}} \,\text { and }\, h \subset h_x \,\}. \end{aligned}$$
(5)

A simple example of a transform of a gray-level image u, given in Fig. 3(a), into an interval-valued map \(\widetilde{u} \) is given in Fig. 3(c). As a result of Eq. 5, we can see that \(\,\widetilde{u} _{|_{H^n_1}}\) (the pinkish part) looks like the set-valued version of the original image u). The span computation is displayed by the gray and olive triangles, respectively for the dimensions \(d=1\) and \(d=0\). Eventually, only faces with a dimension less than n can be non-degenerated intervals (they are then displayed in orange).

A 3D version of the discrete interval-valued representation \(\widetilde{u} \) is depicted in Fig. 3(b); one can easily see that it is a discrete equivalent of the continuous surface of Fig. 1(c). We will define the tree of shapes of such \(\widetilde{u} \) maps in Sect. 4.1.

3.2 Definition of the Naive Dahu Pseudo-Distance

Relying on an interval-valued representation \(\widetilde{u}: {\mathcal {D}}_{\!H} \subset {\mathbb {H}} ^n \rightarrow {\mathbb {I}} _Y\) of a scalar image \(u : {\mathcal {D}} \subset {\mathbb {Z}} ^n \rightarrow Y\), we define the Dahu pseudo-distance by:

(6)

Let us just recall that the notation means that \(\,\forall \, x,\,\, {\overline{u}} (x) \in \widetilde{u} (x)\), so the argument of the minimum operator is a scalar function \(\,{\overline{u}}: {\mathcal {D}}_{\!H} \subset {\mathbb {H}} ^n \rightarrow Y.\,\) It means that we actually search for a minimal path in the cubical complex \({\mathcal {D}}_{\!H} \) (not in \({\mathcal {D}} \)), with the classical definition of the minimum barrier distance \(d^{\mathrm {\tiny MB}} \) (that is, a distance defined on scalar functions), and considering all the possible scalar functions \({\overline{u}} \) that are “included” in the interval-valued map \(\widetilde{u} \). The definition of the Dahu pseudo-distance is thus combinatorial w.r.t. all the scalar images \({\overline{u}} \) “included” in \(\widetilde{u} \) (see the parts highlighted in blue in Eq. 6). The Dahu pseudo-distance can be interpreted as the best minimum barrier distance that we can have considering that the input function is continuous.

The Dahu function is a pseudo-distance since it verifies the non-negativity, identity, symmetry, and subadditivity properties. In addition, we have the property: .

An example is given in Fig. 3(a) for an input function u, in Fig. 3(c) for its “continuous” representation \(\widetilde{u} \), and in Fig. 3(d) for a scalar function . A minimal Dahu path between two original points of u is depicted in blue Fig. 3(d); it is actually the same path as the one depicted on the continuous 3D surface in Fig. 1(c).

Fig. 4.
figure 4

The saddle case in 2D as a symptom of a discrete topology issue with \(\widetilde{u} \).

3.3 Solving a Discrete Topology Issue

In 2D discrete images, we can have saddle points. An example is given in Fig. 4(a), from which we deduce the continuous representation (given in Fig. 4(b)) in order to compute some minimal paths. We have which is obtained with \({\overline{u}} _a\) (Fig. 4(c)), and which is obtained with \({\overline{u}} _b\) (Fig. 4(d)). An interpretation of this situation “in the continuous world” is the following. On one hand, having implies not only that the level in \({\overline{u}} _a\) of the saddle point (the 0-face) is 0, but also that there is a 0-level line joining \(x_a\) and \(x_a'\) in \(\widetilde{u} \). On the other hand, since we have \(u(x_b) = 4\) and \(u(x_b) = 6\), \({\overline{u}} _b\) considers that the level 5 exists between \(x_b\) and \(x'_b\), which is in contradiction with the previous conclusion. We thus end up with some inconsistencies, if we consider two distinct discrete paths in u, and if we try to interpret these paths in a continuous way in \(\widetilde{u} \). The main issue, here in 2D, is that the representation \(\widetilde{u} \) cannot prevent lines to cross at different levels, which is the case at saddle points. From this example, we can draw a negative conclusion: The representation \(\widetilde{u} \) , as defined in Eq. 5 , cannot give us a continuous interpretation of the set of all paths in u without topological flaws.

A solution to this problem is to add an intermediate step which computes an “interpolation” of u that has no pathological parts such as the saddle points as in the 2D case. In the general nD case, these parts are called critical configurations, and an image without any critical configuration is said “digitally well-composed” (DWC) [2].

Let us denote by \({u_{_\Box }} \) an interpolation of the scalar image \(u : {\mathbb {Z}} ^n \rightarrow Y\), defined on the subdivided space \(\left( \frac{{\mathbb {Z}}}{2}\right) ^n \), and taking its values either in Y or in another scalar space \(Y'\). A continuous yet discrete representation of u is now \({\widetilde{{u_{_\Box }}}} \):

$$\begin{aligned} (u : {\mathbb {Z}} ^n \!\rightarrow Y) ~ \xrightarrow {\text {step 1}} ~ ({u_{_\Box }}: \left( \frac{{\mathbb {Z}}}{2}\right) ^{ n} {}\!\rightarrow Y') ~ \xrightarrow {\text {step 2}} ~ ({\widetilde{{u_{_\Box }}}}: \left( \frac{{\mathbb {H}}}{2}\right) ^{ n} {} \!\rightarrow {\mathbb {I}} _{Y'}). \end{aligned}$$
(7)

Under the assumption of \({u_{_\Box }} \) being digitally well-composed, the interval-valued image \({\widetilde{{u_{_\Box }}}} \) allows for representing u in a continuous yet discrete way, and without any topological inconsistency. We will say that such maps \({\widetilde{{u_{_\Box }}}} \) are path-consistent.

Now we can provide a new definition of the Dahu pseudo-distance:

(8)

As compared with the initial (naive) definition given by Eq. 6, we have just replaced \(\widetilde{u} \) by \({\widetilde{{u_{_\Box }}}} \).

Fig. 5.
figure 5

Interpolation-based interval-valued maps which are path-consistent.

Several subdivision-based interpolations of nD scalar images are known to produce DWC images. It is the case of the interpolation with the max operator, used in [13] for the quasi-linear computation of the tree of shapes of a scalar image, as defined by Eq. 2. In the 2D case—and not in nD with \(n>2\)—the only self-dual local interpolation verifying strong invariant properties leading to DWC images is obtained with the median operator [13]. It is depicted in Fig. 5(a) (after the step 2 \({u_{_\Box }} \rightarrow {\widetilde{{u_{_\Box }}}} \) being applied); Fig. 5(b) shows that the level lines do not cross each other. For the general nD case, a self-dual non-local interpolation has been defined [3], which is illustrated in Fig. 5(c) (again, after applying the step 2 to get an interval-valued representation).

4 Computing the Dahu Pseudo-Distance

The tree of shapes of an image is also called topographic map. Since the Dahu distance is related to the notion of topography, the tree of shapes may be a good candidate tool to compute any Dahu distance .

4.1 Tree of Shapes of Interval-Valued Maps

Since the scalar interpolations \({u_{_\Box }} \) are digitally well-composed, the tree of shapes of the interval-valued maps \({\widetilde{{u_{_\Box }}}} \), namely \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\), as defined by Eq. 3, exists. One can easily understand that it is due to the fact that \({\widetilde{{u_{_\Box }}}} \) is path-consistent: reminding that a level line is the boundary of a shape, since two level lines at different levels cannot cross each other, it implies that shapes are either disjoint or nested. Actually, the set \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) verifies the following properties: (i) Every element of this set is a connected component of \({\mathbb {H}} ^n\), having no cavity, and being a regular open set. (ii) The set \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) is a self-dual decomposition of \({\mathbb {H}} ^n \) with respect to u. (iii) The boundary of every component is an iso-level line of u, so:

$$\begin{aligned} \forall \, S \in {\mathfrak {S}} ({\widetilde{{u_{_\Box }}}}),\;\, \exists \, \mu \in Y' \text { such that } \,\forall \, h \in cl (S) \setminus \! S,\;\, \mu \in {\widetilde{{u_{_\Box }}}} (h). \end{aligned}$$

(iv) A mapping that associates a level, denoted by \(\mu (S)\), to every element \(S \in {\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) makes this set being a representation of \({\widetilde{{u_{_\Box }}}} \). We will say that \(\mu (S)\) is the level of the shape S (we will use this mapping in the next section).

4.2 When the Dahu Pseudo-Distance and the Tree of Shapes Meet

Intuitively it is easy to understand that the minimal path between two points of an image u, w.r.t. the Dahu pseudo-distance, corresponds to a path of nodes on the tree of shapes \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\). If we look back at Fig. 2(b) (left), the path between the two points \((x,x')\) indicated by red bullets in u starts from region B, then goes through A and C, and finally ends in region F. When considering the tree of shapes, in Fig. 2(b) (right), this path is exactly the same, and it crosses the level lines, depicted by dashed lines both in the image and on the tree. Such a path is minimal because every path in \(\varPi (x,x')\) should at least cross this same set of level lines to go from x to \(x'\). So the Dahu pseudo-distance corresponds to the level dynamics of this set of lines. In both the continuous version in Fig. 1(c) and its discrete representation in Fig. 3(b), we can directly read that the distance between the red points is 1 (the level lines are the dashed green lines).

Given a node t of a tree, let us denote by \(\mathrm {par} (t)\) the parent node of t in the tree, and by \(\mathrm {lca} (t,t')\) the lowest common ancestor of the nodes t and \(t'\). Let us denote by \(t_x\) the node of \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) corresponding to \(x \in X\); this node corresponds to the smallest shape of \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) containing \(h_x\). We can concatenate the two sequences of nodes \(\pi _x \,=\,\langle t_x,\, \mathrm {par} (t_x),\, \mathrm {par} ^2(t_x),\, ...,\, \mathrm {lca} (t_x,t_{x'}) \rangle \) and \(\pi _{x'} \,=\, \langle t_{x'},\, \mathrm {par} (t_{x'}),\, \mathrm {par} ^2(t_{x'}),\, ...,\, \mathrm {lca} (t_x,t_{x'})\rangle \), to form the new sequence:

$$\begin{aligned} \pi (t_x,t_{x'}) \;=\; \pi _{x}^{\,\,\frown } \pi _{x'}^{-1} \;=\; \langle t_x,\, \mathrm {par} (t_x),\, ...,\, \mathrm {lca} (t_x,t_{x'}),\, ...,\, \mathrm {par} (t_{x'}),\, t_{x'} \rangle . \end{aligned}$$
(9)

Note that, if \(t_{x'}\) is an ancester of \(t_x\) (or the reverse way), this writing is slightly different: \(\,\pi (t_x,t_{x'}) \,=\, \langle t_x,\, \mathrm {par} (t_x),\, ...,\, t_{x'} \rangle \). In the case of the example of Fig. 2(b), the \(\mathrm {lca}\) of the nodes \(t_\textsf {B}\) and \(t_\textsf {F}\) is \(t_\textsf {A}\), and the sequence of nodes is \(\langle t_\textsf {B}, t_\textsf {A}, t_\textsf {C}, t_\textsf {F} \rangle \) (depicted on the right), and it corresponds on the tree to the minimal path in the image space (depicted on the left).

To every shape \(S \in {\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) corresponds a node, say \(t_S\), of the tree of shapes. Let us then write abusively \(\mu (t_S) = \mu (S)\), where \(\mu (S)\) is the level of the shape as defined in Sect. 4.1. Eventually, the Dahu pseudo-distance can then be re-expressed by:

(10)

where the nodes considered and the mapping \(\mu \) are related to the tree \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\).

Practically, to compute we just have to update the interval values (min and max of \(\mu \)) starting respectively from the nodes of x and of \(x'\), up to their \(\mathrm {lca}\). For instance, on \(\pi _x\) we iteratively compute:

$$\begin{aligned} \mu _{\min }(\langle t_x, ... , \mathrm {par} ^{i+1}(t_x) \rangle ) \;=\; \min (\; \mu _{\min }(\langle t_x,..., \mathrm {par} ^i(t_x) \rangle ), \; \mu (\mathrm {par} ^{i+1}(t_x)) \;), \end{aligned}$$

and likewise for \(\mu _{\max }\). Eventually, is the length of the span of both intervals, that is: . On a regular PC, running GNU Linux with a 2.67 GHz CPU, computing one million distances between points randomly taken in the lena image takes about 1 s. Some code is available from: http://publications.lrde.epita.fr/geraud.17.ismm.

Fig. 6.
figure 6

Using the Dahu pseudo-distance on an actual application.

4.3 Illustration on Document Image Segmentation

Figure 6 gives an illustration on a camera-based document image taken from the SmartDoc competition organized at ICDAR 2015 [4]. Let us first recall that the tree of shapes has already been used to such an application [8, 22].

From a scalar image u (Fig. 6(a)), we compute its tree of shapes \({\mathfrak {S}} ({\widetilde{{u_{_\Box }}}})\) (Fig. 6(b)), which allows for computing very efficiently a distance map from the top left point (0, 0) (Fig. 6(c)) using the Dahu distance. One can see that the document is now well contrasted w.r.t. its environment. A saliency map corresponding to the Dahu distance is depicted in Fig. 6(d).

5 Related Works

In addition to the references given throughout the paper, related either to the context of our work or to its theoretical background, several other works shall be mentioned. Actually the notion of path on tree nodes also appear in [7] to assign to each node a label and then perform some scribble-based segmentation, in [8] to count level lines and build a multi-variate tree of shapes, and in [12] to compute some curvilinear variation and separate an object from its background. The notion of barrier used on the tree of shapes is also close to the one of shape saliency used in [24]. Last, about distance transforms and minimal path approaches, the reader can refer to the recent survey [19].

6 Conclusion

We have presented a new pseudo-distance, the Dahu distance, which is a variant of the minimum barrier (MB) distance on a continuous—yet discrete—representation of images. There are two major advantages of this distance as compared to the “classical” MB distance:

  • It considers that the input discrete images are actually defined in a continuous world, that is, that their elevation map is a surface.

  • Computing the Dahu distance for many couples of points \((x,x')\) is very efficient, thanks the pre-computation of a tree of shapes; furthermore, the distances obtained using this tree are exact. That contrasts with the efficient but approximate computation of the MB distance given in [21].

Some other practical interests of this new distance over its classical definition remain to be proved. Yet we believe that there are numerous perspectives for applications, which are made possible thanks to the fast tree-based computation. Another perspective is to adapt this distance to color images; that can be done using the multi-variate tree of shapes (MToS) defined in [8].