1 Introduction

In the digital geometry setting, it is very natural to define distance functions by minimal cost paths. Recently a new digital (i.e., path based) distance function has been investigated which provides the perfect Euclidean distance (from the Origin) for all the points having the same fixed number of steps in the corresponding shortest path from the Origin [11, 12]. This new distance function, which is called distance by weight sequence, is obtained as a kind of mixture of the two well known digital distance approaches, namely of the distances based on neighborhood sequences [5, 8, 10, 19] and of the chamfer distances, also known as weighted distances [1].

Discrete and digital distances may have some non-usual properties, e.g., they may not be metric. A function that is positive definite, symmetric and for which the triangular inequality holds is called a metric. The concept of metricity is an important property of distance functions. In our previous paper [12] we presented a very restricted sufficient condition for a weight sequence distance to be a metric. In Sect. 3 in this paper, we present a less restrictive condition for metricity.

Digital distances are well applicable in digital image processing. Given a distance function, a distance transform is a transform where each element in a set is assigned the distance to the closest (as given by the distance function) element in a complementary set. The result of a distance transform is called a distance map. This tool is often used in image processing and computer graphics [6]. In Sect. 4, we present a distance transform algorithm, which utilizes an auxiliary data structure to keep track of the number of steps of the minimal cost path at each point.

One of the ‘goodness’ measures of digital distances used in practice is related to their rotational dependency and how well they approximate the Euclidean distance. The most basic path-based distance functions, such as the city block and chessboard distances, have very high rotational dependency. In our previous paper [12] (which builds on [17]), we presented a formula for weight sequences that gives the exact Euclidean distance values on the border of a square, for arbitrary size of the square. This property is independent of the order of the weights in the weight sequence, and permutation optimization of the weights by a genetic algorithm is presented in Sect. 5.

2 Definitions, Preliminaries

In this section, first, we recall some basic concepts and fix our notations.

We denote the set of integers by \(\mathbb Z\) and the set of non-negative integers by \(\mathbb N\). Consequently the points of the digital two dimensional (square) grid are represented by \(\mathbb Z^2\). The set of positive real numbers is denoted by \(\mathbb R^+\).

In this paper, we consider grid points with integer coordinates. Of course, in image processing, each grid point is associated with a picture element, pixel. In a city block (resp. chessboard) distance, distinct points with unit difference in at most one (resp. two) of the coordinates have unit distance. Here, we use the notion of 1- and 2-neighbors in the following sense: Two grid points \(P_1=(x_1,y_1),P_2=(x_2,y_2) \in \mathbb {Z}^2\) are \(\rho \)-neighbors, \(\rho \in \{1,2\}\), if

$$\begin{aligned} |x_1 - x_2 | + |y_1 - y_2|&\le \rho \text { and} \\ \max \left\{ | x_1 - x_2 |, |y_1 - y_2|\right\}&= 1.\nonumber \end{aligned}$$
(1)

The points are strict \(\rho \)-neighbors if the equality in (1) is attained. Two points are adjacent if they are \(\rho \)-neighbors for some \(\rho \in \{1,2\}\).

We also recall the notion of path. A path in a grid is a sequence of adjacent grid points. A path \(\varPi =(P_0 , P_1 ,\dots , P_n)\) is a path of n steps where for all \(i \in \{1,2,\dots ,n\}\), \(P_{i-1}\) and \(P_{i}\) are adjacent. The path \(\varPi \) connects \(P_0\) and \(P_n\). We may also say that the path starts from \(P_0\) and arrives to \(P_n\), i.e., they are its start point and endpoint, respectively.

In this paper, we use the general concept of weight (or chamfer) sequences (from [11, 12]), instead of neighborhood sequences [5, 8,9,10] or chamfer distances [1]. This general description is as follows:

Definition 1

(weight-sequence distance). Let \(m\in \mathbb N, \ m\ge 0\) be the number of the used weights, and let \(S= \{1, \infty \} \cup \{ w_3, \dots , w_m \}\) be the weight set including 1, the sign \(\infty \) and the used weights (\(w_i\in \mathbb R\), \(w_i >1\) for all \(i\in \{3,\dots ,m\}\)).

A weight sequence is \(W=\left( c(i)\right) _{i=1}^{\infty }\), where \(c(i)\in S\), for all \(i \in \mathbb N\).

Let \(P, Q\in \mathbb Z^2\), then the weight of the path \(\varPi = (P=P_0,P_1,\dots ,P_m=Q)\) is the sum of the weights of its steps, where the weight of the j-th step is specified as

\({\left\{ \begin{array}{ll} c(j), &{} \hbox {if the } j \hbox {-th step is a step to a strict 2-neighbor;} \\ 1, &{} \hbox {otherwise.} \end{array}\right. }\)

The W-distance d(PQW) of P and Q, is then, defined as the weight of the minimal weighted path connecting P and Q.

In fact, all city block paths are valid for d(PQW) and have the same weight as in the city block distance. This implies that d(PQW) is upper-bounded by the city block distance. When the \(\infty \) sign used in W for some step i (\(c(i)=\infty \)), it denotes an arbitrary large weight that prevents paths with a strict 2-neighbor at step i to be minimal. When computing a W-distance one can vary the features of neighborhood sequences and chamfer distances: the cost of a move to a 1-neighbor is 1 in every step, and the cost of a move to a strict 2-neighbor (diagonal step) is given by the actual element c(j) of the weight sequence.

In [12] it was shown that for any weight sequence W, if \(\varPi \) is a minimal W-path between \(P,Q\in \mathbb Z^2\), then it does not contain any steps to strict 2-neighbors by any weight \(w_i >2\).

The way the set S is defined, m different neighborhood relations (possible steps by various weights) are allowed in our paths:

  • a traditional 1-step is a step between 1-neighbors with unit weights, the sign \(\infty \) denotes these steps in W (practically, strict 2-steps are not allowed);

  • a traditional 2-step is a step between 2-neighbors with unit weights, they are denoted by value 1 in W;

and if \(m>2\), then, by the used weights \(w_3, \dots , w_m\) the further steps are as follows:

  • weighted 2-steps: the steps between 1-neighbors with unit weights, and between strict 2-neighbors with weight \(w_k\) (where \(3\le k \le m\)) with \(c(i)=w_k\) for some i in W.

Note that the weight sequence W can contain m values, “weights”, according to a predefined set S, i.e. \(W=(c(i))_{i=1}^{\infty }\) where \(c(i)\in S\).

When written in a formal way, the sum of the weights along the path is:

$$\sum \limits _{i=1}^n \delta _i , \text { where } \delta _i = {\left\{ \begin{array}{ll} c(i), &{} \text { if } P_{i-1} \text { and } P_i \text { are strict} \ 2 \text {-neighbors}; \\ 1, &{} \text { otherwise}. \end{array}\right. }$$

When the weight sequence W is fixed, the term W-path is used for paths having finite cost as defined by the weight sequence W.

We recall that greedy algorithms cannot be used to provide shortest paths. If a smaller weight appears after a larger weight in W, it may be needed in the shortest path instead of the previous larger one, depending on both the weight sequence and on the difference of the coordinate values of the points.

Now we recall the formula for computing the distance between any two grid points. The formula is used for finding optimal parameters in Sect. 5. Before the theorem we define a technical notation which will also be helpful later on.

Definition 2

Let a weight sequence \(W=(c(i))_{i=1}^\infty \) (based on a weight set \(S=\{1, \infty , w_3, \dots , w_m\}\)) be given. Let \(m,n\in \mathbb N\) such that \(n\ge m\). Then I(nm) contains the indices of the smallest m weight values among the first n elements of W, i.e., among \((c(1),\dots ,c(n))\).

Theorem 1

Let the weight sequence \(W=(c(i))_{i=1}^\infty \) (based on a weight set \(S=\{1, \infty , w_3, \dots , w_m\}\)) and the point \(P(x,y)\in \mathbb {Z}^2\), where \(x\ge y\ge 0\), be given. Then the W-distance of P from the Origin \(\mathbf {0}\) is given by

$$\begin{aligned} d(\mathbf {0},(x,y);W)=\min _{f \in \{0..y\}} \left\{ x+y-2f +\sum \limits _{i\in I(x+y-f ,f)} c(i) \right\} . \end{aligned}$$
(2)

Since the roles of the x- and y-coordinates are similar, and our distance function is translation invariant, one can compute the W-distance of any pair of points of \(\mathbb Z^2\) by the previous formula.

Remark 1

As a special case, the weight sequence \(W=(1)_{i=1}^\infty \) defines the chessboard distance, since steps to 2-neighbors are always allowed with unit cost. The weight sequence \(W=(2)_{i=1}^\infty \) defines the city block distance, since, in this case, in any path one needs to pay the weight of two city block steps for a diagonal steps if the path contains any diagonal steps. Equivalently, minimal cost paths can be obtained using only steps to 1-neighbors.

3 Metricity Properties

One important property of digital distances is that of metricity. A metric is a distance function which satisfies the metric properties: positive definiteness, symmetry, and the triangular inequality. Formally:

A distance function d is a metric if it satisfies the following three properties:

  • \(d(P,Q)\ge 0\) for any point pair PQ, moreover \(d(P,Q)=0\) if and only if \(P=Q\). (positive definiteness)

  • \(d(P,Q)=d(Q,P)\) for any point pair PQ. (symmetry)

  • \(d(P,Q)+d(Q,R)\ge d(P,R)\) for any three points PQR. (triangular inequality)

It is easy to find a weight sequence such that the distance generated by the sequence does not satisfy the metric conditions. The first two properties, namely, the positive definiteness and the symmetry are always satisfied for distances defined by weight sequences on the square grid (it is clear by the definitions and the formula 2 shown in the previous section). However, the triangular inequality is problematic in some cases.

In [12] it was proven that if the weight sequence W contains the weights in a non-increasing order, then the generated distance function is a metric. However, with this restriction the number of the possible weight sequences is very limited. Now, we show a more general sufficient condition for a weight sequence to define a metric. First, we define the shifted sequences of a weight sequence (in a kind of analogous way as similar concept was defined and used for the neighborhood sequences in, e.g., [8]).

Definition 3

The k-shifted sequence of a weight sequence \(W=(c(i))_{i=1}^\infty \) is the sequence that obtained from W by starting from its k-th element, i.e., \(W^k = (c(i))_{i=k}^\infty \).

It is easy to see that \(W=W^1\), while for \(k>1\), \(W^k\) is obtained from W by erasing its first \(k-1\) elements.

Theorem 2

Let the weight sequence \(W =(c(i))_{i=1}^\infty \) be given. If W has the property that for every \(n,m,k\in \mathbb N\) (\(m\le n\))

$$\begin{aligned} \sum \limits _{i\in I(n,m)} c(i) \ge \sum \limits _{i\in I^k(n,m)} c(i) \end{aligned}$$
(3)

(where, according to Definition 2, I(nm) and \(I^k(n,m)\) are the sets containing the indices of the m smallest weights/elements among the first n elements of W and \(W^k\), respectively, thus \(|I(n,m)|=|I^k(n,m)|=m\) is their cardinality), then W defines a metric.

Proof

It is clear that all W-distances are symmetric and positive definite, thus we work only with the triangular inequality. Let us assume, by contrary, that there are three points \(P,Q,R\in \mathbb Z^2\) such that \(d(P,Q;W) + d(Q,R;W) < d(P,R;W)\). Let the path \(\varPi _{P,Q}\) be the path from P to Q with the least weight, i.e., the path which is defining the distance d(PQW). Further, let \(\varPi _{Q,R}\) be the path from Q to R that defines the distance d(QRW). Then let us consider the path \(\varPi _{P,R}\) from P to R which is exactly the concatenation of the path \(\varPi _{P,Q}\) and the steps of the path \(\varPi _{Q,R}\). We notice that since the weights may not be the same in the prefix of W and in its subsequence used from Q to R, it is generally, not true that the obtained path \(\varPi _{P,R}\) has the sum of the weight \(d(P,Q;W) + d(Q,R;W)\). However, if the condition of the theorem is fulfilled, let us choose the numbers nm and k as follows. Let n be the number of the steps of \(\varPi _{Q,R}\). Set m as the number of its diagonal steps, finally put k as 1 more than the number of the steps of the path \(\varPi _{P,Q}\). Considering the steps of \(\varPi _{Q,R}\), in the left hand side of the inequality \(d(P,Q;W) + d(Q,R;W) < d(P,R;W)\) the W-distances are used, while, considering the right hand side, we have a W-path, such that its first part (between P and Q) has exactly the weight d(PQW), and its second part (from Q to R) has the weight that is based on the weight sequence \(W^k\). Then, we state that, by the condition \(\sum \limits _{i\in I(n,m)} c(i) \ge \sum \limits _{i\in I^{k}(n,m)} c(i) \), there is a path \(\varPi '_{Q,R}\) such that its \(W^k\) weight is not more than d(QRW). However, in this case, concatenating \(\varPi _{P,Q}\) and \(\varPi '_{Q,R}\) we have a W-path from P to Q such that its weight is not more than \(d(P,Q;W) + d(Q,R;W)\). That is contradicting to our indirect assumption, thus, the triangular inequality must hold, if the condition of the theorem is fulfilled by the sequence W.

What is remained to show, that if \(\sum \limits _{i\in I(n,m)} c(i) \ge \sum \limits _{i\in I^{k}(n,m)} c(i) \), then there is a path \(\varPi '_{Q,R}\) such that its \(W^k\) weight is not more than d(QRW). Let us assume, by contrary, that \(d(Q,R;W^k) > d(Q,R;W)\), i.e., there exist no such path \(\varPi '_{Q,R}\). Then applying the formula for the distance, actually, \(d(Q,R;W) = n-m + \sum \limits _{i\in I(n,m)} c(i)\). By the condition of the theorem there is also a \(W^k\)-path with n steps between Q and R having m diagonal steps with cost \(n-m + \sum \limits _{i\in I^k(n,m)} c(i)\). However, since \(\sum \limits _{i\in I(n,m)} c(i) \ge \sum \limits _{i\in I^k(n,m)} c(i) \), the cost of this path is not more than d(QRW). Therefore, \(d(P,Q;W^k)\) cannot be larger than d(PQW), path \(\varPi '_{Q,R}\) must exist with the desired property.    \(\square \)

The following examples illustrate metricity of distance functions based on some specific weight sequences.

Example 1

Let the weight sequence contain additional weights \(\{1.5,1.8\}\) and consider the periodic weight sequence \(W=(1.8,1.5,1.8,1.5...)\). One can easily see that W fulfills the condition of Theorem 2, thus it defines a metric.

Example 2

Let the weight set be \(\{1.5,1.55,1.6,1.75\}\). Further, let \(W=(1.75,1.5,1.6,1.5,1.55,1.5,1.5,1.5,...)\) with \(c(i)=1.5\) for all \(i>6\). Again, it is easy to check that the triangular inequality holds and that the given W-distance is a metric.

Notice that in both of our examples the weights in the sequence are not ordered in non increasing way, thus the condition presented in [12] cannot be applied to prove the metricity of the corresponding distances.

Finally, to show that the triangular inequality may fail in some cases, let us consider the next example:

Example 3

Let \(W=(1.2,1.5,1,...)\). Then the W-distances of the points (0, 0), (1, 1) and (2, 2) are computed:

  • \(d((0,0),(1,1);W) = 1.2\)

  • \(d((1,1),(2,2);W) = 1.2\)

  • \(d((0,0),(2,2);W) = 1.2+1.5=2.7.\)

Therefore, the triangular inequality fails for this W-distance.

4 Distance Transform (DT)

The DT is a mapping from the image domain, a subset of the grid, to the range of the distance function. In a DT, each object grid point is assigned the distance from its closest background grid point. A modified version of a wave-front propagation algorithm can be used.

Now the formal definition of an image is given.

Definition 4

The image domain is a finite subset of \(\mathbb {Z}^2\) denoted by \(\mathcal {I}\). We call the function \(F:\mathcal {I} \longrightarrow \mathcal {R}_d\) an image, where \(\mathcal {R}_d\) is the range of the distance function d.

An object is a subset \(X \subset \mathcal {I}\) and the background is \(\overline{X} = \mathcal {I} \setminus X\). We assume that \(X,\overline{X} \ne \emptyset \). We denote the distance map for path-based distances with \(DM_d\), where the subscript d indicates what distance function is used.

Definition 5

The distance map \(DM_d\) generated by the distance function \(d(\cdot , \cdot ; W)\) of an object \(X\subset \mathcal {I}\) is the mapping

$$\begin{aligned} DM_d:\mathcal {I}&\rightarrow \mathcal {R}_d \text { defined by}\\ P&\mapsto d\left( \overline{X},P;W\right) \text {, where}\\ d\left( \overline{X},P;W\right)&= \min _{Q\in \overline{X}} \left\{ d\left( Q,P;W\right) \right\} . \end{aligned}$$

In the case of W-distances with two weights, a minor modification of the Dijkstra algorithm (and with the same time complexity) can be used, see [18] and Theorem 4.1 in [15]. However, for multiple weights, this is not necessarily true. For W-distances, the used weights are also important and they are determined by the number of steps of the minimal cost-path (not by the cost). Therefore, in the general case of multiple weights presented here, we need to store this value also when propagating distance information. We define the auxiliary transform \(DM_s\) that holds the number of steps of the minimal cost path at each point, see Algorithm 1.

Note that we need to store not only the best distance values at the points, but the best values that are computed by various number of steps. Therefore, for each point P a set S(P) of pairs of values of the form \((DM_d,DM_s)\) are stored, i.e., the weight \(DM_d\) of the shortest path among the ones containing exactly \(DM_s\) number of steps, with pairwise different \(DM_s\). After the run of the algorithm for each point the minimal \(DM_d\) gives the result.

Algorithm 1 shows how the distance map can be computed based on an extended optimal search (Dijkstra algorithm) and using the data structure described above. At the initialization the object points are the only points that are reached and it is done by 0 steps and with 0 cost. Then the border points of the object are listed in an increasing order by the minimal cost path already known for them. Actually every point in the priority queue has 0 cost, but the queue will be updated by involving other points to where paths are already found. The while loop chooses (one of the) point(s) with minimal cost from the queue since it is sure that we have the minimal cost path to this point already. Then in the loop the data of all adjacent points of the chosen point are updated by computing the cost of the new paths through the chosen point (having last step from the chosen point to the actual adjacent point). Therefore, the algorithm holds the optimal distance attained at each point (as the usual algorithm), but this is done for each path length from the shortest ones till the ones obtained by only steps to 1-neighbors. So, if there are paths of different lengths ending up at the same point, distance information for each of the different path lengths are stored.

The algorithm may look more complex than similar algorithms for the other distances and this is due to the fact that greedy shortest path algorithm does not work in the general case. However, by using the weights in non-decreasing order, the greedy shortest paths algorithms work, and thus, for every point Q of the grid one need to remember only for the value obtained with the path length when the point Q is pushed into the queue.

5 Approximation of the Euclidean Distance

In this section, we apply a genetic algorithm to permute a weight sequence that gives the exact Euclidean distance values on the border of a square. The comparison to the Euclidean distance is carried out with absolute and relative mean and maximum values of the absolute difference between the Euclidean and weight sequence distance.

The following Lemma, which is from our previous paper [12], will be used for defining the fitness function in the genetic algorithm optimization.

figure a

Lemma 1

If the weight sequence W is non-decreasing and all elements in W are smaller than or equal to 2, then the distance value in Eq. (2) is given by

$$ d(\mathbf 0,(x,y);W)= x-y+\sum \limits _{i=1}^y c(i) $$

The following Theorem, from [12], states that the W-distance with r different weights (as given in the Theorem) can give the exact Euclidean distance values on the border points of a square of side length \(2r-1\).

Theorem 3

Given an integer \(x>0\), the Euclidean distance values from (0, 0) to each point of the set \(\{(x,y)\in Z^2, 0\le y\le x \}\) is given without errors by the weight sequence \(W=(c(i))_{i=1}^\infty \) with \(c(i) = \left( 1+\sqrt{x^2+i^2}-\sqrt{x^2+(i-1)^2}\right) \) for \(1\le i \le x\).

Note that the distance values on the border of the square of side \(2r-1\) are independent of the order of the weights r weights in the sequence given in Theorem 3. In [12], we presented a greedy algorithm for ordering the weights in the weight sequence. Here, we extend the optimization by a global optimization, where the optimal permutation of the r weights are sought in order to minimize

  • the absolute mean error,

    $$\begin{aligned} \frac{2}{r\cdot (r+1)}\sum _{r\ge x\ge y\ge 0} |d_E(x,y)-d(x,y;W)| \end{aligned}$$
    (4)
  • the relative mean error

    $$\begin{aligned} \frac{2}{r\cdot (r+1)}\sum _{r\ge x\ge y\ge 0} \frac{|d_E(x,y)-d(x,y;W)|}{d_E(x,y)} \end{aligned}$$
    (5)
  • the absolute maximum error,

    $$\begin{aligned} \max _{r\ge x\ge y\ge 0} |d_E(x,y)-d(x,y;W)| \end{aligned}$$
    (6)
  • the relative maximum error

    $$\begin{aligned} \max _{r\ge x\ge y\ge 0} \frac{|d_E(x,y)-d(x,y;W)|}{d_E(x,y)} \end{aligned}$$
    (7)

In the experiments, a weight sequence of length 40 was calculated by Theorem 3. The weight sequence is \(c(i) = \left( 1+\sqrt{40^2+i^2}-\sqrt{40^2+(i-1)^2}\right) , i=1..40\). The weights were permuted by a genetic algorithm [7] with the fitness functions (4), (5), (6), and (7). The fitness functions are efficiently computed by Lemma 1. The crossover is a flip of a section (with random start and end point) of the weight sequence, the mutation swaps to random elements of the weight sequence. The optimization is run with a population size of 60 and the maximum number of generations was set to 1000.

The optimal permutations are found below and illustrations of the difference between the so-obtained distance functions and the Euclidean distance are found in Fig. 1.

The obtained optimal permutations are (the indices of the weights c(i) are shown for brevity):

  • the absolute mean error (4)

    36, 1, 32, 16, 22, 11, 23, 35, 7, 25, 10, 26, 12, 40, 4, 30, 18, 27, 5, 37, 14, 19, 38, 3, 28, 13, 24, 9, 29, 15, 39, 2, 31, 17, 33, 8, 20, 34, 6, 21

  • the relative mean error (5)

    19, 7, 37, 28, 2, 32, 22, 16, 10, 31, 14, 27, 4, 39, 21, 12, 26, 6, 40, 15, 30, 3, 35, 17, 20, 8, 34, 13, 24, 29, 1, 36, 18, 11, 38, 9, 25, 23, 5, 33

  • the absolute maximum error (6)

    14, 37, 18, 6, 32, 26, 1, 21, 38, 16, 25, 3, 30, 27, 11, 15, 29, 8, 40, 10, 35, 12, 28, 17, 5, 24, 36, 2, 20, 23, 33, 4, 19, 39, 7, 34, 13, 31, 9, 22

  • the relative maximum error (7)

    19, 13, 36, 4, 40, 26, 1, 16, 21, 14, 27, 8, 25, 7, 34, 35, 15, 23, 29, 2, 31, 3, 18, 38, 20, 10, 12, 33, 24, 9, 37, 11, 28, 39, 5, 22, 30, 6, 32, 17

Fig. 1.
figure 1

Illustration of the point-wise difference between the Euclidean distance and the weight sequence distance with a permutation of the weights obtained by a genetic algorithm. The fitness functions used are Absolute mean difference (a), Relative mean difference (b), Absolute max difference (c), and Relative max difference (d). All distances are computed from a single central source point.

6 Conclusions and Discussion

This paper extends the work presented in [12], and further develops the framework for distances based on weight sequences, that is digital path-based distance functions defined as minimal cost paths on the square grid.

By the results in this paper, a digital and completely error-free distance function with very low rotational dependency, together with an algorithm that can be used to compute distance transforms, Algorithm 1, are presented. Efficient algorithms for computing distance transforms are necessary for real-world applications, where computation time often is a bottle-neck. Due to the very low rotational dependency the proposed digital distance function can be used instead of, for example, the Euclidean distance transform. The Euclidean distance transform can be computed efficiently by state-of-the-art methods, but Euclidean distance transform computation has some drawbacks: (i) the vector-propagation method inevitably produces errors for some pixel configurations [4, 13], (ii) fast-marching methods are based on coarse approximations of the Eikonal equation, and thus give only approximate distance values [14], (iii) separable algorithms are not suited for constrained distance transform computation [2, 3]. See also [15, 16].

This paper presents a less restrictive condition for metricity, compared to what was presented in [12]. This less restrictive condition will be important when further developing the theory for these distance functions.

In addition, this paper presents an optimization procedure based on a genetic algorithm. Note that the genetic algorithm can be run with several different parameters, and the ones used in the manuscript are standard parameters with slight fine-tuning based on experimental evaluation. The optimization is not deterministic and there are no guarantees that the obtained local optimum is a global one, but the process was reasonably stable when executed several times. The low rotational dependency obtained by the optimization procedure is key in many real-world problems.

In our future work, we will analyze Algorithm 1 in depth, including both proof of correctness and space and time complexity. We also leave it as an open problem whether the condition of Theorem 2 is also a necessary condition to define metric distances.

The proposed distance function has great potential in many image processing algorithms where distance transforms with low rotational dependency is required.