Euclidean Ordering via Chamfer Distance Calculations.
(Running head: \Euclidean ordering using chamfer distances")
Stephane Marchand-Maillet and Yazid M. Sharaiha.
Operational Research and Systems
Imperial College of Science, Technology and Medicine 53 Prince's Gate, London SW7 2PG, United Kingdom Phone: +44 (0)171 594 9174 { Fax: +44 (0)171 823 8134 e-mail: [email protected] { URL: http://www.ms.ic.ac.uk/steph/
To whom correspondence should be sent.
This paper studies the mapping between continuous and discrete distances. The continu- ous distance considered is the widely used Euclidean distance whereas we consider as discrete distance the chamfer distance based on 33 masks.
A theoretical characterisation of topological errors which arise during the approximation of Euclidean distances by discrete ones is presented. Optimal chamfer distance coecients are characterised with respect to the topological ordering they induce rather than the approxima- tion of Euclidean distance values. We conclude the theoretical part by presenting a global upper bound for a topologically-correct distance mapping, irrespective of the chamfer distance coecients, and identify the smallest coecients associated with this bound.
We use these results to solve a problem which is a representative of most of problems in image processing, namely the Euclidean-nearest neighbour problem. This problem is formulated as a discrete optimisationproblem and solved accordingly using algorithmic graph theory and integer arithmetic.
1 Introduction
The main motivation of this work is to analyse the mapping between continuous and discrete distances on the unit square grid. For a given pixel on the grid, a neighbourhood of that pixel is dened by a distance metric. The local neighbours of a pixel are contained within a mask centred at that pixel. The most commonly used is the 33 mask, where the neighbours are typically dened by the City-Block distance (4-neighbours) or the Chessboard distance (8-neighbours) [11].
Local distances within the mask form the basis for the computation of global distances on the grid.
Chamfer distance and was rst introduced by Hilditch [7, 8] and studied by Borgefors in [1] and [2]
for the approximation of Euclidean distances on the grid.
While studying in depth the calculation of Euclidean distance values using discrete distance functions (Section 2), we will derive results concerning the decomposition of integer values which can then form the basis for the development of optimal algorithms for the solution of typical problems encountered in image processing (see e.g., [9]). In Section 3, we propose to apply theoretical results derived in this paper and tools issued from graph theory to solve exactly and optimally the Euclidean-nearest neighbour problem (i.e., where continuous distances values are required) using integer arithmetic. Solutions of the nearest neighbour problem have applications for the computation of dierent structures in image processing (e.g., distance maps and Voronoi diagrams). The idea behind the proposed solution therefore denes a new context in which these problems can be solved.
2 Topological Errors
We consider throughout these pages that the continuous distance used is the Euclidean distance
d
Edened as
d
E(p;q
) =q(x
p,x
q)2+ (y
p,y
q)2, wherep
= (x
p;y
p) andq
= (x
q;y
q). We introduce the notation for some standard functions. dx
e is the smallest integer greater or equal to thanx
2 IR and bx
c is greatest integer smaller or equal to thanx
2 IR. Then, round(x
) = bx
c ifb
x
cx
bx
c+12. Otherwise, round(x
) =dx
e.In approximating the Euclidean distance, the chamfer distance is used since it allows for algo- rithms to operate in integer arithmetic. We will consider chamfer distances in relation to 33 masks. We dene
a
as the length of the unit horizontal/vertical move (a
-move) on the grid, andb
as the length of the unit diagonal move (b
-move) on the grid. Parametersa
andb
are referred to as distance transform (DT) coecients. The chamfer distance can be computed as the length of a shortest path on the grid. Given two pointsp
andq
, the chamfer distanced
a;b betweenp
andq
is calculated as follows.d
a;b(p;q
) =k
aa
+k
bb
(1) wherek
a andk
b represent the number ofa
- andb
-moves on the shortest path fromp
toq
on the grid. The conditions ona
andb
ford
a;b to be a distance are given in (2) below (see [10] and [14]for more details). Such conditions allow
d
a;bto satisfy the three common metric properties.0
< a < b <
2a
(2)The number of
a
- andb
-moves (k
a;k
b) on the shortest path fromp
toq
can also be used to compute the Euclidean distance betweenp
andq
.d
E(p;q
) =q(k
a+k
b)2+k
2b (3)Without loss of generality, we restrict this study to values of DT coecients such that
a
andb
are relatively prime (i.e., the Greater Common Divisor ofa
andb
, gcd(a;b
), is such that gcd(a;b
) = 1).This corresponds to normalising the
a
andb
coecients to their minimal conguration.Although dierent studies establish particular values of DT coecients as optimal (e.g.,
a
= 3,b
= 4), optimality generally refers to a criterion in relation to a minimum error in the approxi- mation of Euclidean distance values via chamfer distance computation (see e.g., [2, 14, 15]). In contrast, Forchhammer [5, 6] introduced the concept of topological inconsistencies induced by dis- crete distances when used as an approximation of the Euclidean distance. The inconsistency arises because of the dierence in ordering of the two distance measures as will be described next. He derived values of DT coecientsa
andb
which are empirically shown to be optimal with regard to this criterion. The results were based on the use of look-up tables and an investigation of a limited number of values of the parameters under study.In this section, we propose an analytical (and therefore, complete) characterisation of the op- timal values of
a
andb
with respect to the topological criterion. Essentially, the ordering of the discrete distance does not match the ordering of the Euclidean distance. Consider the following example (see Figure 1). Let the DT coecients bea
= 2,b
= 3, and consider the three integer points (pixels),p
= (0;
0),q
= (10;
1) andr
= (9;
4). The shortest path on the grid fromp
toq
is given byk
a = 9 andk
b = 1 and that fromp
tor
is given byk
a = 5 andk
b = 4. Using Equations (1) and (3), we haved
a;b(p;q
) = 21,d
E(p;q
) =p101,d
a;b(p;r
) = 22 andd
E(p;r
) =p97.If
q
andr
are border pixels, the discrete DT will lead to considerq
as the nearest border pixel top
(by the chamfer distance measure) giving an approximate Euclidean distance of p101. This is clearly incorrect since there is a smaller Euclidean distance betweenp
and another border pixel (namelyr
) giving a Euclidean distance of p97. In other words, since,d
a;b(p;q
)< d
a;b(p;r
) andd
E(p;q
)> d
E(p;r
), the ordering ofd
a;b diers from the ordering ofd
E.q p
r
Figure 1: An example of a topological error.
Given a pair of DT coecients (
a;b
), we characterise the congurations for which this problem occurs precisely. First, we introduce how restrictions for the decomposition of a given discrete distance valueD
intoa
- andb
-moves can be given by the solution to the Frobenius problem.Theorem 1
[13]. Given0< a < b
such that(a;b
)2IN2 andgcd(a;b
) = 1. Consider the equation:k
aa
+k
bb
=D
(k
a;k
b)2IN2 If= (a
,1)(b
,1), then we have the following instances.(i) If
D
, there is always at least one solution(k
a;k
b).(ii) If
D
=,1, there is no solution.(iii) There is exactly 12
values ofD
that have no solution.We will use the solution to this classical problem to characterise the topological error introduced earlier. Two types of errors are distinguished and presented in Sections 2.1 and 2.2, respectively.
2.1 Type 1 error
Given a pair of DT coecients (
a;b
) and three integer pointsp
,q
andr
, a Type 1 error occurs betweenq
andr
relative top
ifd
a;b(p;q
) =d
a;b(p;r
) andd
E(p;q
) 6=d
E(p;r
). More formally, we make the following denition.Denition 1
Type 1 error. Given a pair of DT coecients(a;b
) and a discrete distance valueD
, a Type 1 topological error occurs if there exist two integer pairs (k
a1;k
b1) and (k
a2;k
b2) such thatk
a1a
+k
b1b
=k
a2a
+k
b2b
=D
andq(k
a1+k
b1)2+k
2b1 6=q(k
a2 +k
b2)2+k
2b2.An example for Type 1 error is illustrated in Figure 2 where, (
k
a1;k
b1) represents the shortest path fromp
toq
, and (k
a2;k
b2) the shortest path fromp
tor
. In this example, the DT coecients area
= 2 andb
= 3, and the three integer points arep
= (0;
0),q
= (3;
0) andr
= (2;
2). We obtaind
a;b(p;q
) =d
a;b(p;r
) =D
= 6, sincek
a1 = 3,k
b1 = 0 andk
a2 = 3,k
b2 = 0. On the other hand, we have,d
E(p;q
) = 3 andd
E(p;r
) =p8.r
p q
Figure 2: The rst instance of Type 1 topological error for (
a;b
) = (2;
3).It is clear that a necessary condition for Type 1 error to occur is that
D
can be decomposed in more than one manner. Lemma 1 gives an upper bound on the number of such decompositions, and Lemma 2 provides an exact upper bound on the number ofb
-moves (k
bmax) over all possible decompositions.Lemma 1
Given a pair of DT coecients (a;b
) and a discrete distance valueD
2IN, there is at most bDbac+1+ 1 congurations (k
a;k
b) such thatk
aa
+k
bb
=D
withk
a 0 andk
b 0.Proof:
Clearly,
k
b can take at most jDbk+ 1 values. Now, among these values, only some can satisfy the equationk
aa
+k
bb
=D
. Let us assume that (k
a;k
b) is one such valid pair. Then,D
=k
aa
+k
bb
=k
aa
+k
bb
+ab
,ab
= (k
a+b
)a
+ (k
b,a
)b
. Then, ifk
b,a
0, the conguration (k
a+b;k
b,a
) is also valid. Likewise, all congurations (k
a+ib;k
b,ia
) withi
2ZZ such thatk
a+ib
0 andk
b,ia
0 are valid. Clearly, since gcd(a;b
) = 1, there is at most bDbac+1+ 1 suchi
values.Therefore, Lemma 1 holds. 2
Lemma 2
Given a pair of DT coecients (a;b
) and a discrete distance valueD
, we assume that the existence condition (i) in Theorem 1 holds. Then, the maximal valuek
bmax ofk
b such thatk
aa
+k
bmaxb
=D
withk
a0 andk
bmax0 is given by:k
bmax=D b
, ((
D
modb
) moda
) (4)where is the implicit integer function such that:
:f0
;
1;
;a
,1g7!f0;
1;
;a
,1g and ((x:
(2a
,b
)) moda
) =x
.Proof:
The existence of a decomposition is given by Theorem 1. The problem of nding the maximal value
k
bmax ofk
b such thatk
aa
+k
bmaxb
=D
can be mapped onto the problem of nding the minimal positive valuek
ofk
such that(
D
modb
+kb
) moda
= 0 (5)In this case, we have:
k
bmax=D b
,
k
(6)Consider the following implicit integer function : IN!IN in its general form.
(
x
) =(k
if (x
+kb
) moda
= 0+1 if 8
k
0 (x
+kb
) moda
6= 0 (7)Using the above denition and modulus arithmetic, one can easily prove the following properties for : (i) (0) = 0, (ii) (
x
+a
) = (x
), (iii) (x
+b
) = (x
),1, (iv) (x
+(2a
,b
)) = (x
)+1, (v) (x
) =k
, (x
) =k
moda
Hence, from Properties (i) and (ii), we deduce that is periodic and, therefore, can be dened only forx
2f0;
1;
;a
,1g.Now, let
k
2 IN andk
0 2 IN be such thatk
6=k
0 and (kb
) moda
= (k
0b
) moda
= . Then,9
;
2IN such thatkb
=+a
andk
0b
=+a
. It follows that, (kb
) moda
= (k
0b
) moda
, (k
,k
0)b
= (,)a
, (
k
,k
0)b
moda
= 0, (
k
,k
0) moda
= 0 since gcd(a;b
) = 1Equivalently, if (
k
,k
0) moda
6= 0 , (kb
) moda
6= (k
0b
) moda
. Therefore, the set f(kb
) moda;
8k
0g contains exactlya
dierent values.From Property (v), we know that (
x
) 2 f0;
1;
;a
,1g. Therefore, we can claim that,8
k
2f0;
1;
;a
,1g;
9x
2f0;
1;
;a
,1gsuch that (x
) =k
.Therefore, is a bijection fromf0
;
1;
;a
,1gtof0;
1;
;a
,1gsuch that ((k
(2a
,b
)) moda
) =k
. Hence, using Equations (5) and (7), we obtain thatk
= ((D
modb
) moda
). Therefore,combining this result with Equation (6), Lemma 2 holds. 2
can be easily computed as a one-to-one mapping of the setf0
;
1;
;a
,1gonto itself. Thus, Lemma 2 readily gives an exhaustive list of (k
a;k
b) pairs for decomposing any discrete distance valueD
for any DT coecientsa
andb
.Denition 2
Given a pair of DT coecients (a;b
) and a discrete distance valueD
which can be decomposed in at least one manner, we dene:- The set = f(
k
ai;k
bi);i
= 0;
;n
g as the exhaustive list of all possible decomposition pairs (i.e.,D
=k
aia
+k
bib
,k
ai 0,k
bi 0 8i
= 0;
;n
withn
= jkbmaxa k). Note thatk
bmax= maxi=0;;nk
bi and,k
bi =k
bmax,ia
. Therefore, the set can be fully computed using Lemma 2.-
R
i(D
) as the Euclidean distance associated with the pair (k
ai;k
bi). From Equation (3), we have,R
i(D
) =q(k
ai+k
bi)2+k
2bi (8)-
R
max(D
) (resp.R
min(D
)) as the maximal (resp. minimal) Euclidean distance over alln
+ 1 possible decompositions.-
l
(resp.m
) as the index in the set of the decomposition (k
al;k
bl) (resp. (k
am;k
bm)) leading toR
max(D
) (resp.R
min(D
)).We now present a lemma which allows us to calculate the indices
m
andl
(and, therefore,R
max(D
) andR
min(D
)) directly for any DT coecients (a
,b
) and any discrete distance valueD
.Lemma 3
Given a pair of DT coecients (a;b
) and a discrete distance valueD
, we assume thatD
can be decomposed in at least more than one manner.Then, the minimal decomposition (
k
am;k
bm) leading toR
min(D
) is given bym
= roundD
(a
,b
)a
(b
2,2:ab
+ 2a
2) +k
bmaxa
(9)
and the maximal decomposition (
k
al;k
bl) leading toR
max(D
) is given byl
=( 0 ifk
bmax+ (k
bmaxmoda
)>
b22:D(b,2:ab+2a,a)2n
ifk
bmax+ (k
bmaxmoda
) b22:D(b,2:ab+2a,a)2 (10) Proof:Re-arranging
D
=k
aia
+k
bib
, we obtaink
ai = D,akbib. Combining this with Equation (8), we obtainR
2i(D
) = 1a
2h
k
2bi(b
2,2:ab
+ 2:a
2) + 2:k
biD
(a
,b
) +D
2i (11) Giveni
andj
in f0;
;n
g such thati < j
, we havek
bi> k
bj. Then,R
i(D
)> R
j(D
) ifk
bi+k
bj>
2:D
(b
,a
)b
2,2:ab
+ 2:a
2 (12)Now, if
k
bi> k
bj 8i < j
, Equation (12) shows that we have the following pattern:R
0(D
)> R
1(D
)>
> R
m(D
)(=R
min(D
))< R
m+1(D
)<
< R
n(D
) (13) Therefore,m
is the rst integer such thatR
m,1(D
)> R
m(D
) andR
m(D
)R
m+1(D
):k
bmax,(m
,1):a
+k
bmax,m:a >
2:D
(b
,a
)b
2,2:ab
+ 2:a
2 andk
bmax,m:a
+k
bmax,(m
+ 1)a
2:D
(b
,a
)b
2,2:ab
+ 2:a
2 Therefore,D
(a
,b
)a
(b
2,2:ab
+ 2a
2) +k
bmaxa
+ 12> m
D
(a
,b
)a
(b
2,2:ab
+ 2a
2) +k
bmaxa
, 12:
Hence, Equation (9) holds. It is important to note that
m
is uniquely dened by the above equation. Using the result in Equation (13), we can also say that the maximum Euclidean distance is obtained for either extreme ofi
. Using Lemma 1, we obtain thatk
b0 =k
bmaxandk
bn =k
bmaxmoda
. Therefore, using the valid inequality given in Equation (12), we can claim that Equation (10)completely characterises
l
. Hence, Lemma 3 holds. 2Lemma 4
Characterisation of a Type 1 error. Given a pair of DT coecients (a;b
), a Type 1 error occurs for any discrete distance valueD
for whichR
max(D
)6=R
min(D
).Clearly, the rst instance of
D
for whichR
max(D
) 6=R
min(D
) isD
=ab
. In this case,k
bmax =a
,n
= 1, =f(0;a
);
(b;
0)g, (i.e.,R
0 =a
p2 andR
1 =b
). Hence,R
max(ab
)6=R
min(ab
). Therefore, we dene the following Euclidean distance limit when considering Type 1 errors only.Denition 3
Euclidean distance limit induced by Type 1 error, R1(a;b
). Given a pair of DT coef- cients (a;b
), andD
=ab
as the minimum discrete distance value for whichR
min(D
)6=R
max(D
), we dene the Euclidean distance limit R1(a;b
) for Type 1 errors as follows. R1(a;b
) is the max- imal Euclidean distance value deduced from a discrete distance value (i.e., using Equation (3)) up to which both discrete and continuous distance ordering match. More formally, R1(a;b
) is the maximal Euclidean distance valueR
such that 9k
a; k
b 2 IN such thatR
=q(k
a+k
b)2+k
2b andR < R
max(ab
).In other words,
R
max(ab
) can be considered as a strict (i.e., non-feasible) Euclidean distance limit.In order to obtain a feasible limit, we search
D
0 the maximal discrete distance value such thatR
min(D
0)< R
max(ab
) and consider R1(a;b
) =R
min(D
0). Using the previous study, we can easily design an algorithm to compute, for any pair of DT coecients (a;b
), the value of R1(a;b
). In Figure 3, (R1(a;b
))2 is plotted for each pair of valid DT coecients such thata
10.Figure 3: Euclidean distance limit induced by Type 1 of topological error (R1(
a;b
))2.2.2 Type 2 error
Given a pair of DT coecients (
a;b
) and three integer pointsp
,q
andr
, a Type 2 error occurs betweenq
andr
, relative top
, ifd
a;b(p;q
)< d
a;b(p;r
) andd
E(p;q
)> d
E(p;r
).Denition 4
Type 2 error. Given a pair of DT coecients(a;b
) and two discrete distance valuesD
1 andD
2, we assume that 9 (k
a1;k
b1)and (k
a2;k
b2) such thatk
a1a
+k
b1b
=D
1 andk
a2a
+k
b2b
=D
2 (see Theorem 1). A Type 2 error occurs if,D
1< D
2 and q(k
a1+k
b1)2+k
2b1>
q(
k
a2+k
b2)2+k
2b2.Figure 4 illustrates an instance of Type 2 error between
q
andr
, relative top
. In this example, the DT coecients area
= 2 andb
= 3. We considerp
= (0;
0),q
= (6;
0) andr
= (5;
3). Therefore,D
1 =d
a;b(p;q
) = 12, sincek
a1 = 6 andk
b1 = 0. We also obtainD
2 =d
a;b(p;r
) = 13, sincek
a2 = 2 andk
b2 = 3. On the other hand, we haved
E(p;q
) =p36 andd
E(p;r
) = p34. Therefore,d
a;b(p;q
)< d
a;b(p;r
) andd
E(p;q
)> d
E(p;r
).r
p q
Figure 4: The rst instance of Type 2 topological error for (
a;b
) = (2;
3).From a geometric viewpoint, given three integer points
p
,q
andr
such thatD
1 =d
a;b(p;q
)<
D
2 =d
a;b(p;r
), a Type 2 error occurs betweenq
andr
, relative top
, if there exists at least one integer point (namely,r
) included in the area between the discrete disc of radiusD
1 centred atp
and the Euclidean disc that contains this discrete disc. In Figure 4, this area is illustrated by the shaded surface. A Type 2 error occurs betweenq
andr
, relative top
, sincer
lies in this shaded surface.The geometrical characterisation of Type 2 errors will, therefore, be investigated through the characterisation of the radius of the smallest Euclidean disc that contains the discrete disc of radius
D
for any given values of the DT coecients (a;b
) and for any discrete distance valueD
. The radius of such a Euclidean disc was notedR
max(D
) (see Denition 2). Therefore, the geometrical characterisation of Type 2 error can be formally written as follows.Lemma 5
Given a pair of DT coecients (a;b
) and a discrete distance valueD
, a Type 2 error occurs in the discrete disc of radiusD
if there exists a discrete distance valueD
0> D
such thatR
min(D
0)< R
max(D
).Using this characterisation, the Euclidean distance limit R2(
a;b
) induced by Type 2 error can be dened as follows.Denition 5
Euclidean distance limit induced by Type 2 error, R2(a;b
) Given a pair of DT coe- cients(a;b
), andD
, the minimum discrete distance value for which there exists a discrete distance valueD
0such thatR
min(D
0)< R
max(D
), we dene the Euclidean distance limitR2(a;b
) for Type 2 errors as follows.R2(
a;b
) =R
min(D
0) whereD
0 is the smallest discrete distance value such thatR
min(D
0)<
R
max(D
).In other words, if a Type 2 error occurs for the discrete distance value
D
(e.g., at pointq
in Figure 4, withD
= 12), we consider the Euclidean distance limit as the valueR
min(D
0) whereD
0 is the discrete distance value at the second point for which Type 2 error occurred (e.g., pointr
in Figure 4, andD
0= 13). In Figure 5, (R2(a;b
))2 is plotted for each DT coecients pair such thata
10.Using the results of Sections 2.1 and 2.2, we can now dene a combined Euclidean distance limit where no topological error of any type can occur.
Denition 6
Global Euclidean distance limit, R(a;b
). Given a pair of DT coecients (a;b
), we dene the global Euclidean distance limitR(a;b
) as the minimum between the distance limits induced by both Type 1 and 2 errors. Therefore,R(a;b
) = min(R1(a;b
);
R2(a;b
)).34
16 17 8
Figure 5: Distance limit induced by Type 2 error.
R(
a;b
) represents the maximal achievable Euclidean distance when growing topologically correct discrete discs. Equivalently, given a pair of DT coecients (a;b
), for any discrete distance valueD
such thatR
max(D
)R(a;b
), no topological error (of Type 1 or Type 2) occurs in the discrete disc of radiusD
. In Figure 6, (R(a;b
))2is plotted for each DT coecients pair such thata
10.Note that, for large values of
a
andb
, the limit induced by the Type 2 error dominates.a=3, b=4
Figure 6: Global Euclidean distance limit for the correctness of the EDT.
2.3 Global Euclidean distance limit and optimal DT coecients
Our aim now is to determine, whether an optimal pair exists among all valid pairs of DT coecients.
We dene optimality here as the smallest integer pair of DT coecients which guarantees the maximum achievable Euclidean distance limit. Using the results plotted in Figure 6, we could say that, for all pair of DT coecients such that
a
10, the pair (3;
4) is a local optimum in the sense that it is the smallest pair of DT coecients that leads to a (local) maximum Euclidean distancelimit (i.e.,R(3
;
4) =p17). In order to extend this result to any pair of DT coecients, we will use an analytical approach rather than the geometric approach which was used previously.As suggested in Lemma 4 and Denition 3, an analytical Euclidean distance limit induced by Type 1 errors can be estimated by
R
max(ab
). Since this limit increases with the values of (a;b
), we pointed out earlier that Type 2 error dominates for greater values of DT coecients. Hence, we will mainly concentrate on an analytical study of Type 2 errors and nally combine the result with those of the previous study of Type 1 errors. The result of this study can be stated as follows.Theorem 2
Euclidean distance limit and optimal DT coecients Considering the chamfer distanced
a;b as a discrete distance, the maximal error-free Euclidean distance achievable is p17 and the smallest integer pair of DT coecients that achieves this limit is(a;b
) = (3;
4).We introduce the idea behind the proof of Theorem 2. The approach for deriving an analytical expression of the Euclidean distance limit for Type 2 error (i.e.,R2(
a;b
)) is made by decomposing the region of the plane (x;y
) delimited by the linesy
=x
andy
= 2x
, by a liney
=x
, where (;
) is an integer pair that matches the conditions for being a pair of DT coecients (see Figure 7).y= xαβ
x (α=3, β=4) (a=5, b=8)
(a=6, b=7)
O
y=2x y=x y
Figure 7: Representation of the valid pairs of DT coecients for the proof of Theorem 2.
For each such pair (
;
), we characterise a Euclidean distance limit in each sub-region of the plane (x;y
) delimited by the linesy
=x
,y
=x
andy
= 2x
. Given a valid pair (;
), and for any pair of DT coecients (a;b
) dierent from (;
), two cases are possible, (i
): ba<
or (ii
): ab>
. Case (i
) includes the valid integer points in the sub-region belowy
=x
and abovey
=x
, whereas Case (ii
) includes the valid integer points in the sub-region abovey
=x
and belowy
= 2x
. The Euclidean distance limit R2(a;b
) is to be investigated for the two sub-regions separately and we will refer to this as Rinf(;
) and Rsup(;
) for cases (i
) and (ii
) respectively.In the example illustrated in Figure 7,
= 3, = 4. Then, for instance, R2(6;
7) will include the Euclidean distance limit Rinf(3;
4), since 76<
43. Similarly, R2(5;
8) will include the Euclidean distance limit Rsup(3;
4), since 85>
43.Hence, given a pair of DT coecients (
a;b
), the Euclidean distance limit for Type 2 errors induced by (a;b
) (i.e., R2(a;b
)) will result from a combination of all Euclidean distance limits induced by the pairs (;
) in the following way.R2(
a;b
) = min0
@ min
f(;)=ba<g(Rinf(
;
));
minf(;)=ba>g(Rsup(
;
))1 A
Proof:
Given a pair of DT coecients (
a;b
) and an integer pair (;
) such that 0< < <
2 and gcd(;
) = 1, we consider two cases: (i) ba<
and, (ii) ba>
. It will become apparent that the equality case represents a Type 1 error and, therefore, as noted earlier, will not be studied here.We now investigate cases (i) and (ii) in order to obtain the Euclidean distance limits induced by each case (i.e., Rinf(
;
) and Rsup(;
), respectively).(i) Characterisation ofRinf(
;
).Since, ab
<
then,b < a
. Given 1;
2 2 IN, we can dene the two discrete distancesD
1 =b
+1a
+2b
andD
2 =a
+1a
+2b
. In this case, we clearly haveD
1< D
2. According to Denition 4, a Type 2 topological error occurs if(
+1+2)2+ (+2)2>
(+1+2)2+22 Re-arranging, we obtain, 2>
21(,) +2,222(2
,) (14)Moreover, from Denition 5, the distance limit induced by the case ba
<
is, therefore,(Rinf(
;
))2= (+1+2)2+22 (15) Hence, the rst instance for which a Type 2 error occurs is characterised by (1;
2), a pair of positive integers which satisfy the inequality in (14) (i.e., where a Type 2 error occurs) and for which Rinf(;
) is minimum. Since Rinf(;
)>
0, the minimisation of Rinf(;
) is equivalent to the minimisation of (Rinf(;
))2. If we consider the function (1;
2) = (Rinf(;
))2 = (+1+2)2+22, we can re-write the constrained minimisation problem as follows. Given a valid integer pair (;
),min (
1;
2) subject to:(
C
1) 2>
21(2(2,)+,)2,22 (C
2) 1 0(
C
3) 2 0Now, is a positive convex quadratic function. Therefore, the global (i.e., unconstrained) minimum of is reached in (
1glob;
2glob) such that @@ 1(1glob;
2glob) = 0 and @@ 2(1glob;
2glob) = 0. Then, is minimum for (1glob;
2glob) = (,;
0). But, since1glob=,<
0, the global minimum (1glob;
2glob) does not satisfy constraint (C
2). An analysis of the constraints (see Figure 8) shows that two feasible cases can be considered.If
<
p2, constraint (C
1) can be removed since, in this case, (1;
2) = (0;
0) is fully characterised by constraints (C
2) and (C
3), and therefore is the constrained minimum.If
>
p2, constraint (C
3) becomes redundant. Therefore, in this case, the minimum is obtained using the equalities corresponding to constraints (C
1) and (C
2). Therefore, in this case,1= 0 and 2 is the rst integer strictly greater than 2(2:2,2:,)2In both cases, inf(
;
) =q(+1+2)2+22 .γ γ
γ γ
1 2
1
2
,γ )
* * 1 2
(γglob,γglob)
2 1
(γ γ,
(A)
)
(B)
* (C ) (C )
* (C )
(C ) (C )2
3 1 1 2
glob glob 2
(γ1 ,γ ) (C )3
1 2
γ
O O
(
Figure 8: Graphical representation of the constraints (
C
1), (C
2) and (C
3). (A)>
p2. (B)
<
p2.(ii) Characterisation ofRsup(
;
).Let us assume that ab
>
. Following similar analysis to case (i), we have (1;
2) = (+1+ 2)2+ (+2)2. Again, we obtain the following minimisation problem. Given a valid integer pair (;
),min (
1;
2) subject to:(
C
1) 1>
22(,2(2)+,)2,22 (C
2) 10(
C
3) 20The global minimum of is (
1glob;
2glob) = (0;
,) and violates (C
3). Therefore,If
<
p2, the minimum is obtained for 2 = 0 and 1 is the rst integer strictly greater than 22(2,,)2.If
>
p2, (1;
2) = (0;
0).In both cases, Rsup(
;
) =q(+1+2)2+ (+2)2.We can summarise the analytical expressions for the Euclidean distance limits induced by (
;
) in Table 1 (note that in this case,dx
eis the smallest integer strictly greater thanx
).Rinf(
;
) =q(+1+2)2+22 Rsup(;
) =q(+1+2)2+ (+2)2
<
p2 1= 0;
2 = 0 1=l22(2,,)2m;
2 = 0
>
p2 1= 0;
2=l2(22,2,)2m 1 = 0;
2= 0 Table 1: Analytical expressions of the distance limits.Using these results, we can list the values of the limits for the smallest possible values of
and . Table 2 summarises the Euclidean distance limit values obtained when comparing ba with with the rst possible values of and .From the previous results, we can deduce that each possible combination of
a
,b
,and creates an increasing sequence when ordered such that2+2 increases (e.g., the expression ofRinf(;
)Rinf(
;
) Rsup(;
)2 3 p17 p8
3 4 p16 p34
3 5 p97 p18
4 5 p25 p80
4 7 p337 p32
Table 2: Numerical values Euclidean distance limits deduced from Table 1 for the rst instances of (
;
).when
>
p2 leads to the increasing sequencep17,p97,p337,,r+l2(2:2,2:,)2m2+l2(2:2,2:,)2m2,). Therefore, all possible Euclidean distance limits will be obtained as soon as we obtain a limit value for any range of ba. Using the two rst lines in the previous Table, we deduce that, for
32
<
ba<
2, R2(a;b
) = p8, for ba = 32, R2(a;b
) = p34, for 43 ba<
32, R2(a;b
) = p17, and for 1<
ba<
43,R2(a;b
) =p16.As pointed out earlier,R1(
a;b
) increases with the values of the DT coecients. Hence, clearlyR(
a;b
) =R2(a;b
) for any pair of DT coecients (a;b
)6= (2;
3). Now,R2(2;
3) =Rsup(3;
4) =p34, since 32>
43. From the result of characterisation of Type 1 error, we obtain R1(2;
3) = p8.Therefore, R(2
;
3) = min(R1(2;
3);
R2(2;
3)) =p8.Therefore, the maximal Euclidean distance achievable is maxf(a;b)gR(
a;b
) =p17. Clearly, the rst pair (a
,b
) which realizes this maximum is (a;b
) = (3;
4). Hence, Theorem 2 holds. 2 In summary, we have extended the results derived from the study presented in Section 2. The- orem 2 states that, for any DT coecients (a;b
) such that 43 ba<
32, the topological order is preserved in any discrete disc of radiusD
such thatR
max(D
)<
p17. In the design of algorithms which require chamfer distances, it is wise to maintain small values of the discrete distances com- puted. In this context, the minimum DT coecients for achieving the global upper bound ofp17 is (a;b
) = (3;
4). This is emphasised by the fact that the integer pair (a;b
) = (3;
4) is established as a global optimum for the approximation of Euclidean distance values.3 Nearest Neighbour Problem
In this section, we consider the problem of determining the minimal distance from a grid point to a given set of grid points. More formally, we can formulate the nearest neighbour problem as follows.
(P): Given a reference integer point
o
and a set of integer points ,, nd, using integer arithmetic, a pointq
2, such thatd
E(o;q
) = minp2,d
E(o;p
).Problem (P) is rst reformulated in order to take advantage of the theoretical results presented in Section 2 and to arrive at the Euclidean distance via integer arithmetic. The idea is to characterise two discrete distance bounds,
D
andD
0, between which a pointq
which is the exact solution to (P), will be located. The objective is to minimise distance comparisons in arriving at the exact Euclidean Distance. Using this technique, the search forq
is done using the discrete distanced
a;b(:;:
) rather than the continuous one (i.e.,d
E(:;:
)). From this formulation, we derive an exact algorithm which we express in a pseudo-code. Each step of this algorithm is then described using a graph-theoretic approach and shown to be optimal for the problem in question.Problem (P) can be equivalently formulated as follows. Given
o
and ,, letq
1 be the point suchthat:
d
a;b(o;q
1) = minp2,
d
a;b(o;p
)Following the results derived earlier,
q
1 can be considered as an approximation of the exact solutionq
. LetD
=d
a;b(o;q
1), then, the solution of (P) is given by the pointq
2, which is the solution to the following minimisation problem:minp
2,
d
E(o;p
) subject tod
a;b(o;p
)D
8p
2,Moreover,
R
max(D
) gives an upper bound to the distanced
E(o;q
). Using the previous characteri- sation of topological errors (Lemmas 4 and 5), we can dene another grid pointq
2 as the solution to:R
min(d
a;b(o;q
2)) = minp2,
Rmin(da;b(o;p))>Rmax(D)
R
min(d
a;b(o;p
))In other words, if we note
D
0=d
E(o;q
2),q
2 is the point in , closest too
such thatR
min(D
0)>
R
max(D
). Therefore, the solutionq
2, of (P) is the solution of the following constrained minimi- sation problem.minp
2,
d
E(o;p
) subject toD
d
a;b(o;p
)< D
0 8p
2,From this new formulation, we can readily implement the following algorithm for the solution of Problem (P).
Algorithm 1
1. Grow a discrete disc centred at
o
,a;b(o;D
), incrementally (D
= 1;
2;
3) until a pointq
12, is met.2. Let
D d
a;b(o;q
1),R
maxR
max(D
) andq q
13. Increase the radius of a;b(
o;D
) by 1 (D D
+ 1).4. If
R
min(D
)> R
max(i.e.,D
=D
0) then stop:q
is the solution.5. If9
p
2, such thatd
a;b(o;p
) =D
andd
E(o;p
)< d
E(o;q
) then, setq p
. 6. Go to Step 3.In Step 1,