Acta Cybernetica 0 (0 399 47. Aroximation of the Euclidean Distance by Chamfer Distances András Hajdu, Lajos Hajdu, and Robert Tijdeman Abstract Chamfer distances lay an imortant role in the theory of distance transforms. Though the determination of the exact Euclidean distance transform is also a well investigated area, the classical chamfering method based uon small neighborhoods still outerforms it e.g. in terms of comutation time. In this aer we determine the best ossible maximum relative error of chamfer distances under various boundary conditions. In each case some best aroximating sequences are exlicitly given. Further, because of ossible ractical interest, we give all best aroximating sequences in case of small (i.e. and 7 7 neighborhoods. Keywords: Chamfering, Aroximation of the Euclidean distance, Distance transform, Digital image rocessing Introduction Suose we measure distances between grid oints of a two-dimensional grid and we want to aroximate the Euclidean distance by a distance function which can be comuted quickly, without calculating square roots. We may then use the class of chamfer distances. They are obtained by rescribing the lengths of the grid vectors in a so-called mask M := {(x, y Z : max( x, y } (for some ositive integer Research of the Hungarian authors was suorted in art by the OTKA grants F043090, T0498, T04879, K6780, K766, NK0680, by the János Bolyai Research Fellowshi of the Hungarian Academy of Sciences, by the TECH08- roject DRSCREEN - Develoing a comuter based image rocessing system for diabetic retinoathy screening of the National Office for Research and Technology of Hungary (contract no.: OM-0094/008, OM-009/008, OM- 0096/008, and by the TÁMOP 4.../B-09//KONV-00-0007 roject, which is imlemented through the New Hungary Develoment Plan, cofinanced by the Euroean Social Fund and the Euroean Regional Develoment Fund. Faculty of Informatics, University of Debrecen, H-400 Debrecen, P.O. Box, Hungary. E-mail: hajdu.andras@inf.unideb.hu Number Theory Research Grou of the Hungarian Academy of Sciences and Institute of Mathematics, University of Debrecen, H-400 Debrecen, P.O. Box, Hungary. E-mail: hajdul@math.unideb.hu Mathematical Institute, Leiden University. Niels Bohrweg, Leiden Postbus 9, 300 RA Leiden, The Netherlands. E-mail: tijdeman@math.leidenuniv.nl
400 András Hajdu, Lajos Hajdu, and Robert Tijdeman such that the values at (±x, ±y and (±y, ±x are all the same, and by defining the length function W as follows: the length W ( v of any vector v Z is defined as the minimal sum of the lengths of those vectors from M, reetitions ermitted, which have sum v. The literature on chamfer distances is very rich. See Borgefors [, 3, 4] for the basics, [7, 8] for lists of ( + ( + neighborhoods for 0, and [7] for an overview of alications. Further, recently many related results have been obtained by several authors, concerning distance transforms and their exlicit calculation using different kinds of neighborhoods in certain (mostly 3D grids. For examle, Strand, Nagy, Fouard and Borgefors [0] gave a sequential algorithm for comuting the distance ma using distances based on neighborhood sequences in the D square grid, and 3D cubic and so-called FCC and BCC cubic grids, resectively. Similar results for other kinds of grids are also known, see e.g. [6] (nd hexagonal grids, [] (diamond grid and [] (general oint grids and the references given there. Classical chamfer distances using 3 3, and 7 7 neighborhoods given by Borgefors [, 3] are generated by the masks 4 3 4 3 0 3 4 3 4, 4 0 4 7 7 0 0 0 7 7 4 0 4 and 43 38 36 38 43 43 34 7 4 7 34 43 38 7 7 7 7 38 36 4 0 4 36 38 7 7 7 7 38 43 34 7 4 7 34 43 43 38 36 38 43 resectively (with the actual generator entries underlined. For comarison with the Euclidean distance the values of the neighborhoods have to be divided by 3, and, resectively. The aroximations to.4 are therefore 4/3.33, 7/ =.4 and 7/.4, resectively. For alternative neighborhood values see Verwer [, 3], Thiel [], Coquin and Bolon [6], Butt and Maragos [] and Scholtus [7]. More secifically, in [6] the minimization of the error between the Euclidean distance and the local distance was considered over circular trajectories similarly to [, 3] rather than linear ones [3, ]. The aroximation error can also be measured based on area as it is done in [] with calculating the difference between a disk of large size obtained by chamfer metric and a Euclidean disk of the same radius. The determination of the exact Euclidean distance transform is also a well investigated area (see e.g. [, 7, 8, 3, 9], but the classical 3 3 chamfering method still outerforms it in terms of comutation time and simle extendability to other grids. In this aer we determine chamfer distances best aroximating the Euclidean distance in a certain sense. In each neighborhood size some best aroximating sequences are exlicitly given. Further, because of ossible ractical interest, we give all best aroximating sequences in case of small (i.e. and 7 7 neighborhoods. Throughout the aer, as a measure for the quality of a length function W
Aroximation of the Euclidean Distance by Chamfer Distances 40 defined on Z we use the so-called maximum relative error (m.r.error for short E := lim su W ( v v v where. denotes the Euclidean length. The M -, M - and M 3 -neighborhoods given above yield rounded E-values 0.07, 0.098 and 0.038, resectively. Firstly we shall rove that the smallest ossible constant E B for the mask M under the condition that W (x, 0 = x for x Z is given by E B = + + + + =. ( + O 4. In articular, E B 0.0, E B 0.087 and E3 B 0.0089. Comaring these values with the E-values given above, one can see that the E B -values yield aroximately 4%, 6% and 3% imrovement, resectively. The B refers to Borgefors who was the first to consider such neighborhoods. Secondly we consider the case D in which W ( v v for all v Z. (The D refers to the fact that W ( v dominates v. The otimal m.r.error under this restriction equals E D = ( + + = ( 8 + O 4 = 0. ( + O 4. In articular, E D 0.084, E D 0.07 and E3 D 0.03. Thirdly we shall rove that the otimal E-value without any restriction on the neighborhood defined on M (i.e. droing the condition W (x, 0 = x for x Z equals + + E C = + = ( 6 + + + O 4. In articular, E C 0.0396, E C 0.036 and E3 C 0.006. In 99, on using the symmetry in case C the value of E C was comuted by Verwer [, 3] in terms of trigonometric functions. The C refers to the word central. In 998, because of geometric considerations, Butt and Maragos [] chose to use the error function lim su v v W ( v which of course is small if and only if E C is small. In general it gives different error values, but the values for E C are equal to the values obtained by the above error function (cf. Scholtus [7]. We rove the correctness of the above E C values. In doing so, our motivation is twofold: on the one hand, by a simle reasoning we obtain these values immediately from the values of E D, and on the other hand, our
40 András Hajdu, Lajos Hajdu, and Robert Tijdeman roofs are mathematically rigorous while the corresonding arguments of Verwer and Butt and Maragos contain some hidden assumtions. Namely, by certain lausible but not exlicitly verified geometric arguments they restrict their attention and investigations to certain values of the neighborhoods in question, and they erform exact investigations only for these values. We shall further study an auxiliary class of neighborhoods on M, viz. the class of neighborhoods satisfying N c ( v = for all v = (x, y M with either x < or y < 0, N c ( v = for v = (, 0, and N c ( v = c v for v = (, k with 0 < k. Here c is a constant close to and at most equal to. Informally seaking, the use of such neighborhoods means that only such stes (v, v are allowed, where v is a ositive multile of and v is nonnegative. Further, beside N c (, 0 = the weights of the other such neighborhood vectors are their Euclidean lengths, multilied by a factor c. All the other vectors of the neighborhood are forbidden to use, thus they have weights. For examle, the weights for the neighborhood N c with = (i.e. for M are given by c 8 c where the origin is in the middle. We denote the maximum relative error for this class of neighborhoods by E c where we restrict the limsu to vectors v with finite lengths W ( v (i.e. having coordiantes (x, y with 0 y x and x. Our motivation for considering such neighborhoods is that it will turn out that (due to its secial form N c is easier to handle, but yields the same m.r.error as the corresonding neighborhood N c, in which N c (±, 0 = N c (0, ± = and N c (x, y = c x + y otherwise ((x, y M. In Section we introduce some notation and rove some reliminary results. In Sections 3 and 4 we comute the values of E B and E D where E B is the maximum relative error E c for otimal c and E D = E. We give all sequences yielding minimal m.r.error in case of and 7 7 neighborhoods, as well. In Section 4 we rove that E B = E B and E D = E D and further show that E C = E D /( + E D for all. Finally, we draw some conclusions in Section. Definitions and basic roerties Let N be a neighborhood defined on the mask M. Put M = M \ {(0, 0}. We denote the value of N at osition (n, k by w(n, k for (n, k M. Throughout the aer we assume that w(±n, ±k = w(±k, ±n > 0 for all (n, k M and all ossible sign choices. Hence it suffices to consider the values w(n, k with 0 k n. We can measure lengths of vectors and distances between oints using neighborhood sequences. Note that such sequences rovide a flexible and very useful
Aroximation of the Euclidean Distance by Chamfer Distances 403 tool in handling several roblems in discrete geometry. For the basics and most imortant facts about such sequences, see e.g. the aers [9, 4, 0,, 4] and the references given there. Here we only give those notions which will be needed for our uroses. Let A = (N i i= be a sequence of neighborhoods defined on M and u, v Z. The sequence u = u 0, u,..., u m = v with u i u i M is called an A-ath from u to v. The A-length of the ath is defined as m w i ( u i u i. The distance W A ( v u between u and v, which is the A-length of v u, is defined as the minimal A-length taken over all A-aths from u to v. If the neighborhood sequence is fixed, then we suress the letter A in the above notation. If N i = N for all i, then the corresonding (constant neighborhood sequence is denoted by A = N. We assume throughout the aer that for such sequences W (n, k = w(n, k holds for (n, k M ; if it would not have been the case, then the function w := W M would have generated W, too. We call W a metric if for all u, v Z W ( u < (W is finite, W ( u = 0 u = 0 (W is ositive definite, W ( u = W ( u (W is symmetric, W ( u + v W ( u + W ( v (W satisfies the triangle inequality. It follows from the above roerties that W ( u 0 for every u Z. By our basic assumtions on w, every induced length function W is ositive definite and symmetric. Furthermore, W satisfies the triangle inequality for u, v with u, v, u+ v M by definition. The first lemma shows that for a constant neighborhood sequence W ( v/ v attains a minimal value which is reached already in M. Lemma. Let N be a neighborhood defined on M which induces the length function W on Z. Then W ( v w( v lim inf = min. v v v M v w( v Proof. Let m = min v M v = w( u u W ( v so that lim inf v v i= ( u M. Then for all n we have W (n u n u = m, m. On the other hand, since w( v v m for every v M, it follows from the definition of shortest ath and the triangle inequality for the Euclidean distance that W ( v i w( v i = i w( v i v i v i m i v i m v for every v Z W ( v not equal to the origin. Thus lim inf v v m.
404 András Hajdu, Lajos Hajdu, and Robert Tijdeman The challenge is therefore to comute lim su v W ( v v. 3 The maximum relative error for neighborhoods N c Let c be some ositive real number with < c. We shall study neighborhoods N c on M with N c (n, k = for which either n < or k < 0, N c (, 0 = + and N c (, k = c + k for 0 < k. We are interested in the length function W c induced by A c := N c for oints in the set {(x, y Z : x, 0 y x}. First we secure that under suitable conditions only two distinct stes occur in a shortest A c -ath. Lemma. Let < c. Then a shortest A c-ath from (0, 0 to (m, mr+k + with m, r, k Z, 0 r <, 0 k < m consists only of stes (, r and (, r +. Proof. Suose a shortest ath from (0, 0 to (m, mr + k with m, r, k Z, 0 r <, 0 k < m contains two stes (, t and (, u with t u 0. Relace the two stes with stes (, t and (, u +, and write L and L for the length of the old and new aths, resectively. Then we have L L c + t c + (t + c + u c + (u + = = c(f (t f (u +, where f (x = + x + (x (x Z 0. A simle calculation yields that f (x is strictly monotone increasing in x, which shows that L L > 0. However, this contradicts the minimality of the length of the original ath. Hence a shortest ath may contain stes (, t and (, t + only, for some nonnegative integer t. Since altogether we make m stes, this immediately gives that t = r, and our statement follows. Remark. The latter inequality is the most severe and exlains why we restrict c to values greater than. + Corollary. Let < c Then a shortest A c-ath from (0, 0 to (m, mr + with 0 r consists of m stes (, r. The next theorem gives the value of the aroximation error for general, in case of any neighborhood N c on M.
Aroximation of the Euclidean Distance by Chamfer Distances 40 Theorem. Let, distance is given by max( c, < c. Then the m.r.error of A c to the Euclidean + + c + + c c +. Proof. As a general remark we mention that to erform our calculations, we used the rogram ackage Male R. Let be a ositive integer, and fix c with < c. As reviously, it + is sufficient to consider the A c -length of oints of the form (m, k where m is some ositive integer and k is an integer with 0 k m. Write k = mq + r with 0 q and 0 r < m. The ossible stes are (, 0 of length and (, ±i of length W i := c + i (for i. From Lemma and the inequalities = W 0 < W <... < W we see that a ath of minimal length from (0, 0 to a oint (m, mq + r consists of r stes (, q + and m r stes (, q. Hence for the induced length function we get W(m, mq + r = rw q+ + (m rw q. Put t = r/m, and recall that W 0 = and W i = c + i for i =,...,. Set and for q and let H 0 (t = ct + + ( t + t, H q (t = c t + (q + + ( t + q + (q + t, h q (, c = max 0 t H q(t (0 q < and h (, c = H (0. Now we investigate the error functions h q (, c for q =, q = 0, 0 < q <, resectively. Suose first that q =. Then r = 0 and k = m. In this case we trivially have h (, c = c. Assume next that q = 0. Then 0 k <. Put t 0 := (c +. A simle calculation yields that 0 t 0, and that H 0 is monotone increasing on the interval [0, t 0 ] and monotone decreasing on the interval [t 0, ]. Moreover, we have H 0 (0 = 0 and H 0 ( = c, hence H 0 (t 0 0. Thus we have h 0 (, c = max( c, H 0 (t 0 = max( c, + c + + c c +. Male is a registered trademark of Waterloo Male Inc.
406 András Hajdu, Lajos Hajdu, and Robert Tijdeman Finally, suose that 0 < q <, that is k < m. Put + q t q := ( ( + q ( + (q + q q (q + + q q. + (q + A simle calculation gives that 0 t q, and that H q is monotone increasing on the interval [0, t q ], while monotone decreasing on the interval [t q, ]. We also have H q (0 = H q ( = c. Hence H q (t q < 0 imlies H q (t q c. Thus we get h q (, c = max( c, H q (t q = max c, c + ( +q ( +(q+ Now we calculate the error function h(, c := lim su W(n, k n + k = max h q(, c. 0 q n, n k 0. Observe first that for fixed and c the function h q (, c is monotone decreasing in q with q. Hence h q (, c h (, c for q =,...,. Further, again by Male, we obtain that for any c with < c + c + ( +( +4 + c + + c c + holds, which imlies h (, c h 0 (, c. Hence h(, c = max( c, + c + + c c + and the theorem follows. The following corollaries rovide the m.r.errors E B (when c = c B and E D (when c =, resectively. Corollary. Let be a ositive integer. Then we have c B = + + + +. That is, the sequence A = A c B of eriod given by A = N c B yields the smallest m.r.error among all sequences A c of eriod. Moreover, the error is given by E B = c B = + + + + =. ( + O 4 0.088 ( + O 4.
Aroximation of the Euclidean Distance by Chamfer Distances 407 Proof. Put f(c = c and g(c = + c + + c c +. A straightforward comutation shows that f is strictly monotone decreasing, while g is strictly monotone increasing for < c. Hence there is a unique + solution of the equation f(c = g(c in this interval. By Theorem this solution is given by c B = + + + +. Thus the statement follows. Corollary 3. Let be a ositive integer. Then the sequence A = A of eriod given by A = N (corresonding to the choice c = has m.r.error E D = ( + + = ( 8 + O 4 = 0. ( + O 4. Proof. On substituting c = into the formula of Theorem, the statement follows immediately. Now we give the best aroximating sequences realizing the minimal maximum relative error for matrices ( = in Theorem and for 7 7 matrices ( = 3 in Theorem 3, resectively. Theorem. Let < c. Let A c = N c be the corresonding sequence on M. Then the minimal m.r.error to the Euclidean distance among the neighborhood sequences A c is attained if and only if where c = c B, W = s and u W v, s = + 0.943, u = s.776 and v = + s.8777. Further, the m.r.error is given by E B = c B = s = 3 0.087.
408 András Hajdu, Lajos Hajdu, and Robert Tijdeman Proof. For any even n with 0 k n the ossible stes are (, 0 of length, (, and (, of length W, and (, and (, of length W. From Lemma and the inequality < W < W we see that the ath from (0, 0 to (n, k of minimal length consists of k stes (, and n k stes (, 0 if 0 k n/ and of k n/ stes (, and n k stes (, if n k n. Hence we have for the induced length function { kw + n k, if k n W(n, k =, (n kw + (k n W, otherwise. Put t = k/n. Then the error function is given by h(w, W := lim su W(n, k n + k = max ( max 0 t t(w + + t n, n k 0, max t ( tw + (t W + t. Our aim is to choose W and W such that h(w, W is minimal. For fixed W, define the function H 0 : R 0 R by H 0 (t = t(w +. + t Put t 0 = W. We observe that H 0 is monotone increasing on [0, t 0 ] and monotone decreasing on [t 0,. Hence, as H 0 (0 =, ( ( max ( H 0 (t = max H 0 (t 0, H 0 0 t ( = max W 4W +, W if W / and ( max 0 (t = H 0 = 0 t ( H W otherwise. Clearly, ( min (h(w, W min max W 4W +, W,W W. ( W A calculation gives that the minimum of the right-hand side is achieved for W = s := + 0.943
Aroximation of the Euclidean Distance by Chamfer Distances 409 and equals s 4s + = s = 3 0.087. Now we fix the value s of W, and show that we can choose W in a way to have equality in (. In fact we comletely describe the set of the aroriate W -s. Consider the maximum over t [/, ]. For fixed W, define the function H : R 0 R by H (t = ( tw + (t W. + t Observe that H attains its maximum at t := (W W W W (which is ositive and further, H is monotone increasing in [0, t ] and monotone decreasing in [t,. Hence ( ( max ( H (t = max H, H (t, H ( = t ( = max W (W W, + 4(W W, W if / t, and max t ( H (t = max ( ( H, H ( = ( = max W, W otherwise. By our choice of W, we have that W = s 0.087. The values of W (W W and +4(W W do not exceed this value if and only if u W v where u and v are defined in the statement of the theorem. We conclude that h(w, W attains its minimum s if W = s and u W v. The above argument shows that E B = W. Hence the minimum among neighborhoods N c is realized for c = c B = W and for no other value of c. 3 Theorem 3. Let 0 < c. Let A c = N c be the corresonding sequence on M 3. Then the minimal m.r.error to the Euclidean distance among the neighborhood sequences A c is attained if and only if c = c B 3, W = s, u W v, q W 3 r,
40 András Hajdu, Lajos Hajdu, and Robert Tijdeman where s = 30 0 + 00 30 0 3.340, 9 3 u = s 3.733, 0 v = 43s 8 3 + 6 690 43 3s q = 3s 4.047, r = 3 3s 0s + 0 0W 3 0 3.944, + W 3, and in the definition of r, W can be any number with u W v. Further, the m.r.error is given by E3 B = c B 3 = s = 3 0 0 3 0 0.0089. 0 9 Proof. Let 3 n and 0 k n. The ossible stes are (3, 0 of length 3, (3, ± of length W, (3, ± of length W, and (3, ±3 of length W 3. From the inequalities 3 < W < W < W 3 it follows that the ath from (0, 0 to (n, k of minimal length consists of k stes (3, and n 3 k stes (3, 0 if 0 k n 3 ; of k n 3 stes (3, and n 3 k stes (3, if n 3 k n 3 ; of k n 3 stes (3, 3 and n k stes (3, if n 3 k n. Hence we have for the induced length function kw + n 3k, if k n/3, W(n, k = (n/3 kw + (k n/3w, if n/3 < k n/3, (n kw + (k n/3w 3, otherwise. Put t = k/n, and define the functions H i : R 0 R (i = 0,, by H 0 (t = t(w ( 3 + 3, H (t = t W + ( t 3 + t + t W and H (t = ( tw + ( t 3 + t W3. Then for fixed W, W, W 3 the error of aroximation is given by ( h(w, W, W 3 = max max 0 t 3 H 0 (t, max 3 t 3 H (t, max 3 t H (t. Let t 0 = W 3, t = 3(W W W W, t = 3(W 3 W 3W W 3,
Aroximation of the Euclidean Distance by Chamfer Distances 4 and observe that all t 0, t and t are ositive. By differentiation and following standard calculus, we get that for i = 0,,, H i is monotone decreasing if t i [i/3, (i + /3], and that H i is monotone increasing in [i/3, t i ] and monotone decreasing in [t i, (i + /3] otherwise. Hence from H 0 (0 = we get that ( ( max ( H 0 (t = max H 0 (t 0, H 0 0 t 3 = 3 ( = max W 6W + 0, W 0. Hence obviously, ( min h(w, W, W 3 min max W 6W + 0, W,W,W 3 W. ( 0 W By a simle calculation we get that the minimum of the right-hand side is achieved for and equals W = s := 30 0 + 00 30 0 9 M := s 6s + 0 = 3.340 s = 3 0 + 7 + 0 3 0 0.0089. 0 9 Now we fix the value s of W, and show that we can choose W and W 3 in a way to have equality in (. More recisely, we comletely describe the set of the aroriate airs (W, W 3. For this urose, first we consider the maximum of H over t [/3, /3]. In a similar manner as in the roof of Theorem, we obtain that max ( H (t = max 3 t 3 = max W 0, ( ( H 3, H (t, H (W W + 9(W W 3 ( 3 =, W 3. Using our choice for W, a simle calculation gives that the above maximum does not exceed the value of M recisely when u W v, where u and v are defined in the statement of the theorem. So let W be any fixed number from the interval [u, v], and consider the the maximum of H over t [/3, ]. Now we get that ( ( max ( H (t = max H 3 t 3, H (t, H ( =
4 András Hajdu, Lajos Hajdu, and Robert Tijdeman (3W W 3 + 9(W 3 W ( = max W 3,, W 3 3 3. Using our choice for W and W, a simle calculation yields that the above maximum is not larger than M if and only if q W 3 r, where q and r are given in the statement. (Note that 4.766 < r < 4.804. The above argument shows that E B 3 = W 0. Hence the minimum among neighborhoods N c is realized for c = c B 3 = W 0, and the theorem follows. 4 Equivalence of m.r.errors for M neighborhoods In this section we comute the m.r.errors E B, E C and E D. First we introduce neighborhoods N c on M defined by N c (0, 0 =, N c (n, 0 = N c (0, n = n for 0 < n, N c (n, k = c n + k for (n, k M, nk 0. Let W c denote the length function induced by the sequence N c. We show that the corresonding m.r.error E c satisfies E c = E c for every considered value of c. It then follows that E B = E B and E D = E D for every. Lemma 3. Let < c. There is a shortest N c-ath from (0, 0 to (m, k + with 0 k m which consists of stes of the form (, 0 and (,. Proof. Suose a shortest ath from (0, 0 to (m, k contains a ste (g, h with h < 0. Then it also contains a ste (i, j with j. But it is shorter to relace both stes with stes (g, h + and (i, j. A similar argument can be used to exclude stes (g, h with h >. So every shortest ath from (0, 0 to (m, k contains only stes of the forms (g, 0 and (g,. If k = m, then taking only stes (, gives the shortest ath length because of the triangle inequality for the Euclidean distance and the inequality c. Suose that there is a ste (g, with g < in a shortest ath from (0, 0 to (m, k with 0 k < m. Then there is also a ste (h, 0 with h > 0. But we can relace both stes with stes (g +, and (h, 0 and make the ath shorter. Therefore all the stes of the form (g, are of the form (,. The remaining stes can be combined to stes of the form (, 0. Lemma 4. Let be fixed. Let < c. The m.r.error of the neighborhood + sequence N c is equal to E D if c = and equal to E B if c assumes the value c B from Corollary. Proof. Because of symmetry it suffices only to consider oints (n, k with 0 k n. First let c =. By definition N(n, k = n + k for (n, k M. Hence the induced length function satisfies W (n, k (n, k for all (n, k Z. Thus min W (n, k n + k
Aroximation of the Euclidean Distance by Chamfer Distances 43 where the minimum is taken over all (n, k Z with (n, k (0, 0. On the other hand, by Lemma 3, the shortest N ath from (0, 0 to (m, k with 0 k m consists of stes of the forms (, 0 and (, which have lengths and +, resectively. Hence W (m, k = W (m, k for 0 k m. If n = m + r with 0 r <, then W (n, k W (m, k <. Note that in view the roof of Theorem (in articular, since h 0 (, c h i (, c for all i there we have W (m, k lim su (m,k (m, k 0 k m Thus on the one hand it follows that W (n, k lim su (n,k (n, k 0 k n = lim su (m,k 0 k m W (m, k. (m, k W (m, k = lim su (m,k (m, k 0 k m W (m, k W (m, k lim su = lim su (m,k (m, k (m,k (m, k 0 k m 0 k m = lim su (m,k 0 k m W (m, k. (m, k On the other hand, by W (m, k W (m, k for all m, and k, we also have that W (m, k lim su (m,k (m, k 0 k m W (m, k lim su (m,k (m, k 0 k m W (n, k = lim su (n,k (n, k. 0 k n Hence and by W (n, k lim su (n,k (n, k 0 k n W (m, k = lim su (m,k (m, k 0 k m W (m, k lim su = + E D, (m,k (m, k the m.r.error of N equals E D. Next let c = c B = E B. Then + < c <, and, by construction, W c (, 0 =, W c (, k = c + k for 0 < k, and W c (n, k = c n + k for 0 < k n. Hence min (n,k M W c (n, k n + k = c = E B. Thus W c B lim inf (n, k = E B. (n,k (n, k
44 András Hajdu, Lajos Hajdu, and Robert Tijdeman On the other hand, by Lemma 3, the shortest N c ath from (0, 0 to (m, k with 0 k m consists of stes of the form (, 0 and (,. By a similar reasoning as above we obtain that W c B lim su (n, k = + E B. (n,k (n, k Thus the m.r.error of N c equals E B. Theorem 4. For every we have E B = E B and E D = E D. Proof. We first consider the D-case. Suose the neighborhood N on M induces a length function W : Z R 0 such that W ( v v for all v Z and W has m.r.error E D. It can only imrove the m.r.error if we relace the value N(n, k for some (n, k M with a smaller value (n, k. Therefore we may assume without loss of generality that N = N. Hence E D = E D. Now we turn to the B-case. Suose a neighborhood N on M induces a length function W such that W (n, 0 = W (0, n = n for n Z and ( E B v W ( v ( + E B v for all v Z. Without loss of generality we may relace all values N(n, k for (n, k M with n if k = 0, with k if n = 0, and with ( E B (n, k otherwise. Thus E B equals the m.r.error of the neighborhood sequence N E B. We know from Lemma 4 and Corollary that if c = c B, then the m.r.error of N c equals E B = c B. Hence E B E B. From N(n, k ( E B (n, k c B (n, k for all (n, k M we obtain W ( v W c B ( v for all v Z. Hence + E B W ( v W c B = inf lim su lim su ( v = + E B N v v v v by Lemma 4. Thus E B = E B. Finally, we comute the minimal m.r.error E C for the class of arbitrary neighborhoods N defined on M. Observe that the m.r.error E C is attained by the length function W corresonding to the neighborhood N defined by w( v = ( E C v for v M, since N( v v should not assume a smaller value than E C and the limsu-value cannot increase if we decrease some w( v. Clearly, the length function W corresonding to N is just W E C where W is the length function on N. Recall that N has m.r.error E D. Therefore we have + E C = lim su v W ( v v = ( + E D ( E C. (3 By a simle calculation we get E C = ED. So we have roved +E D
Aroximation of the Euclidean Distance by Chamfer Distances 4 Theorem. For every we have E C = ED + E D = + + + = ( 6 + + + O 4. Remark. Observe that E B is about 37% larger than E C. This is the rice to be aid for the restriction W (n, 0 = n for n Z. The value of E D is about twice the error E C. This is due to the fact that the negative and ositive deviations in E C are added to the ositive deviation in E D. Conclusion In this aer, we have determined the smallest ossible maximum relative error of chamfer distances with resect to the Euclidean distance under various conditions. We have dealt with aroximating distances from three main asects: suosing that a horizontal/vertical ste has a weight in the local chamfer neighborhoods, majorating the Euclidean distance, and also without any constraint. We have calculated otimal weights for small ( and 7 7 neighborhoods in a certain case, as well. Our framework is embedded in the theory of neighborhood sequences with ossible generalizations in this field. References [] Bailey, D.G. An efficient euclidean distance transform. Lecture Notes in Comuter Science, 33:394 408, 004. [] Borgefors, G. Distance transformations in arbitrary dimensions. Comuter Vision, Grahics, and Image Processing, 7:3 34, 984. [3] Borgefors, G. Distance transformations in digital images. Comuter Vision, Grahics, and Image Processing, 34:344 37, 986. [4] Borgefors, G. Hierarchical chamfer matching: a arametric edge matching algorithm. IEEE Transactions on Pattern Analysis and Machine Intelligence, 0:849 86, 988. [] Butt, M.A. and Maragos, P. Otimum design of chamfer distance transforms. IEEE Transactions on Image Processing, 7:477 484, 998. [6] Coquin, D. and Bolon, Ph. Discrete distance oerator on rectangular grids. Pattern Recognition Letters, 6:9 93, 99. [7] Cuisenaire, O. Distance Transformation, Fast Algorithms and Alications to Medical Image Processing. PhD thesis, Université Catholique de Louvain, 999.
46 András Hajdu, Lajos Hajdu, and Robert Tijdeman [8] Danielsson, P.E. Euclidean distance maing. Comuter Grahics and Image Processing, 4:7 48, 980. [9] Das, P.P., Chakrabarti, P.P., and Chatterji, B.N. Distance functions in digital geometry. Information Sciences, 4:3 36, 987. [0] Fazekas, A., Hajdu, A., and Hajdu, L. Lattice of generalized neighbourhood sequences in nd and d. Publ. Math. Debrecen, 60:40 47, 00. [] Fouard, C., Strand, R., and Borgefors, G. Weighted distance transforms generalized to modules and their comutation on oint lattices. Pattern Recognition, 40:43 474, 007. [] Hajdu, A., Hajdu, L., and Tijdeman, R. General neighborhood sequences in Z n. Discrete Al. Math., :07, 007. [3] Jr, C.R. Maurer, Qi, R., and Raghavan, V. A linear time algorithm for comuting exact euclidean distance transforms of binary images in arbitrary dimensions. IEEE Transactions on Pattern Analysis and Machine Intelligence, :6 70, 003. [4] Nagy, B. Distance with generalized neighbourhood sequences in nd and d. Discrete Al. Math., 6:344 3, 008. [] Nagy, B. and Strand, R. Neighborhood sequences in the diamond grid: algorithms with two and three neighbors. International Journal of Imaging Systems and Technology, 9:46 7, 009. [6] Nagy, B. and Strand, R. Neighborhood sequences on nd hexagonal/facecentered-cubic grids. Lecture Notes in Comuter Science, 8:96 08, 009. [7] Scholtus, S. Chamfer Distances with Integer Neighborhoods, Master Thesis, Leiden University, The Netherlands. 006. [8] Scholtus, S. and Tijdeman, R. Chamfer distances with integer neighborhoods. Technical reort, Leiden University, The Netherlands, 006. [9] Shih, F.Y. and Wu, Y.T. Fast euclidean distance transformation in two scans using a 3 3 neighborhood. Comuter Vision and Image Understanding, 93:9 0, 004. [0] Strand, R., Nagy, B., Fouard, C., and Borgefors, G. Generating distance mas with neighbourhood sequences. Lecture Notes in Comuter Science, 44:9 307, 006. [] Thiel, E. Les Distances de Chamfrein en Analyse d Images: Fondements et Alications. PhD thesis, Université Joseh Fourier de Grenoble, 994. [] Verwer, B.H.J. Distance Transforms: Matrics, Algorithms and Alications. PhD thesis, Techn. Univ. Delft, 99.
Aroximation of the Euclidean Distance by Chamfer Distances 47 [3] Verwer, B.H.J. Local distances for distance transforms in two and three dimensions. Pattern Recognition Letters, :67 68, 99. [4] Yamashita, M. and Ibaraki, T. Distances defined by neighbourhood sequences. Pattern Recognition, 9:37 46, 986. Received 6th February 00