Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

1 Introduction

Both in theory and practice of image processing and computer graphics, digital geometry is of high importance. In 2D pixels, in 3D voxels play the role of units. Digital geometry differs from the usual Euclidean geometry: neighbor relation is understood and play important role among the units (e.g., pixels). In digital geometry (since the domain is discrete), digital, path-based distances are considered. The history of digital geometry has been started by the seminal paper [19], in which the cityblock (Manhattan) and the chessboard distances were defined on the square grid. Since these distances are very rough approximations of the Euclidean distance, various techniques are developed. By neighborhood sequences one may vary the type of used neighborhood along a path [3, 4, 10, 13, 24]. In weighted distances the minimal weighted paths are counted in which steps to different type of neighbors may count with different weights [1, 20]. It is well known that based on a larger “neighborhood”, i.e., allowing direct steps to a larger set of pixels, better approximation of the Euclidean distance can be obtained [1, 2, 23]. There are also mixed solutions [17] to obtain errorless approximations on a ‘perimeter’ of a square. The field has developed involving other, non-traditional grids, e.g., hexagonal and triangular grids in 2D [5, 9, 11] and various 3D grids [16, 22]. Using various grids appropriate coordinate systems have large advantages [6, 12, 15] allowing relatively simple formulations of theoretical results which is also very useful for practical purposes.

Digital geometry has also some very interesting properties by comparing it to the usual, Euclidean geometry. One of these properties is known as a ‘topological paradox’: considering the two diagonals of a chessboard, one of them consist of only black, the other consists of only white pixels: these two lines cross each other without having an intersection pixel. There are various solutions to overcome this paradox, e.g., to use a non-traditional grid, e.g., the hexagonal grid in this case; or to use a topological coordinate system addressing not only the pixels of the grid [8, 14]; or to use a restricted neighborhood, see, e.g., [7, 21]. In Khalimsky grid the 4-neighbor and the 8-neighbor relations are used for the points of the grid, alternately, depending on their positions (see Fig. 1, left, also).

Motivated by these facts, in this paper we are considering the Khalimsky grid (to avoid some topological paradoxes) and we define weighted distances on this grid. We also show some interesting phenomena, and future directions of research.

Fig. 1.
figure 1

The usual representation of the Khalimsky grid: neighbor points are connected by edges (left); and a part of the grid T(8,8,4): pixels with their Cartesian coordinates (right).

In the next section, we describe the Khalimsky grid with an appropriate coordinate system, then in Sect. 3 weighted distances on this grid are defined. In Sect. 4, we present results based on two types of natural neighborhood relations, while in Sect. 5 three types of neighborhood relations are used including a semi-neighborhood relation.

2 Description of T(8,8,4)

Figure 1 (left) shows a usual representation of the Khalimsky grid. As one can observe, the grid (the digital plane) is not homogeneous, and there are various ways to choose pixels. In our paper, we use the basic form of the grid, considering each vertex of the grid as a pixel. Consequently, our grid is T(8,8,4) if dual notation is used, see, e.g., [18]. We have also rotated the grid with \(\pi /4\) and in this way a convenient coordinate system can be assigned to the pixels. In this representation octagons represent the points for which 8-neighborhood is used and squares (diamonds) the points for which 4-neighborhood is used (see Fig. 1, right).

Each pixel of the T(8,8,4) grid is an octagon or a square. An octagon has 8 neighbors with common sides (4 octagons and 4 squares). A square has 4 neighbors with common sides (4 octagons).

Each pixel (octagon or square) of the grid can be described by a unique coordinate pair.

There is an octagon with coordinates (0, 0). The axes are horizontal or vertical. At every time when we step from an octagon to another one crossing their common side, the step is done parallel to one of the axes. If the step is in the direction of an axis, then the respective coordinate value is increased by 1, while in case the step is in opposite direction to an axis, the respective coordinate value is decreased by 1. In this way every octagon gets a unique coordinate pair with integer values. The octagons p(p(1), p(2)) and q(q(1), q(2)) are neighbors, if \(|p(1)-q(1)|+|p(2)-q(2)|=1\).

When we step from an octagon to a square crossing their common side, the step is done diagonally. If the step is in the half-direction of an axis, then the respective coordinate value is increased by 0.5, while in case the step is in opposite direction, the respective coordinate value is decreased by 0.5. In this way every square gets a unique coordinate pair with fraction values (i.e. each value has the form of an integer plus a half). The octagon p and the square q are neighbors, if \(|p(1)-q(1)|+|p(2)-q(2)|=1\).

There are no squares with common side. But every square p has 4 semi-neighbor square, for example q, for which \(|p(1)-q(1)|+|p(2)-q(2)|=1\). In this case, square p and square q have two common octagon neighbors, and the common side of the octagon neighbors is situated between the two squares as an edge connecting them.

3 Definition of Weighted Distances

Let \(\alpha ,\beta \in \mathbb R^+\) be positive weights. The simplest weighted distances allow to step from an octagon to a cityblock neighbor octagon by changing only 1 coordinate value by \(\pm 1\) with weight \(\alpha \). Similarly it allows to step from an octagon to a diagonal neighbor square (and vice versa) by changing both the coordinate values by \(\pm 0.5\) with weight \(\beta \).

Let the weight of a step from a square to a semi-neighbor square be \(\gamma \). This step changes only 1 coordinate value by \(\pm 1\) (We use this kind of step only at the second part of this article, in Sect. 5 about extended weighted distances.).

We can define the weighted distance of any two points (octagons or squares) of the grid. Let p and q be two points of the grid. A finite point sequence of points of the form \(p=p_0,p_1,\dots ,p_m=q\), where \(p_{i-1},p_i\) are neighbors (or semi-neighbors) for \(1\le i \le m\), is called a path from p to q. A path can be seen as consecutive steps to neighbors (or semi-neighbors). Then the cost of the path is the sum of the weights of its steps.

Finally, let the weighted distance \(d(p,q;\alpha ,\beta )\) of p and q by the weights \(\alpha , \beta \) be the cost of the minimal (basic) weighted paths between p and q. Similarly, the weighted distance \(d(p,q;\alpha ,\beta ,\gamma )\) is the cost of the minimal extended weighted paths between p and q using the weights \(\alpha ,\beta ,\gamma \).

A technical definition is used through the paper. The difference \(w_{p,q}=(w(1),w(2))\) of two points p and q is defined by \(w(i)=|q(i)-p(i)|\).

4 Minimal Weighted Paths

Firstly we use only the steps between neighbors (steps with weight \(\gamma \) is forbidden in this basic case).

There are various paths with various sums of weights that can be found between any two points. When the weights \(\alpha \) and \(\beta \) are known the optimal search (the Dijkstra algorithm) can be used. However depending on the actual ratios and values of the weights \(\alpha ,\beta \) one can compute a minimum weighted paths. Using a combinatorial approach, we give methods for these computations for each possible case.

The relative weights give the separation of the possible cases.

4.1 Case \(\alpha \le \beta \)

If p and q are octagons, then the use of \(\beta \)-steps is not efficient. A minimal path can be constructed only by \(\alpha \)-steps. In every step the absolute value of a coordinate difference is decreasing by 1. Thus

$$\begin{aligned} d(p,q;\alpha ,\beta )=\alpha \cdot (w(1)+w(2)). \end{aligned}$$
(1)

For example the weighted distance of the octagons (0,0) and (3,1) is \(4\alpha \).

If p and q are an octagon and a square, then the minimal path contains the minimal path between the octagon and another octagon, which is the closest octagon neighbor of the square. Moreover the minimal path contains one \(\beta \)-step between the above mentioned octagon and the square. Thus

$$\begin{aligned} d(p,q;\alpha ,\beta )=\alpha \cdot (\lfloor w(1)\rfloor +\lfloor w(2)\rfloor )+\beta , \end{aligned}$$
(2)

where w(i) is a fraction value and \(\lfloor w(i)\rfloor \) is the next lowest integer value of w(i) (floor function). For example the weighted distance of the octagon (0,0) and the square (3.5,1.5) is \(4\alpha +\beta \).

If p and q are squares, then the minimal path uses only two \(\beta \)-steps, the first and the last steps. Between these steps the minimal path contains the minimal path between the closest octagon neighbors of the squares using only \(\alpha \)-steps. Thus

$$\begin{aligned} d(p,q;\alpha ,\beta )=\alpha \cdot (\lfloor |w(1)-0.5|\rfloor +\lfloor |w(2)-0.5|\rfloor )+2\beta , \end{aligned}$$
(3)

where w(i) is a non-negative integer, thus \(|w(i)-0.5|\) is a non-negative fraction. For example, the distance of the squares (0.5,0.5) and (3.5,1.5) is \(2\alpha +2\beta \). But \(d((0.5,0.5),(3.5,0.5);\alpha ,\beta )=2\alpha +2\beta \), too. Also, \(d((0.5,1.5),(3.5,0.5);\alpha ,\beta )=2\alpha +2\beta \).

Let us assume, that \(2\alpha <\beta \), and let us determine the set of points, which distance from the octagon (0, 0) is less or equal to \(2\alpha \). Then the distance of the 4 octagon-neighbors of the original octagon is \(\alpha \), i.e. these are in the set: (1, 0), (0, 1), \((-1,0)\), \((0,-1)\). The distances of every octagon-neighbors of these 4 neighbors are \(2\alpha \), i.e. these are in the set, too: (2, 0), (0, 2), \((-2,0)\), \((0,-2)\), (1, 1), \((-1,1)\), \((-1,-1)\), \((1,-1)\). The distances of all other octagons are more than \(2\alpha \), and the distances of the square-neighbors are more than \(2\alpha \), too. It means that this set contains 13 octagon-elements, and it has 4 holes. For example, the square-neighbor (0.5, 0.5) is not in the set, but all of its neighbors ((0, 0), (1, 0), (0, 1), and (1, 1)) are elements of the set.

4.2 Case \(\beta \le \alpha \le 2\beta \)

Two \(\alpha \)-steps, a vertical and after that another horizontal, can be substituted by two consecutive diagonal \(\beta \)-steps, because \(2\beta \le 2\alpha \). We can do this change \(\min \{w(i)\}\) times. Thus if p and q are octagons, then

$$\begin{aligned} d(p,q;\alpha ,\beta )=2\beta \cdot \min \{w(i)\}+\alpha \cdot (\max \{w(i)\}-\min \{w(i)\}). \end{aligned}$$
(4)

For example the weighted distance of the octagons (0,0) and (3,1) is \(2\beta +2\alpha \).

Similarly, if p and q are an octagon and a square, then the minimal path contains the minimal path between two octagons and a final step between an octagon and a square. Thus

$$\begin{aligned} d(p,q;\alpha ,\beta )&=\,2\beta \cdot \min \{\lfloor w(i)\rfloor \}+\alpha \cdot (\max \{\lfloor w(i)\rfloor \}-\min \{\lfloor w(i)\rfloor \})+\beta =\nonumber \\&=\, 2\beta \cdot \min \{w(i)\}+\alpha \cdot (\max \{w(i)\}-\min \{w(i)\}). \end{aligned}$$
(5)

For example \(d((0,0),(3.5,1.5);\alpha ,\beta )=3\beta +2\alpha \).

Finally, if p and q are squares, then the minimal path contains the minimal path between two octagons and the starting and the final step between an octagon and a square. Thus

$$\begin{aligned} d(p,q;\alpha ,\beta )= 2\beta \cdot \min \{(\lfloor |w(i)-0.5|\rfloor \}+\alpha \cdot (\max \{(\lfloor |w(i)-0.5|\rfloor \}-\min \{(\lfloor |w(i)-0.5|\rfloor \})+2\beta \end{aligned}$$
(6)

For example the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(2\alpha +2\beta \). But if the coordinates of the squares are (0.5,0.5) and (3.5,0.5), then \(w(1)=3\) and \(w(2)=0\). In this case the weighted distance is equal to \(2\alpha +2\beta \), too. This is not equal to \(2\beta \cdot \min \{w(i)\}+\alpha \cdot (\max \{w(i)\}-\min \{w(i)\})\), which value is \(3\alpha \).

4.3 Case \(2\beta \le \alpha \)

Every \(\alpha \)-step can be substituted by two consecutive \(\beta \)-steps. Moreover on a diagonal way, a vertical and after that another horizontal \(\alpha \)-step can be substituted by two consecutive parallel diagonal \(\beta \)-steps. It means that in every two steps the maximum of the absolute value of the coordinate differences is decreasing by 1. Thus if p and q are octagons, then

$$d(p,q;\alpha ,\beta )=2\beta \cdot \max \{w(i)\}.$$

It means that for example \(d((0,0),(3,1);\alpha ,\beta )=6\beta \).

If p and q are an octagon and a square, then the minimal path contains the minimal path between two octagons and a final step between an octagon and a square. Thus

$$d(p,q;\alpha ,\beta )=2\beta \cdot \max \{\lfloor w(i)\rfloor \}+\beta =2\beta \cdot \max \{w(i)\}.$$

For example \(d((0,0),(3.5,1.5);\alpha ,\beta )=7\beta \).

If p and q are squares, then the minimal path contains the minimal path between two octagons and the starting and the final step between an octagon and a square (Of course if the two squares are semi-neighbors, the minimal path contains only two steps: the first and the final step.). Thus

$$d(p,q;\alpha ,\beta )=2\beta \cdot \max \{\lfloor |w(i)-0.5|\rfloor \}+2\beta =2\beta \cdot \max \{w(i)\},$$

because \(\max \{w(i)\}\ge 1\), and that case \(\max \{\lfloor |w(i)-0.5|\rfloor \}=\max \{w(i)\}-1\). For example the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(6\beta \).

5 Minimum Weighted Paths by Using the Semi-neighbor Step

In this case the \(\gamma \)-weighted step is not forbidden and thus, extended weighted distances are obtained. The relative weights give the separation of the possible cases again.

5.1 Case \(\alpha \le \beta \)

Case \(\varvec{\alpha \le \beta \le \gamma }\) . If p and q are octagons, then similarly to the basic case, when \(\alpha \le \beta \), the minimal path can be constructed only by \(\alpha \)-steps. In every \(\alpha \)-step the absolute value of a coordinate difference is decreasing by 1. Every \(\gamma \)-step decreases the absolute value of a coordinate difference only by 1, too. Thus, the use of \(\gamma \)-steps is not efficient, because \(\alpha \le \gamma \). It means that \(d(p,q;\alpha ,\beta ,\gamma )\) is computed by Eq. 1, i.e., it is \(\alpha \cdot (w(1)+w(2))\).

Similarly, if p and q are an octagon and a square, this solution does not use \(\gamma \)-steps, either. Thus Eq. 2 produces \(d(p,q;\alpha ,\beta ,\gamma ) =\alpha \cdot (\lfloor w(1)\rfloor +\lfloor w(2)\rfloor )+\beta .\)

If p and q are squares, then the solution of the basic case contains two \(\beta \)-steps. If these two steps are the same in coordinates (for example \((+0.5,+0.5)\), then we could only change them by two \(\gamma \)-steps, but it is not efficient.

If \(\min \{w(i)\}\ge 1\), then these two \(\beta \)-steps are the same in coordinates, i.e. the solution in this case is the original, see Eq. 3. For example the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(2\alpha +2\beta \).

But if \(\min \{w(i)\}=0\), then one coordinate of the two \(\beta \)-steps is different (for example \((+0.5,+0.5)\) and \((+0.5,-0.5)\)). In this case we can change it only by one \(\gamma \)-step. For example if \(\gamma \le 2\beta \); \(\min \{w(i)\}=0\) and \(\max \{w(i)\}=1\), then the minimal path contains only one \(\gamma \)-step (without two \(\beta \)-steps).

If \(\min \{w(i)\}=0\), we have two alternative paths:

  1. (1)

    \(\max \{w(i)\}\) \(\gamma \)-steps, the total weight of it is \(\gamma \cdot \max \{w(i)\}\),

  2. (2)

    the first and the last steps are \(\beta \)-steps between squares and octagons; and between these steps there are \(\max \{w(i)\}-1\) \(\alpha \)-steps, so the total weight of it is \(2\beta +\alpha \cdot (\max \{w(i)\}-1)\).

If \(\max \{w(i)\}\)=1, then (1) is the minimal path with weight \(\gamma \), because \(\gamma \le 2\beta \). Otherwise path (1) is the minimal one, if

$$\max \{w(i)\}\le \frac{2\beta -\alpha }{\gamma -\alpha }.$$

Thus if \(\min \{w(i)\}=0\), then

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\left\{ \begin{array}{ll} \gamma \cdot \max \{w(i)\}, &{} \mathrm{if}\,\max \{w(i)\}\le \frac{2\beta -\alpha }{\gamma -\alpha }; \\ \alpha \cdot (\max \{w(i)\}-1)+2\beta , &{} \mathrm{if}\,\max \{w(i)\}\ge \frac{2\beta -\alpha }{\gamma -\alpha }. \end{array} \right. \end{aligned}$$

For example, the weighted distance of the squares (0.5,0.5) and (3.5,0.5) is \(3\gamma \) or \(2\alpha +2\beta \).

Case \(\varvec{\alpha \le \gamma \le \beta }\) . Similarly to the previous case the use of \(\gamma \)-steps instead of \(\alpha \)-steps is not efficient, because \(\alpha \le \gamma \). It means that the minimal path between two octagons, and between an octagon and a square is the same as in the previous case.

If p and q are squares, then the solution of the original case contains two \(\beta \)-steps. It means that minimal path can contain only \(\gamma \)-steps, because \(\gamma \le \beta \).

In this case we have two alternative paths:

  1. (1)

    The original path, see Eq. 3, \(\alpha \cdot (\lfloor |w(1)-0.5|\rfloor +\lfloor |w(2)-0.5|\rfloor )+2\beta \).

  2. (2)

    The path containing only \(\gamma \)-steps, the total weight of it is \(\gamma (w(1)+w(2))\). The minimal path is the better one.

Case \(\varvec{\gamma \le \alpha \le \beta }\) . If p and q are squares, then the minimal path can be constructed only by \(\gamma \)-steps. In every step the absolute value of a coordinate difference is decreasing by 1. Thus

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (w(1)+w(2)).$$

For example, the weighted distance of the squares (0.5,0.5) and (3.5,0.5) is \(3\gamma \).

Similarly, if p and q are an octagon and a square, then the minimal path contains one \(\beta \)-step and only \(\gamma \)-steps. This solution does not use \(\alpha \)-steps, either. Thus

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (\lfloor w(1)\rfloor +\lfloor w(2)\rfloor )+\beta .$$

For example \(d((0,0),(3.5,1.5);\alpha ,\beta ,\gamma )=4\gamma +\beta \).

If p and q are octagons, then the two alternative path are following:

  1. (1)

    The original minimal path, the total weight of it is \(\alpha \cdot (w(1)+w(2))\).

  2. (2)

    The path containing two \(\beta \)-steps (the first and the last) and only \(\gamma \)-steps, the total weight of it is \(\gamma \cdot (\lfloor |w(1)-0.5|\rfloor +\lfloor |w(2)-0.5|\rfloor )+2\beta \). The minimal path is the better one.

5.2 Case \(\beta \le \alpha \le 2\beta \)

Case \(\varvec{\beta \le \alpha \le 2\beta \le \gamma }\) . Every \(\gamma \)-step can be substituted by two consecutive \(\beta \)-steps. If \(2\beta \le \gamma \), then the use of \(\gamma \)-steps is not efficient. It means that the computing the distances is the same as we did it above in the basic case.

Case \(\varvec{\beta \le \alpha \le \gamma \le 2\beta }\) . If at least one of p and q is an octagon then neither the \(\beta \)-steps, nor the \(\alpha \) steps can be substituted by \(\gamma \) steps in economic way. It means, that still the formulae (4) and (5) give the distances.

If both p and q are squares and \(\min \{w(i)\}\ge 1\), then the solution of the basic case contains only \(\beta \)-steps with same coordinates. It means that the use of \(\gamma \)-steps is not efficient, the solution is given by the original Eq. 6.

But if \(\min \{w(i)\}=0\), then one coordinate of the two \(\beta \)-steps is different (for example \((+0.5,+0.5)\) and \((+0.5,-0.5)\)). In this case we can change it only by one \(\gamma \)-step.

If \(\min \{w(i)\}=0\), we have two alternative paths:

  1. (1)

    \(\max \{w(i)\}\) \(\gamma \)-steps, the total weight of it is \(\gamma \cdot \max \{w(i)\}\),

  2. (2)

    the first and the last steps are \(\beta \)-steps between squares and octagons; and between these steps there are \(\max \{w(i)\}-1\) \(\alpha \)-steps, so the total weight of it is \(2\beta +\alpha \cdot (\max \{w(i)\}-1)\).

If \(\max \{w(i)\}\)=1, then (1) is the minimal path with weight \(\gamma \), because \(\gamma \le 2\beta \). Otherwise path (1) is the minimal one, if

$$\max \{w(i)\}\le \frac{2\beta -\alpha }{\gamma -\alpha }.$$

Thus if \(\min \{w(i)\}=0\), then

$$d(p,q;\alpha ,\beta ,\gamma )=\left\{ \begin{array}{ll} \gamma \cdot \max \{w(i)\}, &{} \mathrm{if}\,\max \{w(i)\}\le \frac{2\beta -\alpha }{\gamma -\alpha }; \\ \alpha \cdot (\max \{w(i)\}-1)+2\beta , &{} \mathrm{if}\,\max \{w(i)\}\ge \frac{2\beta -\alpha }{\gamma -\alpha }. \end{array} \right. $$

For example the weighted distance of the squares (0.5,0.5) and (3.5,0.5) is \(3\gamma \) or \(2\alpha +2\beta \).

Case \(\varvec{\beta \le \gamma \le \alpha \le 2\beta }\) . If p and q are squares, then the use of \(\alpha \)-steps is not efficient, because \(\gamma \le \alpha \). If two \(\beta \)-steps are the same in coordinates (for example \((+0.5,+0.5)\), then we could only change them by two \(\gamma \)-steps, but it is not efficient. But if one coordinate of two consecutive \(\beta \)-steps is different (for example \((+0.5,+0.5)\) and \((+0.5,-0.5)\)), then we can change it by one \(\gamma \)-step. It means that:

$$d(p,q;\alpha ,\beta ,\gamma )=2\beta \cdot \min \{w(i)\}+\gamma \cdot (\max \{w(i)\}-\min \{w(i)\}).$$

For example the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(2\beta +2\gamma \).

Similarly, if p and q are a square and an octagon, then the minimal path contains the minimal path between two squares and a final step between a square and an octagon. Thus,

$$\begin{aligned}&d(p,q;\alpha ,\beta ,\gamma )=2\beta \cdot \min \{\lfloor w(i)\rfloor \}+\gamma \cdot (\max \{\lfloor w(i)\rfloor \}-\min \{\lfloor w(i)\rfloor \})+\beta = \nonumber \\&\qquad \qquad \,\;\;\, =2\beta \cdot \min \{w(i)\}+\gamma \cdot (\max \{w(i)\}-\min \{w(i)\}). \end{aligned}$$

For example, \(d((0,0),(3.5,1.5);\alpha ,\beta ,\gamma )=3\beta +2\gamma \).

If p and q are octagons, and \(\min \{w(i)\}\ge 1\), then the solution of the basic case contains \(\beta \)-steps. In this case we are able to change \(\alpha \)-steps to \(\gamma \)-steps (first and final steps need to be \(\beta \)-step). Thus in this case:

$$d(p,q;\alpha ,\beta ,\gamma )=2\beta \cdot \min \{w(i)\}+\gamma \cdot (\max \{w(i)\}-\min \{w(i)\}).$$

For example the weighted distance of the octagons (0,0) and (3,1) is \(2\beta +2\gamma \).

In any other cases if \(\min \{w(i)\}=0\), we have two alternative paths:

  1. (1)

    \(\max \{w(i)\}\) \(\alpha \)-steps, the total weight of it is \(\alpha \cdot \max \{w(i)\}\),

  2. (2)

    the first and the last steps are \(\beta \)-steps between octagons and squares; and between these steps there are \(\max \{w(i)\}-1\) \(\gamma \)-steps, so the total weight of it is \(2\beta +\gamma \cdot (\max \{w(i)\}-1)\).

If \(\max \{w(i)\}\)=1, then (1) is the minimal path with weight \(\alpha \), because \(\alpha \le 2\beta \). Otherwise path (1) is the minimal one, if

$$\max \{w(i)\}\le \frac{2\beta -\gamma }{\alpha -\gamma }.$$

Thus if \(\min \{w(i)\}=0\), then

$$d(p,q;\alpha ,\beta ,\gamma )=\left\{ \begin{array}{ll} \alpha \cdot \max \{w(i)\}, &{} \mathrm{if}\,\max \{w(i)\}\le \frac{2\beta -\gamma }{\alpha -\gamma }; \\ \gamma \cdot (\max \{w(i)\}-1)+2\beta , &{} \mathrm{if}\,\max \{w(i)\}\ge \frac{2\beta -\gamma }{\alpha -\gamma }. \end{array} \right. $$

For example the weighted distance of the octagons (0,0) and (3,0) is \(3\alpha \) or \(2\gamma +2\beta \).

Case \(\varvec{\gamma \le \beta \le \alpha \le 2\beta }\) . If p and q are squares, then the minimal path can be constructed only by \(\gamma \)-steps. Thus

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (w(1)+w(2)).$$

For example, the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(4\gamma \).

Similarly, if p and q are a square and an octagon, then the minimal path contains the minimal \(\gamma \)-path between two squares and a final \(\beta \)-step between a square and an octagon. Thus,

$$\begin{aligned} d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (\lfloor w(1)\rfloor \ + \lfloor w(2)\rfloor )+\beta . \end{aligned}$$

For example, \(d((0,0),(3.5,1.5);\alpha ,\beta ,\gamma )=4\gamma +\beta \).

If p and q are octagons, and \(\min \{w(i)\}\ge 1\), then the solution contains two \(\beta \)-steps (first and last steps), and \(\gamma \)-steps between them. In this case we are able to change all steps to \(\alpha \)-steps, but it is not efficient, because all \(\beta \)-steps and all \(\gamma \)-steps decrease the absolute value of the coordinate difference by 1 (It is not true in case of \(\min \{w(i)\}=0\), when the two \(\beta \)-steps are not the same in coordinates.). Thus in this case:

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (\lfloor |w(1)-0.5|\rfloor \ + \lfloor |w(2)-0.5|\rfloor )+2\beta .$$

For example the weighted distance of the octagons (0,0) and (3,1) is \(2\gamma +2\beta \).

In any other cases if \(\min \{w(i)\}=0\), we have two alternative paths as in the previous case (All is similar.). Thus if \(\min \{w(i)\}=0\), then

$$d(p,q;\alpha ,\beta ,\gamma )=\left\{ \begin{array}{ll} \alpha \cdot \max \{w(i)\}, &{} \mathrm{if}\,\max \{w(i)\}\le \frac{2\beta -\gamma }{\alpha -\gamma }; \\ \gamma \cdot (\max \{w(i)\}-1)+2\beta , &{} \mathrm{if}\,\max \{w(i)\}\ge \frac{2\beta -\gamma }{\alpha -\gamma }. \end{array} \right. $$

5.3 Case \(2\beta \le \alpha \)

Case \(\varvec{2\beta \le \alpha }\) and \(\varvec{2\beta \le \gamma }\) . If \(2\beta \le \gamma \), then using of \(\gamma \)-steps is not efficient. It means that the computing the distances is the same as we did it in the basic case.

Case \(\varvec{\beta \le \gamma \le 2\beta \le \alpha }\) . If p and q are squares, then similarly to the basic case, when \(2\beta \le \alpha \), the minimal path can be constructed only by \(2\beta \)-steps (\(\alpha \)-steps are not efficient at all when \(\alpha >2\beta \)). Every \(\gamma \)-step decreases the sum of the absolute value of coordinate differences by 1. It means, that if two consecutive \(\beta \)-steps decrease the sum of the absolute value of the coordinate differences by 1, too, then the use of \(\gamma \)-steps is efficient. But if two consecutive \(\beta \)-steps are parallel diagonal steps, then we are able only to change them for two \(\gamma \)-steps and it is not efficient. It means that

$$d(p,q;\alpha ,\beta ,\gamma )=2\beta \cdot \min \{w(i)\}+\gamma \cdot (\max \{w(i)\}-\min \{w(i)\}).$$

For example the weighted distance of the octagons (0,0) and (3,1) is \(2\beta +2\gamma \).

If p and q are a square and an octagon, then the minimal path contains the minimal path between two squares and a final step between a square and an octagon (the use of \(\alpha \)-steps is not efficient). Thus

$$\begin{aligned}&d(p,q;\alpha ,\beta ,\gamma )=2\beta \cdot \min \{\lfloor w(i)\rfloor \}+\gamma \cdot (\max \{\lfloor w(i)\rfloor \}-\min \{\lfloor w(i)\rfloor \})+\beta =\nonumber \\&\qquad \qquad \,\;\;\,=2\beta \cdot \min \{w(i)\}+\gamma \cdot (\max \{w(i)\}-\min \{w(i)\}). \end{aligned}$$

For example \(d((0,0),(3.5,1.5);\alpha ,\beta ,\gamma )=3\beta +2\gamma \).

Finally, if p and q are octagons, then the minimal path contains the minimal path between two squares and the starting and the final step between an octagon and a square. Thus

\(d(p,q;\alpha ,\beta ,\gamma )=\)

$$2\beta \cdot \min \{\lfloor |w(i)-0.5|\rfloor \}+\gamma \cdot (\max \{\lfloor |w(i)-0.5|\rfloor \}-\min \{\lfloor |w(i)-0.5|\rfloor \})+2\beta .$$

For example the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(2\gamma +2\beta \).

Case \(\varvec{\gamma \le \beta }\) and \(\varvec{2\beta \le \alpha }\) . If p and q are squares, then the minimal path can be constructed only by \(\gamma \)-steps. Thus

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (w(1)+w(2)).$$

For example, the weighted distance of the squares (0.5,0.5) and (3.5,1.5) is \(4\gamma \).

Similarly, if p and q are a square and an octagon, then the minimal path contains the minimal \(\gamma \)-path between two squares and a final \(\beta \)-step between a square and an octagon. Thus,

$$d(p,q;\alpha ,\beta ,\gamma )=\gamma \cdot (\lfloor w(1)\rfloor \ + \lfloor w(2)\rfloor )+\beta .$$

For example, \(d((0,0),(3.5,1.5);\alpha ,\beta ,\gamma )=4\gamma +\beta \).

If p and q are octagons, and \(\min \{w(i)\}\ge 1\), then the solution contains two \(\beta \)-steps (first and last steps), and \(\gamma \)-steps between them. Thus in this case:

For example the weighted distance of the octagons (0,0) and (3,1) is \(2\gamma +2\beta \).

Table 1. Value of \(d(p,q;\alpha ,\beta ,\gamma )\) (or \(d(p,q;\alpha ,\beta )\) in Basic case shown as ‘B’)

6 Summary and Further Thoughts

Minimal weighted paths can obviously computed by Dijkstra algorithm. However, based on the regular structure of the grid and by the help of an appropriate coordinate system direct formulae are provided to compute them. There are various cases depending on the relation of the used weights. A summary of the results is shown in Table 1 for various cases. Note that each of the distance functions detailed in this manuscripts are metric. It is a task of a future study to compare these new distance functions to other, well-known digital distances. Digital disks are usually defined based on digital distances to analyse various properties of these distances. It is noted (see, e.g., Subsect. 4.2) that in some cases digital disks based on weighted distances on the grid T(8,8,4) have holes, i.e., they are not digitally convex (in any sense). It is a future work to describe and analyze these digital disks, develop algorithms for distance transform etc. Measuring the approximation quality of the Euclidean distance is also a usual task with digital distances: based on that, optimal weights can also be computed. We believe that the nice topological properties of the Khalimsky grid can effectively be used in various applications using the weighted distances.