On Chamfer Distances on the Square and Body-Centered Cubic Grids: An Operational Research Approach

Linear programming is used to solve optimization problems. -us, finding a shortest path in a grid is a good target to apply linear programming. In this paper, specific bipartite grids, the square and the body-centered cubic grids are studied. -e former is represented as a “diagonal square grid” having points with pairs of either even or pairs of odd coordinates (highlighting the bipartite feature). -erefore, a straightforward generalization of the representation describes the body-centered cubic grid in 3D. We use chamfer paths and chamfer distances in these grids; therefore, weights for the steps between the closest neighbors and steps between the closest same type points are fixed, and depending on the weights, various paths could be the shortest one. -e vectors of the various neighbors form a basis if they are independent, and their number is the same as the dimension of the space studied. Depending on the relation of the weights, various bases could give the optimal solution and various steps are used in the shortest paths. -is operational research approach determines the optimal paths as basic feasible solutions of a linear programming problem. A directed graph is given containing the feasible bases as nodes and arcs with conditions on the used weights such that the simplexmethodmay step from one feasible basis to another one.-us, the optimal bases can be determined, and they are summarized in two theorems. If the optimal solution is not integer, then the Gomory cut is applied and the integer optimal solution is reached after only one Gomory iteration. Chamfer distances are frequently used in image processing and analysis as well as graphics-related subjects. -e body-centered cubic grid, which is well-known in solid state physics, material science, and crystallography, has various applications in imaging and graphics since less samples are needed to represent the signal in the same quality than on the cubic grid. Moreover, the body-centered cubic grid has also a topological advantage over the cubic grid, namely, the neighbor Voronoi cells always share a full face.


Introduction
Grids have a significant role not only in crystallography, material science, and solid state physics but also in various engineering applications, e.g., in image processing and in digital geometry [1].
ere is a large variety of ways to tessellate the plane and the three dimensional space. Regular grids in 2D are the square, the hexagonal, and the triangular grids, and the only regular grid in 3D is the cubic grid [2,3]. e square and the cubic grids are most popular grids since their coordinate systems are the Cartesian coordinate systems. ey are considered as the traditional grids. One of the earliest results on the square grid is the introduction of chessboard and cityblock motions which is given in [4]. e dual of the square grid is again a square grid, whereas the hexagonal and the triangular grids are duals of each other.
e hexagonal grid has a useful symmetric coordinate frame, and every pixel, also called hexel [5], has six neighbors. e triangular grid is also described by the symmetric coordinate system. e useful descriptions of these grids by three coordinates are given in [6][7][8]. ese two regular grids are also studied from various points of view such as topological/combinatorial coordinate systems [9] and applied in discrete tomography [5,10,11].
Irregular grids are also applied in various places, e.g., triangulation in computer graphics. ese grids are usually ad hoc and miss any type of structure. On the other hand, there are various well-structured grids. Two of the nontraditional grids in 3D are the body-centered Cubic (BCC) and the face-centered cubic (FCC) grids. ey provide structures of various solid materials, and thus they play crucial importance in crystallography. ey are alternative to the cubic grid in various engineering applications. ese grids have many application areas, e.g., image processing [12], visualization [13], and topology preserving digitization [14]. It is worth noting that the FCC and BCC grids are point lattices. Further, BCC and FCC grids are generalizations of the hexagonal grid to 3D. Especially, in the hexagonal grid, there is only one usual neighborhood relation among the hexagon-shaped tiles/pixels, and two neighbor hexagons share a full side. e BCC grid generalizes this property to 3D, i.e., both of the used types of neighbor relations are among voxels such that either a full hexagon face or a square face is shared between the neighbor voxels. is topological advantage of the BCC grid can be used, e.g., by combinatorial coordinate systems in boundary tracking [15]. Moreover, the BCC grid is proven to have some better properties in applications than the cubic grid [16][17][18] highlighting the importance of our study. In electronic imaging, it is important what kind of mesh we scan the object according to. BCC grid is often used for this purpose [19]. Further, the BCC grid also plays an important role in the latest chapters of material science [20].
In 2D, one of the irregular grids is the Khalimsky grid. In this grid, the 4-neighbor and the 8-neighbor relations are used for the points of the grid, alternately, depending on their positions. Khalimsky's topology on the integers is introduced by Efim Khalimsky [21,22]. is topology is a digital counterpart of the Euclidean topology on the real line and is useful in connection with digital geometry. Digital geometry of the 2D Khalimsky grid is studied, e.g., in [23].
In digital geometry, the distance between two points is defined by the number of steps in a shortest path connecting these points [1,3,4]. An algorithm which finds the shortest path and also their number between arbitrary two points in the square grid is given in [24]. Distance on the hexagonal grid is computed in [25]. Moreover, in [8], an algorithm, which produces the shortest path between two arbitrary points of the hexagonal grid is introduced. Weighted distances play also an important role in image processing, e.g., morphological filtering [26]. Weighted distances (chamfer distances) are also studied in various grids [23,27,28]. One may think about to finding a minimal path (and so, to determine the digital distance) as an optimization problem. We should note here that there are various shortest path algorithms in graph theory and in artificial intelligence [29], but those algorithms, e.g., Dijkstra algorithm (see, e.g., in [1]), are very general and do not take into account the very definite structures of the grids used in digital geometry. For this reason, both of their space and time complexities are much worse than the complexities of some more specific algorithms ( [8]) and computations. Our aim here is to provide direct formulae for the distance computation.
Another important subject of our work is linear programming. Linear programming is an optimization problem. e objective function is linear, the constraints are linear equations, and the variables are nonnegative. e linear programming was discovered by George Dantzig in 1947. He published the simplex method in 1949 [30]. It is still one of the most effective methods of linear optimization. A great advantage of the simplex method is that its theory is a complete geometric description of the structure of the problem. In this paper, the results are based on the optimality criterion of the method. It is important to know that if optimal solution exists, then an optimal solution must exist among finitely many points.
ey are the so-called basic feasible solutions. Each such point belongs to a linear basis of the columns of the matrix of the equation system.
In the next section, as a preliminary part, we recall the simplex method and the Gomory cut [31] from operational research. In this paper, the 2D square grid and the 3D BCC grid are studied. eir formal description is given in Section 3. Both of these grids are bipartite grids (according to the new concept, we investigate in Subsection 3.1). Actually, we use an unusual description of the square grid which is somewhat related to the coordinate system we have invented for the Khalimsky grid (see, e.g., [23]). In this novel representation that we named as "diagonal square grid," the closest neighbor points are represented by coordinates with different parities (see the details in Subsection 3.2). Although the square grid is the most known, the new description gives us a new way of view that allows us to make an analogous study in nontraditional higher dimensional grids, as we do also in the 3D BCC grid. Section 4 shows our linear programming model for each grid in its subsections, respectively. Depending on the relation of the weights assigned to the two types of neighbors, various bases could give the optimal solution, i.e., various types (and directions) of steps could be used in the shortest paths. If the optimal solution is not integer (one case of both problems), then the so-called Gomory cut cuts the noninteger solutions, and the integer optimal solution is reached after only one Gomory iteration. Our theorems can easily be applied by knowing the fixed weights for the two types of neighbors; the distance of any two points can be computed directly, as we show it in examples. It is widely known that weighted distances were already studied both in the square and the BCC grids; however, our approach has not been applied yet, by giving a nice relation between digital geometry and linear programming. Moreover, our approach, up to our knowledge, is more general than the study, e.g., in [32,33] since the case when closest neighbors get a larger weight than the second closest neighbors is not studied yet in detail for the BCC grid. In this way, our results also complement the previous knowledge on this field. Finally, the paper is closed by a concluding section.

Methods: On the Simplex Method and the
Gomory Cuts e simplex method of linear programming solves an optimization problem given in the form as follows: where A is an m × n matrix, b is an m-dimensional vector, c is an n-dimensional vector of constants, and x is the n-dimensional vector of variables. e constraints determine a polyhedral set. What is called the corner point in the usual geometry is called extreme point here. A point is an extreme point of the polyhedral set if it is the only intersection point of the polyhedral set and a hyperplane. e extreme points of the polyhedral set of the linear programming problem are the so called basic feasible solutions. For the sake of simplicity, assume that the rank of matrix A is m. Let B be a subset of the columns of A such that the vectors of B form a basis. e matrix formed from the elements of B is an m × m matrix. It is also denoted by B. Assume that matrix A and vector x are partitioned accordingly, i.e., A � (B, N) and . e basic solution of basis B is obtained if x satisfies the equation system, and its x N part is 0. It can be obtained as follows: Hence, us, the x B part of the basic solution is An important consequence of the linearity, that if optimal solution exists, then at least one basic feasible solution is optimal.
Roughly speaking, the finite versions of the simplex method start from a basic feasible solution. It improves the solution by stepping to another basic feasible solution along an edge of the polyhedral set. It repeats this step until it recognizes that the current extreme point is optimal. is property also proves that the set of edges of a convex polyhedral set is a connected graph.
Gomory's method of integer programming is based on the observation that the basic variables are expressed by the other variables in the form of the equation system (3). Assume that one of this equation is where K is the index set of the nonbasic variables. Assume further on, that d i0 is noninteger. It is the current value of the integer variable x i . Let f j be the fractional part of the coefficient, i.e., the fractional part of d tj : Let us substitute these quantities into the equation. If the equation is rearranged such that all terms which are integer for sure are in the left-hand side, the new form of the equation is obtained as follows: Hence, All the coefficients of this relation are between 0 and 1. us, the two sides can be congruent only if the value of the right-hand side is in the set {f 0 , f 0 + 1, f 0 + 2, . . . }. Hence, the inequality is inequality is not satisfied by the current basic feasible solution as the values of the variables in the sum are all 0. is inequality is the Gomory cut.

Formal Descriptions of the Diagonal Square Grid and the BCC Grid
In this paper, we are focusing on two grids, the first is the 2D square grid but with a nontraditional description, while the second one is the body-centered cubic grid. We use a nontraditional view to represent the square grid in such a way that its description generalizes to 3D exactly in a way that produces a description of the BCC grid.

On Bipartite Grids.
One may connect the closest neighbor point pairs of a grid by edges. erefore, grids can be seen as infinite graphs with a kind of regular, periodic structure. Various grids could have various (graph-theoretic) properties. We call a graph and thus also a grid "bipartite" if there it does not contain any odd cycle. It is easy to see that the square grid is bipartite, and this well-known property is reflected, e.g., by the coloring of a chessboard: the two partitions of the points (i.e., pixels and fields in the usual square grid terminology) are colored by two different colors, e.g., black and white. e cubic and also the BCC grids are bipartite, as well as, the triangular and the diamond grids (moreover, these two latter grids are not point lattices, the relation of the two partitions-called also types or parities of the points in these cases-does not provide closure under translations). On the other hand, it is also easy to show grids which are not bipartite, e.g., the hexagonal or the FCC grids (in both of these grids, 3 cycles-i.e., triangles-exist among closest neighbor points). Now, for bipartite grids, it is interesting to see what is the grid structure of the partitions and what is the type of the subgrids. At the case of triangular grid, each of the partitions of the even and odd points forms a hexagonal subgrid. e even and odd points of the Mathematical Problems in Engineering diamond grid have the structure of two separate FCC subgrids. e two partitions of the BCC grid are cubic subgrids. Finally, each partition of the square grid is again a square grid. In the next subsection, by showing an unusual coordinate system for the square grid, we underline its bipartite property.

3.2.
e Diagonal Square Grid: Reflecting the Bipartite Property of the Grid. We use a 45°rotation of the usual square grid, and we call this representation and description as the diagonal square grid (see Figure 1). e two coordinates are used in a similar manner, as we have described the so-called Khalimsky grid in [23,34], but in this paper, we consider every point/pixel of the grid with the same connectedness, i.e., the same neighborhood. In this way, although the coordinate pairs of the represented points/pixels are similar to those that are used for the Khalimsky grid, our description fits to the square grid, which is in fact, a regular grid and it represents a point lattice at the same time. We note here that in the mentioned papers, integer coordinate pairs addressed half of the points of the grid, while coordinate pairs having value integer plus a half the other half of the points. In contrast to this, here, we prefer to use only integer coordinates (by multiplying each of the Khalimsky coordinates by 2); thus, we have two subgrids as follows. e even-subgrid is built up by the points (or squares, depending on the representation used) addressed by a pair of even coordinates. e odd-subgrid is built up by points addressed by odd coordinate pairs. Consequently, we call the points even or odd depending on the fact which subgrid they belong. It is worth noting that both the even and the odd subgrids are square grids themselves, and our grid which is the union of these two subgrids is also a square grid. e traditional 4-neighborhood relation consists of pairs of points that are different types and closest to each other (i.e., always an even and an odd point). ey are depicted by vectors (±1, ±1). Additionally, the traditional 8-neighborhood contains also the pairs of the closest same type points (i.e., two even or two odd points). ey are described by vectors (±2, 0) and (0, ±2). In Figure 2, part (a) shows also a part of this grid (in the dual representation, showing "grid points"-i.e., midpoints of the pixels-instead of pixels) with the assigned coordinate pairs of the points, and the neighbors of the point (0, 0) are also shown. Chamfer distances are defined first on the square grid [35,36]. Based on the two classical neighborhoods, assigning weight a for steps between the closest neighbors (examples are shown by pink lines) and weight b for the steps between the second closest neighbors (examples are shown by black lines), the shortest weighted path between two points gives their chamfer (or weighted) distance. e paths we refer here are built in graph-theoretic sense by consecutive steps between (various type of ) neighbor points of the grid.

A (Usual) Coordinate
System for the BCC Grid. Now, as a straightforward generalization of the previous description, one can obtain the grid which is the union of the two 3D subgrids: the grid of even points (addressed by triplets of even numbers) and the grid of odd points (addressed by triplets of odd numbers). Here, both the even and the odd subgrids are cubic grids, and their union is actually the BCC grid [32,33] (see also Figure 2, part (b)), where the "grid point" representation of the diagonal square grid can easily be generalized from two to three dimensions. For explanation, we recall that, e.g., the caesium chloride (CsCl) has such 3D structure: the caesium ions are represented by black balls and the chloride ions are represented by red-while balls. In the BCC grid, there are also two usual neighborhoods. e closest neighbor points are different type, and each point has 8 of them (as a chloride ion has 8 caesium ion neighbors). ey are described by vectors (±1, ±1, ±1) (in Figure 2, part (b), the eight closest neighbors of the point (−1, 1, 1) are also highlighted, pink color is used to connect those neighbors, and their Euclidean distance is � 3 √ /2 times the length of the edge of the cubes of the unit cell, which is 2 here to ensure to use only integer coordinates to address the points of the grid). On the other hand, the second closest neighbors are actually the closest neighbors inside a given subgrid; that is, they are the closest same type points. Each point has 6 such neighbors, and they are described by vectors of the form (±2, 0, 0), (0, ±2, 0) and (0, 0, ±2) as, e.g., a chloride ion has 6 closest chloride ion neighbors. Actually, every point pair having their distance exactly the same as the length of the edge (shown by black lines on the figure) of a unit cell are representing two such neighbors. By our coordinate system, this length is exactly 2. Chamfer distances on the BCC grid can be defined analogously to the way they have been defined on the (diagonal) square grid: steps between two closest neighbor points (shown, e.g., by pink line in Figure 2) have weight a, while between the closest same type points (connected, e.g., by black line) weight b is used. en, the weighted length of a corresponding shortest path connecting the points gives the chamfer distance of the points. We note here that in the mentioned literature, one may found also results about the weighted distances; however, in this paper, we use an approach coming from operational research. Moreover, we study also the case in which the steps to the second closest neighbors have a smaller weight than the steps to the closest neighbors, i.e., b < a. erefore, we present not only a new approach but also some new results. We should also note here, that in 2D, the square grid and the diagonal square grid have the same structure, same number of neighbors, and so on. However, in 3D, the cubic and the BCC grids are two essentially different grids. e BCC grid is more compact than the cubic grid; both the number of closest neighbors and its packing density are larger than the corresponding values of the cubic grid.

Results and Discussion: The Linear
Programming Model Many problems of combinatorial optimization are actually linear programming problems. e shortest path problem in a finite graph has also its linear programming version. A grid can be represented by an infinite graph. erefore, the linear programming model is different. e matrices of the steps of the diagonal square grid and the 3-dimensional BCC grid are given in the matrices shown in formulae (9) and (10), respectively. e matrix of the diagonal square grid is as follows: e matrix of the BCC grid is as follows: It can be seen immediately that the matrix of the BCC grid is the generalization of the matrix of diagonal square grid to 3-dimension.
It is supposed that the paths start at the origins and those go to the target points which are (p, q) T and (p, q, r) T , respectively. As the grids are highly symmetric, it is enough to investigate just a segment of the plane. erefore, it is supposed that p > q > 0 and p > q > r > 0, respectively. All the components of the target points must be either even numbers or odd numbers. e lengths of the steps are positive numbers. e lengths of the vertical and horizontal steps are equal and are denoted by b. e lengths of the cross steps are equal, too, and it is denoted by a.

e Diagonal Square Grid.
e optimization model in the case of the diagonal square grid is as follows: x 1 , . . . , x 8 is integer.  (0, 0)), the two subgrids, and the assigned coordinate system. Mathematical Problems in Engineering 5 theory of the simplex method. If the solution is not integer, then the Gomory method of integer programming is applied. ere are 28 pairs of the columns of matrix (9). However, there are only six out of the 28 which give a feasible, i.e., nonnegative, solution of the equation system. According to the theory of linear programming, an optimal solution must be among these solutions. e optimal solution depends on the right-hand sides. Table 1 summarizes the six solutions. Instead of the columns, the variables are given. e only basis which may produce a fractional solution is basis 1. All other solutions are integer because the parities of p and q are the same. It is easy to see that the objective function value of the solution of basis 2 is smaller than the objective function values of the solutions of bases 3, 4, and 5.
us, only bases 1, 2, and 6 can be linearly optimal. If either basis 2 or basis 6 is linearly optimal, then it is the optimal solution of the integer programming problem, i.e., the optimal linear solution provided with the steps of the optimal path. e solution of basis 2 is better than the solution of basis 1 if and only if It is equivalent to b > a. (17) Similarly, the solution of basis 6 is better than the solution of basis 2 if and only if It is equivalent to Another calculation shows that the solution of basis 6 is better than the solution of basis 1 if and only if e multiplier 2p/(p + q) is between 1 and 2. us, when the solution of basis 6 is better than the solution of basis 2, it is already better than the solution of basis 1. e results can be summarized as follows. e only case which is not discussed yet is when b < a and both p and q are odd numbers. e starting point is the origin. Its coordinates are even numbers. us, at least one step must exists such that the parities of the coordinates change. It is equivalent to the inequality e first method of integer programming such that it could solve problems with unbounded integer variables was the Gomory method. It is still the most general method. It is a cutting plane method. It starts from the linear programming relaxation. If the optimal linear programming solution is not integer, then a cut is generated. It is called Gomory cut. It cuts the last linear programming optimal solution which is not integer. However, it does not cut any integer feasible solution. A new linear programming problem is generated in this way. It is solved by the lexicographic simplex method. Interestingly, the first Gomory cut is (21). e cut generation in this particular case is as follows. e simplex method works in a way such that the basic variables are expressed with the nonbasic variables. If x 1 and x 2 are the two basic variables, then the expression of x 1 is obvious.
Collecting all terms which are integer to the left-hand side, the new form of the equation is e right-hand side must be integer. As every term with the exception of the constant are nonpositive on the righthand side, the value of the right-hand side is a nonpositive integer implying that It is equivalent to (21). e lexicographic simplex method makes only one simplex iteration and immediately gets the integer optimal solution which is After describing our method in detail in this 2D case, we are ready to go to 3D and discuss and apply it on the BCC grid to obtain our main and most important results.

Number
Basic variables Solution e value of the objective function 1 If the optimal solution belonging to basis 1 is not integer, then the Gomory cut is e first lexicographic simplex iteration again finds the optimal solution which is As it can be seen from Figure 3, only five bases can be optimal. ey are in the rows 1, 2, 7, 14, and 15 of Table 2.
e order of steps of the minimal paths can be interchanged. Example 2. Let a � 1, b � 3, and (p, q, r) � (5, 3, 1). It is the fifth case of eorem 2. en, the optimal basis is basis (7,8,9) or basis (7,8,10). In the case of the basis (7,8,9), the solution is x 7 � 2, x 8 � 2, and x 9 � 1, and the length of the minimal path is 5. In the case of the basis (7,8,10), the solution is x 7 � 3, x 8 � 1, and x 10 � 1, and the length of the minimal path is 5, too. As we have proven, based on the respective ratio of the weight, the case can be easily determined, and direct formulae give the weighted distance. One may think that Dijkstra or other well-known shortest path algorithms from graph theory could be used, and it is true. However, their complexity is much worse, i.e., the time we need to get the result will be much longer. On the one hand, we cannot use the upper bound as the size of the graph since our grids are infinite. On the other hand, practically, of course only a finite segment of the grid could and will play role in shortest paths between two fixed points. However, the size of this segment is proportional to the third power of the largest coordinate difference of the points, which also implies a relatively large time complexity with respect to our approach. is means that the results presented in this paper give a more efficient way to determine weighted distances.

Conclusions
In this paper, it is shown that linear programming gives an efficient tool to find optimal solutions in some digital geometry problems. Chamfer distances on the square grid and on the BCC grid are studied. e BCC grid plays importance in solid state physics, crystallography, and material science since it describes the structure of the atoms/ions in various materials. is structure is more compact than the simple cubic structure and has various advantages also in engineering applications. e distances we have computed are based on weighted paths among the grid points. ese distances are useful in various applications (e.g., 2D and 3D image processing) since they could provide relatively good approximations of the Euclidean distance, but since they are step-based, efficient incremental algorithms, e.g., distance transform [37] can easily be adapted. Feasible and optimal bases are found for various cases of the used weights. We have also studied the case when the second closest neighbors can be reached by a smaller weighted step than the closest neighbors (up to our knowledge this has not been done before on the BCC grid). e structure of all optimal paths is explicitly given. Moreover, one needs to check only the respective ratio of the weights and then can easily choose the case, thus, an optimal path and the chamfer distance.
We believe that our method can easily be applied for other similar grids, similarly as we also used in the second part of the paper, where n-dimensional generalizations of the BCC are considered [38].

Data Availability
No data were used to support this study.