Minimal-delay distance transform for neighborhood-sequence distances in 2D and 3D

9
Minimal-delay distance transform for neighborhood-sequence distances in 2D and 3D Nicolas Normand a,, Robin Strand b , Pierre Evenou a , Aurore Arlicot a a LUNAM Université, Université de Nantes, IRCCyN UMR CNRS 6597, Polytech Nantes, Rue Christian Pauc, La Chantrerie, 44306 Nantes Cedex 3, France b Centre for Image Analysis, Uppsala University, Sweden article info Article history: Received 3 November 2011 Accepted 29 August 2012 Available online 13 December 2012 Keywords: Distance transform Neighborhood-sequence distance Minkowski Sum Lambek–Moser inverse Beatty sequence abstract This paper presents a path-based distance, where local displacement costs vary both according to the displacement vector and with the travelled distance. The corresponding distance transform algorithm is similar in its form to classical propagation-based algorithms, but the more variable distance increments are either stored in look-up-tables or computed on-the-fly. These distances and distance transform extend neighborhood-sequence distances, chamfer distances and generalized distances based on Minkowski sums. We introduce algorithms to compute a translated version of a neighborhood sequence distance map both for periodic and aperiodic sequences and a method to derive the centered distance map. A decomposition of the grid neighbors, in Z 2 and Z 3 , allows to significantly decrease the number of displacement vectors needed for the distance transform. Overall, the distance transform can be computed with minimal delay, without the need to wait for the whole input image before beginning to provide the result image. Ó 2012 Elsevier Inc. All rights reserved. 1. Introduction In [1] discrete distances were introduced along with sequential algorithms to compute the distance transform (DT) of a binary im- age, where each point is mapped to its distance to the background. These discrete distances are built from adjacency and connected paths (path-based distances): the distance between two points is equal to the cost of the shortest path that joins them. For distance d 4 (‘‘d’’ in [1]), defined in the square grid Z 2 , each point has four neighbors located at its top, left, bottom and right edges. Similarly, for distance d 8 (‘‘d ’’ in [1]), each point has four extra diagonally lo- cated neighbors. In both cases, d 4 and d 8 , the cost of a path is de- fined as the number of displacements. These simple distances have been extended in different ways, by changing the neighbor- hood depending on the travelled distance [2,3], by weighting dis- placements [3,4], or even by a mixed approach of weighted neighborhood sequence paths [5]. Section 2 presents definitions of distances, balls and some prop- erties of non-decreasing integer sequences that will be used later. Section 3 introduces a new generalization of path-based distances, where displacement costs vary both on the displacement vector and on the travelled distance. An application is presented in Section 4 for the efficient computation of neighborhood-sequence DT in 2D and 3D. 2. Preliminaries 2.1. Lambek–Moser inverse of a integer sequence [6] Let the function f define a non-decreasing sequence of integers (f(1), f(2), ...) For the sake of simplicity, we call f a sequence. The in- verse sequence of f, denoted by f  , is a non-decreasing sequence of integers defined by: f ðmÞ < n () f y ðnÞ ¥ m: ð1Þ f  (n) can be seen as the count of values less than n in f, the last index of a value less than n in f, the index that precedes the first value greater than or equal to n: f y ðnÞ¼ Cardðfm : f ðmÞ < n¼ maxfm : f ðmÞ < ng or 0 if f ð1Þ P n or 1 if 8m; f ðmÞ < n ¼ minfm : f ðmÞ P ng 1 or 1 if 8m; f ðmÞ < n: ð2Þ Table 1 shows a non-decreasing sequence f and its inverse f  . f  (6) = 3 because there are exactly three values less than 6 in f: f(1), f(2) and f(3). An interesting property of a sequence f and its inverse f  is that, by adding the rank of each term to these two sequences, we obtain two complementary sequences f(m)+ m and f  (n)+ n [6], as shown in Table 1. This property extends the results given by Ostrowski, 1077-3142/$ - see front matter Ó 2012 Elsevier Inc. All rights reserved. http://dx.doi.org/10.1016/j.cviu.2012.08.015 Corresponding author. E-mail addresses: [email protected] (N. Normand), [email protected] (R. Strand), [email protected] (P. Evenou), [email protected] (A. Arlicot). Computer Vision and Image Understanding 117 (2013) 409–417 Contents lists available at SciVerse ScienceDirect Computer Vision and Image Understanding journal homepage: www.elsevier.com/locate/cviu

Transcript of Minimal-delay distance transform for neighborhood-sequence distances in 2D and 3D

Computer Vision and Image Understanding 117 (2013) 409–417

Contents lists available at SciVerse ScienceDirect

Computer Vision and Image Understanding

journal homepage: www.elsevier .com/ locate/cviu

Minimal-delay distance transform for neighborhood-sequence distances in 2Dand 3D

Nicolas Normand a,⇑, Robin Strand b, Pierre Evenou a, Aurore Arlicot a

a LUNAM Université, Université de Nantes, IRCCyN UMR CNRS 6597, Polytech Nantes, Rue Christian Pauc, La Chantrerie, 44306 Nantes Cedex 3, Franceb Centre for Image Analysis, Uppsala University, Sweden

a r t i c l e i n f o a b s t r a c t

Article history:Received 3 November 2011Accepted 29 August 2012Available online 13 December 2012

Keywords:Distance transformNeighborhood-sequence distanceMinkowski SumLambek–Moser inverseBeatty sequence

1077-3142/$ - see front matter � 2012 Elsevier Inc. Ahttp://dx.doi.org/10.1016/j.cviu.2012.08.015

⇑ Corresponding author.E-mail addresses: [email protected]

[email protected] (R. Strand), [email protected]@polytech.univ-nantes.fr (A. Arlicot).

This paper presents a path-based distance, where local displacement costs vary both according to thedisplacement vector and with the travelled distance. The corresponding distance transform algorithmis similar in its form to classical propagation-based algorithms, but the more variable distance incrementsare either stored in look-up-tables or computed on-the-fly. These distances and distance transformextend neighborhood-sequence distances, chamfer distances and generalized distances based onMinkowski sums. We introduce algorithms to compute a translated version of a neighborhood sequencedistance map both for periodic and aperiodic sequences and a method to derive the centered distancemap. A decomposition of the grid neighbors, in Z2 and Z3, allows to significantly decrease the numberof displacement vectors needed for the distance transform. Overall, the distance transform can becomputed with minimal delay, without the need to wait for the whole input image before beginningto provide the result image.

� 2012 Elsevier Inc. All rights reserved.

1. Introduction

In [1] discrete distances were introduced along with sequentialalgorithms to compute the distance transform (DT) of a binary im-age, where each point is mapped to its distance to the background.These discrete distances are built from adjacency and connectedpaths (path-based distances): the distance between two points isequal to the cost of the shortest path that joins them. For distanced4 (‘‘d’’ in [1]), defined in the square grid Z2, each point has fourneighbors located at its top, left, bottom and right edges. Similarly,for distance d8 (‘‘d⁄’’ in [1]), each point has four extra diagonally lo-cated neighbors. In both cases, d4 and d8, the cost of a path is de-fined as the number of displacements. These simple distanceshave been extended in different ways, by changing the neighbor-hood depending on the travelled distance [2,3], by weighting dis-placements [3,4], or even by a mixed approach of weightedneighborhood sequence paths [5].

Section 2 presents definitions of distances, balls and some prop-erties of non-decreasing integer sequences that will be used later.Section 3 introduces a new generalization of path-based distances,where displacement costs vary both on the displacement vectorand on the travelled distance. An application is presented in

ll rights reserved.

iv-nantes.fr (N. Normand),.univ-nantes.fr (P. Evenou),

Section 4 for the efficient computation of neighborhood-sequenceDT in 2D and 3D.

2. Preliminaries

2.1. Lambek–Moser inverse of a integer sequence [6]

Let the function f define a non-decreasing sequence of integers(f(1), f(2), . . .) For the sake of simplicity, we call f a sequence. The in-verse sequence of f, denoted by f�, is a non-decreasing sequence ofintegers defined by:

f ðmÞ < n() f yðnÞ¥m: ð1Þ

f�(n) can be seen as the count of values less than n in f, the last indexof a value less than n in f, the index that precedes the first valuegreater than or equal to n:

f yðnÞ ¼ Cardðfm : f ðmÞ < ngÞ¼ maxfm : f ðmÞ < ng or 0 if f ð1ÞP n or 1 if 8m; f ðmÞ < n

¼ minfm : f ðmÞP ng � 1 or 1 if 8m; f ðmÞ < n: ð2Þ

Table 1 shows a non-decreasing sequence f and its inverse f�. f�

(6) = 3 because there are exactly three values less than 6 in f: f(1),f(2) and f(3).

An interesting property of a sequence f and its inverse f� is that,by adding the rank of each term to these two sequences, we obtaintwo complementary sequences f(m) + m and f�(n) + n [6], as shownin Table 1. This property extends the results given by Ostrowski,

Table 1Example of a non-decreasing sequence f and its Lambek–Moser inverse. f is the cumulative sequence of the periodic sequence (1, 2,0,3), f� its inverse. f�(6) = 3 because there areexactly three values less than 6 in f. Each positive integer appears exactly once in the range of f(n) + n or f�(m) + m. f�(f(n) + 1) + 1 locates the rank of the next f increase.

m Or n 1 2 3 4 5 6 7 8 9 10 11 12 13 14

f(n) 1 3 3 6 7 9 9 12 13 15 15 18 19 21f�(m) 0 1 1 3 3 3 4 5 5 7 7 7 8 9f(n) + n 2 5 6 10 12 15 16 20 22 25 26 30 32 35f�(m) + m 1 3 4 7 8 9 11 13 14 17 18 19 21 23f�(f(n) + 1) + 1 2 4 4 5 6 8 8 9 10 12 12 13 14 16

410 N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417

Hyslop, and Aitken [7] about Beatty sequences [8]. From [6], we de-duce that the inverse of the sequence f(m) = bsmc with a scalar s, isf yðnÞ ¼ n

s� 1� �

so f(m) + m = b(1 + s)mc and f yðnÞ þ n ¼1þ 1

s

� �n� 1

� �are two complementary sequences. If s is irrational,

these sequences are Beatty sequences and, for any positiven; 1þ 1

s

� �n� 1

� �is equal to 1þ 1

s

� �n

� �as given in [8].

Hajdu and Hajdu [9] introduced Beatty sequences in the contextof neighborhood-sequence distances [9]. Beside their interest indefining neighborhood sequences, Lambek–Moser inverse se-quences will be used in following Section 3.2 as a link betweenthe propagation of distance values and the construction of disks.With Proposition 1, we introduce a new use of the Lambek–Moserinverse to iterate over non-decreasing integer sequences.

Proposition 1. f�(f(m) + 1) + 1 is the rank of the smallest term greaterthan m, where f increases.

Proof.

f yðf ðmÞ þ 1Þ þ 1 ¼ m0 () f yðf ðmÞ þ 1Þ < m0

f yðf ðmÞ þ 1ÞP m0 � 1

�()

f ðm0ÞP f ðmÞ þ 1f ðm0 � 1Þ < f ðmÞ þ 1

�() f ðm0Þ > f ðmÞ and f ðm0 � 1Þ 6 f ðmÞ: �For example, in Table 1, f(6) = 9, f�(f(6) + 1) + 1 = 8 is the rank of

appearance of the first value greater than 9, which is 12 in thiscase. If we extend f with f(0) = 0, and define g by g(0) = 0,g(n + 1) = f�(f(g(n)) + 1) + 1, then f(g(n)) takes, in increasing order,all the values of f, each one appearing once.

2.2. Path-based distances

Definition 1 (Discrete distance). A function d : Zn � Zn ! N is atranslation-invariant distance if the following conditions hold8x; y; z:

1. translation invariance d(x + z,y + z) = d(x,y),2. positive definiteness d(x,y) P 0 and d(x,y) = 0, x = y,3. symmetry d(x,y) = d(y,x).

In the following sections, we will drop definiteness and symme-try to define ‘‘asymmetric pseudo-distances’’.

Definition 2 (Path-based distance). Let Pðp; qÞ be the set of pathsfrom p 2 Zn to q 2 Zn. d : Zn � Zn ! N is a path-based distance if:

(i) 8ðp; qÞ; dðp; qÞ ¼minfLðPÞ; P 2 Pðp; qÞg,(ii) d is a distance,

where LðPÞ is the length (or cost) of the path P. A path P 2 Pðp; qÞ isminimal if its length is equal to d(p,q). It is usually not unique be-tween p and q.

Definition 3 (k-neighbor). In the nD square, cubic or hypercubicgrid, two points p and q are k-neighbors, 0 < k 6 n, if their cubiccells share a face of dimension at least n � k, i.e.:Xi¼1...n

jpi � qij 6 k;

maxi¼1...nfjpi � qijg 6 1;

ð3Þ

where pi stands for the ith component of p.

The k-neighborhood of p, denoted by N kðpÞ, is the set of k-neighbors of p and the k-neighborhood N k, in a translation-invariant context, is the set of vectors from any point p to its k-neighbors. In the 2D square grid, k-neighborhoods are definedas follows:

N 1 ¼ fð0;0Þ; ð�1;0Þ; ð0;�1Þg andN 2 ¼ fð0;0Þ; ð�1;0Þ; ð0;�1Þ; ð�1;�1Þg:

N 1 and N 2 are often referred to as 4- and 8-neighborhoods becausethey contain respectively four and eight non-zero displacementvectors.

For distance d4, a path is a sequence of points (p0, . . . , pn), whereeach pair of successive points (pi�1,pi) are 1-neighbors and thelength of the path is the number of displacements, n. Whereasthe 2-neighborhood is used for distance d8 [1,2]. Distances d4 andd8 have a high rotational dependancy as noticed by Rosenfeldand Pfaltz.

A neighborhood sequence (NS) B = (b(i))i>0 is a sequence, whereeach b(i) denotes a neighborhood relation in Zn in the sense of Def-inition 3. If B is l-periodic, i.e. if for some finite, strictly positivel 2 Zþ, b(i) = b(i + l) is valid for all i 2 N�, then we write

B ¼ ðbð1Þ; bð2Þ; . . . ; bðlÞÞ. A B-path is a sequence of points (p0, . . . ,pn), where each pair of successive points (pi�1,pi) are B(i)-neigh-bors. Given the NS B, the NS-distance dB is the path-based distancewhose paths are only B-paths and the length of a path is the num-ber of displacements. d4 and d8 can be seen as NS-distances dð�1Þ and

dð�2Þ with 1-periodic sequences B ¼ ð�1Þ and B ¼ ð�2Þ, but the simplestNS-distance that combines both neighborhoods is the octagonaldistance dð1;2Þ with sequence B ¼ ð1;2Þ [2].

The notation 1B(r) for N 1, more generally, jB(r) for N j, is usedto count the occurrences of the neighborhood in B up to positionr:

jBðrÞ ¼ Cardðfi : bðiÞ ¼ j;1 6 i 6 rgÞ:

A different approach is used for chamfer, or weighted, distances,where each displacement vector vk

! in a neighborhood N is asso-ciated to the weight (or local cost) wk [3,4,10]. A chamfer maskM isa central symmetric set of weightings ð vk

!; wkÞ with at least a base

of Zn:

M¼ fð vk!

; wkÞ 2 Zn �N�g16k6m:

N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417 411

The length of the path (p0, . . . , pn) is the sum of the displace-ments costs:

Lðp0; . . . ;pnÞ ¼Xn

i¼1

wðiÞ; where ðpi�1pi!

; wðiÞÞ 2 M:

Definition 4 (Ball). The disk D(p,r) of center p and radius r and thesymmetrical disk D(p,r) are the sets:

Dðp; rÞ ¼ fq : dðp; qÞ 6 rg;�Dðp; rÞ ¼ fq : dðq;pÞ 6 rg:

ð4Þ

By definition, any disk of negative radius is empty and the diskof radius 0 only contains its center (D(p,0) = {p}).

Definition 5 (Distance transform). The distance transform DTX ofthe set X is a function that maps each point p to its distance fromthe complement of X:

Fig. 1. Total cost of a path P = (p0,p1,p2). Costs of displacements p0p1!

;p1p2! and p2p3

!depend on the partial costs L0ðPÞ ¼ 0; L1ðPÞ ¼ c ~p0p1

ð0Þ þ 0 andL2ðPÞ ¼ cp1p2

!ðL1ðPÞÞ þ L1ðPÞ. The total cost of P is cp2p3!ðL2ðPÞÞ þ L2ðPÞ.

DTX : Zn ! N

DTXðpÞ ¼minfdðq;pÞ : q 2 Zn n Xg:ð5Þ

Alternatively, since all points at a distance less than DTX(p) to pbelong to X, because D(p,DTX(p) � 1) � X, and at least one point at adistance to p equal to DTX(p) is not in X, because D(p,DTX(p)) å X,then:

DTXðpÞP r () �Dðp; r � 1Þ � X: ð6Þ

The DT is usually defined as the distance to the backgroundwhich is equivalent to the distance from the background by sym-metry. The equivalence is lost with asymmetric distances, and thisdefinition better reflects the fact that DT algorithms always propa-gate paths from the background points.

Efficient algorithms exist to compute the DT of path-based dis-tances based on the propagation of values from the neighbor pointswith the addition of local costs. They require two scans in reverseorders for the simple d4 and d8 distances [1], two scans for chamferdistances [3,4]. NS-distances have an extra complexity because thecost of a path is not invariant to the order of its displacement vec-tors. NS–DT algorithms are known with four scans [11] and threescans [12].

2.3. Path-based distances and displacement costs

In the following, we show that path-based distances presentedin Section 2.2, despite having different definitions of paths andpath lengths, can be described with a unique paradigm in whichthey are only characterized by the local costs of displacementvectors.

For a simple distance, a path is a sequence of points, wherethe difference between two successive points is a displacementvector taken in a fixed neighborhood N , and the cost (or length)of a path is the number of its displacements. The cost of thepath ðp0; . . . ; pn; pn þ~vÞ derives from the cost of the path(p0, . . . ,pn):

Lðp0; . . . ;pnÞ ¼ r ) 8~v 2 N ;Lðp0; . . . ; pn; pn þ~vÞ ¼ r þ 1: ð7Þ

Rosenfeld and Pfaltz specifically forbid paths, where a point ap-pears more than once [1]. This restriction has no effect on the dis-tance because a path, where a point appears more than once cannot be minimal. In a similar manner, they exclude the null vectorfrom the neighborhood, forbidding a point to appear several timesconsecutively. As before, it has no effect on the distance. Notice

that, in terms of distance, forbidding a path is equivalent to givingit an infinite cost, so that it can not be minimal. Eq. (7) can berewritten as:

Lðp0; . . . ; pnÞ ¼ r ) 8~v ;Lðp0; . . . ;pn;pn þ~vÞ ¼ r þ c~v ;

where

c~v ¼1 if ~v 2 N1 otherwise

�:

For a NS-distance characterized by the sequence B:

Lðp0; . . . ; pnÞ ¼ r ) 8~v ;Lðp0; . . . ;pn;pn þ~vÞ ¼ r þ cB~vðrÞ; ð8Þ

where the displacement cost cB~vðrÞ is 1 for a displacement vector in

the neighborhood B(r + 1) and infinite otherwise:

cB~vðrÞ ¼

1 if ~v 2 N Bðrþ1Þ

1 otherwise

�: ð9Þ

For a weighted distance with mask M¼ fð~vk; wkÞ 2Zn �N�g16k6m, the distance increment only depends on the dis-placement vector, but not on the distance already travelled:

Lðp0; . . . ; pnÞ ¼ r ) 8~v ;Lðp0; . . . ;pn;pn þ~vÞ ¼ r þ c~v ; ð10Þ

c~v ¼w if ð~v; wÞ 2 M1 otherwise

�: ð11Þ

Briefly, the displacement cost for a vector ~v and the travelleddistance r, is 1 or 1, independently of r for simple distances, isequal to 1 or1whether~v belongs or not to N BðrÞ for a NS-distance,is in N� [ f1g according to the chamfer mask and independently ofr for a weighted distance.

In the following, we propose to use a displacement cost, de-noted by c~vðrÞ, with values in N� [ f1g, that depends both onthe displacement vector ~v and on the travelled distance r. Accord-ing to the previous remarks, the cost associated to the null dis-placement will always be unitary:

8r 2 N; c~0ðrÞ ¼ 1: ð12Þ

3. Path-based distance with varying weights

3.1. Definition and properties

Definition 6 (Path). We call path from p to q, any finite sequence ofpoints P = (p = p0,p1, . . . ,pn = q) with at least one point, and denoteby Pðp; qÞ, the set of these paths.

Notice that this definition of a path is not related to any adja-cency relation. The sequence P = (p) is allowed as a path from pto itself. It is distinct from P = (p,p), the path from p to itself witha null displacement.

(a)

(b)Fig. 2. (a) Given P = (p0,p1,p2), shown with dashed lines, has a total cost LðPÞ ¼ 8 measured with displacement costs c~v . P0 = (p0,p1,p1,p1,p2,p2), solid lines, is built in such away that its cost L0ðP0Þmeasured with minimal displacement costs c~v , is equal to LðPÞ ¼ 8. (b) Given P0 = (p0,p1,p2), shown with solid lines, has a total cost L0ðP0Þ ¼ 7 measuredwith displacement costs c~v . P = (p0,p0,p1,p1,p1,p1,p2), dashed lines, is built in such a way that LðPÞ ¼ L0ðP0Þ ¼ 7.

412 N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417

Definition 7 (Partial and total costs of a path). Let N be a set ofvectors containing the null vector ~0 and the positive displacementcosts c~v (with c~0ðrÞ ¼ 1 and c~vRN ðrÞ ¼ 1). The total cost of the pathP = (p0,p1, . . . ,pn) is:

LðPÞ ¼ LnðPÞ;L0ðPÞ ¼ Lðp0Þ ¼ 0;Liþ1ðPÞ ¼ Lðp0; . . . ;piþ1Þ ¼ LiðPÞ þ C

pipiþ1!ðLiðPÞÞ;

ð13Þ

where LiðPÞ is the partial cost of the path truncated to its i + 1 firstpoints (i.e. to its i first displacements).

Fig. 1 illustrates the individual displacement costs in a path,each one depending on the partial length of the path.

Definition 8 (Absolute and relative costs of displacement). We usethe notation C vk

!ðrÞ ¼ r þ c vk!ðrÞ. c vk

!ðrÞ is the relative cost of thedisplacement vk

! when the distance travelled so forth is r. C vk!ðrÞ

represents the partial cost of the path after this displacement (theabsolute cost of this displacement):

Liþ1ðPÞ ¼ LiðPÞ þ cpipiþ1!ðLiðPÞÞ ¼ C

pipiþ1!ðLiðPÞÞ: ð14Þ

Definition 9 (Pseudo-distance). The pseudo-distance induced byðf vk!g; c vk

!Þ is defined by:

dðp; qÞ ¼ 0() p ¼ q

dðp; qÞ ¼ minP2Pðp;qÞ

fLðPÞg:

Definition 10 (Minimal cost of displacement). We call minimal rel-ative (resp. absolute) cost of displacement, denoted by c (resp. bC),the quantity c~v ðrÞ ¼ minfc~v ðsÞ þ s� r;8s P rg (resp.bC~v ðrÞ ¼minfC~vðsÞ;8s P rg).

Proposition 2 (Preservation of cost order by concatena-tion). Appending the same displacement to existing paths preservesthe relation order of their costs. Let P ¼ ðp1; . . . ; pnP

Þ andQ ¼ ðq1; . . . ; qnQ

Þ be two paths with costs LðPÞ and LðQÞ;~v a vectorand P0 ¼ ðp1; . . . ; pnP

; pnPþ~vÞ;Q 0 ¼ ðq1; . . . ; qnQ

; qnQþ~vÞ the extended

paths with costs LðP0Þ and LðQ 0Þ measured with minimal displace-ment costs. Then:

LðPÞ 6 LðQÞ ) LðP0Þ 6 LðQ 0Þ: ð15Þ

Proof. From (14), LðP0Þ ¼ bC~vðLðPÞÞ and LðQ 0Þ ¼ bC~vðLðQÞÞ. By defi-nition of bC~v ; s 6 r ) bC~v ðsÞ 6 bC~v ðrÞ, which gives (15). h

Proposition 3. Let N ¼ f~vkg be a set of vectors and, c~v ðrÞ, the dis-placement costs for these vectors. There exists a path P from p to qof cost LðPÞ ¼ r measured with costs c~v ðrÞ if and only if there existsa path P0 from p to q of cost L0ðP0Þ ¼ r measured with the minimal dis-placement costs c~vðrÞ.

Proof. Consider the cost of P after i displacements,LiðPÞ ¼ Liðp0; p1; . . . ; piÞ, we notem0 ¼ 1; m0<i6n ¼ 1þ LiðPÞ � Li�1ðPÞ � cpi�1pi

!ðLi�1ðPÞÞ ¼

1þ cpi�1pi!ðLi�1ðPÞÞ � cpi�1pi

!ðLi�1ðPÞÞ and Mi ¼Pi

j¼0mi the cumu-

lated sum of mi. Clearly, if LðPÞ is finite then each mi is finite andpositive because c~vðrÞ is less than or equal to c~v ðrÞ by construction.Let P0 be the (finite) path obtained by mi occurrences of each pointpi:

P0 ¼ p0;p1 . . . p1|fflfflfflfflffl{zfflfflfflfflffl}m1

; . . . ; pi . . . pi|fflfflfflffl{zfflfflfflffl}mi

; . . . ;pn . . . pn|fflfflfflffl{zfflfflfflffl}mn

0B@1CA:

We take as an induction hypothesis that the partial cost of P0

after mi occurrences of pi;L0Mi�1ðP0Þ, is equal to LiðPÞ. It holds for

i = 0 because L0M0�1ðP0Þ ¼ L0m0�1ðP

0Þ ¼ L00ðP0Þ ¼ 0 ¼ L0ðPÞ. If the

hypothesis holds for i � 1, then the partial cost of P0 after the firstoccurrence of pi is L0Mi�1

ðP0Þ ¼ Li�1ðPÞ þ cpi�1pi!ðLi�1ðPÞÞ, and after

mi � 1 repeats of pi, equals L0Mi�1þmi�1ðP0Þ ¼ L0Mi�1ðP

0Þ ¼ Li�1ðPÞþcpi�1pi!ðLi�1ðPÞÞ þmi � 1 ¼ Li�1ðPÞ þ cpi�1pi

!ðLi�1ðPÞÞ ¼ LiðPÞ and

the hypothesis is true at rank i. Therefore, for every path of finitecost r measured with L, there exists a path with the same costmeasured with L0. This is shown in Fig. 2a.

Conversely, let P0 be a path with finite cost measured by L0. Webuild a path P, where each point of P0 appears m0i times consec-utively with m0i such that m0i � 1þ cpipiþ1

!ðL0iðP0Þ þm0i � 1Þ ¼

cpipiþ1!ðL0iðP0ÞÞ. By definition of c;8r; 9s : c~v ðrÞ ¼ c~v ðsÞ þ s� r, so

m0i exists. Let M00 ¼ 0 and M00<i6n ¼Pi�1

j¼0mj, be the cumulated sumof the previous terms of m0i.

The induction hypothesis is that the partial cost of P, measuredwith L, at the first occurence of pi;LM0i

ðPÞ, is equal to L0iðP0Þ. It holds

for i = 0 with a null partial cost LM00ðPÞ ¼ L0ðPÞ ¼ 0 ¼ L00ðP

0Þ. If thehypothesis holds at rank i, the partial cost of P, after m0i � 1repetitions of pi, if LM0iþm0

i�1ðPÞ ¼ LM0i

ðPÞ þm0i � 1 ¼ L0iðP0Þ þm0i � 1,

and at the first occurence of pi+1, equals

Table 3Displacement costs for the decomposition of N 01 and N 02, (a) and(b). In (c), minimal relative displacement costs of the alternateconcatenation of (a) and (b) providing a translated octagonaldistance with intermediate disks.

N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417 413

L0iðP0Þ þm0i � 1þ cpipiþ1

!ðL0iðP0Þ þm0i � 1Þ ¼ L0iðP0Þþ

cpipiþ1!ðL0iðP0ÞÞ ¼ L0iþ1ðP

0Þ and the hypothesis also holds at rank

i + 1. An example of such a path is shown on Fig. 2b. h

r 0 1

(a)c1ð1;0ÞðrÞ 1 1

c1ð�1;1ÞðrÞ 2 1

c1ð0;1ÞðrÞ 1 1

c1ð1;1ÞðrÞ 2 1

(b)c2 ðrÞ 1 1

Corollary 1. Displacement costs c~v and c~v induce the same pseudo-distance.

According to (12), any path from p to q of cost less than r can beextended with null displacements to reach cost r:Lðp0; . . . ;pn ¼ qÞ ¼ s < r ) Lðp0; . . . ;pn ¼ q; . . . ; q|fflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflffl}

1þr�s

Þ ¼ r: ð16Þ

ð1;0Þ

c2ð�1;1ÞðrÞ 1 1

c2ð0;1ÞðrÞ 1 1

Proposition 4. There exists a path of cost r from p to q if and only ifd(p,q) 6 r.

c2ð1;1ÞðrÞ 1 1

r 0 1 2 3

(a)cð1;0ÞðrÞ 3 2 1 1

cð�1;1ÞðrÞ 2 5 4 3

cð0;1ÞðrÞ 1 1 1 1

Proof. If a path of cost r from p to q exists then by definition of thedistance, d(p,q) = r if P cost is minimal, d(p,q) < r otherwise. Con-versely, if d(p,q) = s then there exists a path of cost s from p to qthat, according to (16), can be extended to cost r P s. h

cð1;1ÞðrÞ 2 2 1 1

Corollary 2. For any value of r greater than or equal to d(p,q), thereexists a path from p to q which cost is exactly r. The closed disk cen-tered in p with radius r is the set of points for which a path from pof cost equal to r exists:

q 2 Dðp; rÞ () 9P 2 Pðp; qÞ;LðPÞ ¼ r: ð17ÞAn iterative construction rule of balls is deduced from (17):

8r > 0;Dðp; rÞ ¼[~v2Nfq : 9P 2 Pðp; q�~vÞ and C~vðLðPÞÞ ¼ rg

¼[

~v 2 Ns : C~vðsÞ ¼ r

Dðpþ~v ; sÞ: ð18Þ

3.2. Iterative construction of shapes

Let (D(O,r)) be a sequence of balls built iteratively using:

DðO; rÞ ¼

; if r < 0fOg if r ¼ 0[~v2N

DðOþ~v ; S~vðrÞ � 1Þ otherwise

8>><>>: ð19Þ

where the construction values S~v are non decreasing sequences ofnatural integers, in particular 8r > 0; S~0ðrÞ ¼ r. A generalized dis-tance that produces these balls was shown in [13], along with amethod to decompose any convex polygon into a sequence of ballswith a few neighbors ~v . Examples of such decompositions areprovided in Fig. 5 and Tables 2 and 3 for the 2D case, in Fig. 6 andTable 4 for the 3D case.

Table 2Construction values for the decomposition of the two neighborhoods in 2D.

r 1 2

S1ð1;0ÞðrÞ 0 0

S1ð�1;1ÞðrÞ 0 1

S1ð0;1ÞðrÞ 1 2

S1ð1;1ÞðrÞ 0 1

S2ð1;0ÞðrÞ 1 2

S2ð�1;1ÞðrÞ 0 0

S2ð0;1ÞðrÞ 1 2

S2ð1;1ÞðrÞ 1 2

Using the Lambek–Moser inverse and notations used in this pa-per, we can reformulate the expression of the displacement costsfrom the construction rules as:

8r P 0; C~vðrÞ ¼ Sy~vðr þ 1Þ þ 1: ð20ÞNote that a finite sequence of balls with maximal radius l is

practically equivalent to an infinite sequence of balls, where allballs with radii greater than or equal to l are equal. In this case,all values of S~v at index l and beyond are equal and do not exceedthe value l. As a consequence, C� is infinite at index l and beyond.

3.3. Sequences of Minkowski sums

Proposition 5. If all finite values of absolute costs for radii less thanr1 do not exceed r1 ("0 6 r < r1, C(r) 6 r1 or C(r) =1) then all balls ofradius r2 greater than or equal to r1 are the Minkowski sum of D(p,r1)with the disk D0(O,r2 � r1) produced by the displacement costsc0~v ðrÞ ¼ c~vðr þ r1Þ (i.e. C0~vðrÞ ¼ C~vðr þ r1Þ � r1):

8r < r1;CðrÞ 6 r1 ) 8r2 P r1;Dðp; r2Þ¼ Dðp; r1Þ � D0ðO; r2 � r1Þ: ð21Þ

Proof. (21) holds for r2 = r1: D(p,r1) = D(p,r1) � {O}. Suppose (21)holds in the interval [r1,r2]. Only values of s in the interval [r1,r2]can be such that C~v ðsÞ ¼ r2 þ 1 and (21) applies to Dðpþ~v ; sÞ, so(18) can be written as:

Dðp; r2 þ 1Þ ¼[

~v 2 N

s : C~vðsÞ ¼ r2 þ 1

Dðpþ~v; r1Þ � D0ðO; s� r1Þ

¼ Dðpþ~v ; r1Þ �[

~v 2 N

s : C~vðsÞ ¼ r2 þ 1

D0ðO; s� r1Þ

¼ Dðpþ~v ; r1Þ �[

~v 2 N

s : C 0~vðsÞ ¼ r2 � r1 þ 1

D0ðO; sÞ

¼ Dðpþ~v ; r1Þ � D0ðO; r2 � r1 þ 1Þ:

Hence, (21) holds in the interval [r1,r2 + 1]. h

Table 4Construction values for the decomposition of the 3D neighborhoods. Only strictly positive values are shown.

r N 1 N 2 N 3

1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

(0,0,1) 4 5 4 5 4 5

(0,�1,1) 4

(0,1,1) 4

(�1, 0, 1) 4 3

(1,0, 1) 4 3

(0,1,0) 1 2 1 2

(1,0, 0) 1 2

(1,1,0) 1 1 2

(�1,1,0) 1

414 N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417

Proposition 5 provides a sufficient (but not necessary) conditionthat enables to build sequences of Minkowski sums. In particular,when relative displacement costs are either 1 or 1 as in (9), thenProposition 5 applies to all positive radius values so that the NS-distance balls are produced by a sequence of Minkowski sums withthe sequence of neighborhoods, as it is well known. In the follow-ing Section 4.4, Proposition 5 will be used along with (19) and (20)to build sequences of balls in which Minkowski sums are decom-posed into several steps.

4. Minimal delay NS-distance transform

In [14], Wang and Bertrand, proposed a single scan asymmetricgeneralized DT based on a neighborhood for which there exists ascanning order such that when a point p in the image is scanned,all neighbors of p have already been scanned (forward scan condi-tion). Then, they extended this result to a sequence, where twoneighborhoods with forward scan condition are alternated (i.e.B = (1,2)) [15]. In the following we propose a method to compute,using a single raster scan, an asymmetric generalized DT based onany number of neighborhoods having forward scan condition usedin an arbitrary order defined by a sequence B, either periodic or not.For our purpose, we will use translated versions of regular NS-dis-tances neighborhoods, in order to meet the forward scan conditionfor each of them. The resulting translated distance map can easilybe transformed back into a regular, symmetrical, NS-distance map.

4.1. Generalized distance transform

Proposition 6. The DT of an image X with the distance induced by theneighborhood N and the displacement costs C~v is such that:

DTXðpÞ ¼0 if p R X

minfbC~vðDTXðp�~vÞÞ;~v 2 N �g otherwise

(: ð22Þ

where bC~v represents the minimal absolute displacement costs corre-sponding to C~v (Definition 10).

Proof. Case p R X directly results from Definitions 5 and 9. Supposenow that p 2 X so any path from q R X to p has at least onedisplacement. Proposition 3 states that distances induced byðf vk!g;C vk

!Þ and ðf vk!g; bC vk

!Þ are equal so we consider the latter

cost increments for which Proposition 2 holds. According toProposition 2, if P ¼ ðq ¼ p0; . . . ; pn ¼ p�~vÞ is a minimal pathfrom q to p�~v then P0 ¼ ðq ¼ p0; . . . ; pn; pþ~vÞ has a minimalcost—among paths from q to p with second last point p�~v—equalto bC~vðLðPÞÞ. So bC~vðDTXðp�~vÞÞ is the shortest distance from a pointq R X to p via p�~v . Since all paths which last displacement ~v doesnot belong to N have an infinite cost and can not be minimal, (22)holds. h

When all vectors in N� are directed forward relatively to thescan order, (22) propagates paths from background pixels in a sin-gle scan. As a consequence, a generalized DT using any number ofneighborhoods N 1; . . . ; N n, selected by a sequence B,B(i) 2 [1,n],derives directly from (9) and (22) and minimal costs given by:bC~vðrÞ ¼minfs : s > r and ~v 2 N BðsÞg: ð23Þ

Let v~v ðrÞ denote the characteristic function of the set N BðrÞ (i.e.v~v ðrÞ ¼ 1 if ~v 2 N BðrÞ; 0 otherwise) and vR

~v ðrÞ its cumulative sumvR~v ðrÞ ¼

Ps6rv~v ðrÞ

� �. Then according to Proposition 1:bC~vðrÞ ¼ vR

~v� �y vR

~v ðrÞ þ 1� �

þ 1: ð24Þ

Algorithm 1 produces a generalized DT using any sequence ofneighborhoods (N represents their union) in forward scan condi-tion, using displacement costs given by (24). A similar algorithmwas already presented for the decomposition of convex structuringpolygons [13].

Algorithm 1. Single scan generalized distance transform

Data: X: a set of pointsData: N : neighborhood in forward scan condition

Data: bC~v : minimal absolute displacement costsResult: DTX: generalized distance transform of Xforeach p in DT domain, in raster scan do

if p R X thenDTX(p) 0;

elsel 1;foreach ~v in N do

l minfl; bC~vðDTXðp�~vÞg;end

DTX(p) l;end

end

(a) (b) (c) (d) (e) (f)Fig. 3. Neighborhoods used for the translated NS-distance transform. (a) and (b) arerespectively the types 1 and 2 translated neighborhoods, N 01 and N 02. (c)–(e) arerespectively N 01 n N

02; N

02 n N

01 and N 01 \ N

02, each set associated to a different

N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417 415

sequence of displacement costs. (f) is the whole set of neighbors, N 01 [ N02, used for

the translated NS–DT.

4.2. Translated NS-distance transform

The sequence of balls for a NS-distance induced by a sequence Bis produced by iterative Minkowski sums of neighborhoods:

Dðp;0Þ ¼ fpg; Dðp; rÞ ¼ Dðp; r � 1Þ � N BðrÞ:

For each neighborhoodN j, we apply a translation vector tj!

suchthat the translated neighborhoodN 0j ¼ N j � f tj

!g is in forward scancondition. In a translation preserved scan order, tj

!translates the

first visited point inN j to the origin. Assuming a nD standard rasterscan order:

tj!¼ 0; . . . ;0|fflfflfflffl{zfflfflfflffl}

n�j

;1; . . . ;1|fflfflfflffl{zfflfflfflffl}j

0B@1CA: ð25Þ

The translated neighborhoods N 01 and N 02 obtained witht1!¼ ð0;1Þ and t2

!¼ ð1;1Þ are depicted in Fig. 3a and b. Character-istic functions for vectors in N 01 n N

02; N

02 n N

01 and N 01 \ N

02 (see

Fig. 3c–e) are respectively the first differences of 1B, 2B and the con-stant value 1 resulting in the following minimal displacementcosts:

bC~vðrÞ ¼

bC 1~vðrÞ ¼ 1yBð1BðrÞ þ 1Þ þ 1 if ~v 2 N 01 and ~v R N 02bC 2~vðrÞ ¼ 2yBð2BðrÞ þ 1Þ þ 1 if ~v R N 01 and ~v 2 N 02bC 12~v ðrÞ ¼ r þ 1 if ~v 2 N 01 and ~v 2 N 02

8>><>>: :

Periodic sequence When B is a periodic sequence, minimal relativecosts c~v are also periodic sequences. Take the periodic sequence of theoctagonal distance B ¼ ð1;2Þ, then 1BðrÞrP0 ¼ ð0;1;1;2; . . .Þ;1yBðrÞr > 0 ¼ ð0;2;4; . . .Þ; bC1

~vðrÞrP0 ¼ ð1;3;3;5 . . .Þ and c1~v ðrÞrP0 ¼

ð1;2;1;2 . . .Þ. 1B(r)r>0 is the cumulative sum of the 2-periodic se-quence ð1;0Þ, whereas 1yBðrÞr>0 is the cumulative sum with offset �2of the 1-periodic sequence ð�2Þ as given by Algorithm 2. Similarly,2BðrÞrP0 ¼ ð0;0;1;1;2; . . .Þ; 2yBðrÞr>0 ¼ ð1;3; . . .Þ;bC2

~vðrÞrP0 ¼ ð2;2;4 . . .Þ and c2~v ðrÞrP0 ¼ ð2;1;2;1 . . .Þ.

Rate-based sequence Suppose now that the sequence ofneighborhoods is defined as the first difference of a Beatty se-quence (as in [9]): B(r) = bsrc � bs (r � 1)c, with s 2 [1,2] so thatB(r) 2 {1,2}. 1B and 2B are respectively the cumulative sums

(a) (b)Fig. 4. (a) Octagonal DT of a binary image. (b) Translated octagonal DT. Outlined centTranslated octagonal DT with intermediate disks.

of 2 � B(r) = d(2 � s)re � d(2 � s)(r � 1)e and B(r) � 1 = b(s � 1)rc� b(s � 1)(r � 1)c. Then 1BðrÞ ¼ dð2� sÞre; 2BðrÞ ¼bðs� 1Þrc; 1yBðrÞ ¼ r�1

2�s

� �and 2yBðrÞ ¼ r

s�1� 1� �

. This allows to com-pute bC1

~v and bC2~v on the fly. For the octagonal distance,

s ¼ 32 ; 1BðrÞ ¼ r

2

� �; 2BðrÞ ¼ r

2

� �; 1yBðrÞ ¼ 2r � 2 and 2yBðrÞ ¼ 2r � 1.

Algorithm 2. Computation of gR ¼ f Ry, inverse of the sequence fR.fR is the cumulative sequence of the fp-periodical non-negativesequence f with constant offset fo and negative values clipped to 0:8r > 1; f RðrÞ ¼max 0; fo þ

Prs¼1f ðsÞ

�. Likewise, gR is the cumula-

tive sequence of the gp-periodical non-negative sequence g withoffset go and negative values clipped to 0.

Data: fp, f(1) � � � f(fp) and fo

Result: gp, g(1) � � � g(gp) and go gp !Pfp

i¼1f ðiÞ;n = fo + 1;m0 fp;for m ? 1 to fp do

if f(m) – 0 then m0 ? min{m0;m};g(n) ? g(n) + 1;n ? n + f(m);

endgo ? m0 � 1 � g(fo + 1);for m ? 1 to�fo do go ? go + g(m + fo); // Adjust go if fo < 0;endfor m ? 0 down to �fo do go ? go � g(m + fo); //. . . or if

fo P 0;end

An exemple result of Algorithm 1 for the translated octagonaldistance (with displacement costs obtained either from sequenceB = (1,2) either from s ¼ 3

2) is shown in Fig. 4b.

4.3. Symmetric DT from asymmetric DT

Let f~tðrÞ; r 2 N�g be a sequence of translation vectors such thatthe translated disks D0ðp; rÞ ¼ Dðpþ~tðrÞ; rÞ and�D0ðp; rÞ ¼ �Dðp�~tðrÞ; rÞ are increasing according to the set inclusion.For a sequence of disks produced by translated neighborhoods de-fined in (25), the translation vectors are:

~tðrÞ ¼~tðr � 1Þ þ tBðrÞ! ¼X

j

jBðrÞ tj!¼

Xn

j¼n

jBðrÞ; . . . ;Xn

j¼1

jBðrÞ !

:

In particular, for the 2D case:

~tðrÞ ¼ ð2BðrÞ;1BðrÞ þ 2BðrÞÞ ¼ ð2BðrÞ; rÞ: ð26Þ

DT0X has equivalence with values of DTX:

(c)ers of disks (a) are translated to the same location, outlined with value 3 (b). (c)

Fig. 6. Decomposition of the neighborhoods used for the translated NS-distancetransform in 3D. Top, middle and bottom rows correspond to neighborhoodsN 01; N

02 and N 03. The decomposition steps are represented from left to right. The

number of displacements vectors is reduced from 32 without the decomposition toonly nine.

(a) (b) (c) (d) (e)Fig. 5. Decomposition of the neighborhoods used for the translated NS-distancetransform. (b), and (d) are respectively the type 1 and 2 translated neighborhoods,N 01 and N 02. (a) and (c) are intermediate disks. Only four displacement vectors (e)are needed instead of nine without this decomposition.

416 N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417

DTXðpÞPr () �Dðp; r � 1Þ# X

() �D0ðpþ~tðr � 1Þ; r � 1Þ# X () DT0Xðpþ~tðr � 1ÞÞP r:

Consequently:

DTXðpÞ ¼ r () DTXðpÞP r and DTXðpÞ< r þ 1() DT0Xðpþ~tðrÞÞ 6 r 6 DT0Xðpþ~tðr � 1ÞÞ: ð28Þ

Knowing DT0XðpÞ and DT0Xðpþ~tÞ, we can deduce the values ofDTXðp�~tðr � 1ÞÞ for all values of r between DT0Xðpþ~tÞ and DT0XðpÞfor which ~tðrÞ ¼~tðr � 1Þ þ~t, i.e. ~t ¼ tBðrÞ

!. Algorithm 3 recovers the

values r of the centered DT by selecting all r in the interval½DT0Xðpþ~tjÞ;DT0XðpÞ such that B(r) = j. Iterating through values rwith B(r) = j is achieved using Proposition 1. Values of DT0X becomeavailable before the whole image is computed. For instance, in astandard raster scan, as soon as line y is processed, all lines ofDT0X above y � rmax are fully recovered (where rmax denotes themaximal value of DT0 in that line).

4.4. Translated NS–DT with Intermediate disks

The full set of neighbors used by the previous algorithm is theunion of all translated neighbors (excluding the new origin of theneighborhood). In 2D, this set contains nine vectors, compared tothe eight neighbors needed by the classical algorithms. This countincreases rapidly with the dimension: 32, 107, 350 respectively for3D, 4D and 5D (apparently following, with a constant offset �1, se-quence A126184 in Sloane’s On-Line Encyclopedia of Integer Se-quences [16]). In this section we will show how we candrastically reduce the count of required vectors, by further decom-posing neighborhoods using set unions and translations.

Let B be a sequence of values in [1,n] and cj~v where j 2 [1,n] be n

relative cost sub-sequences with finite length corresponding to theconstruction of n sets of points N j with j 2 [1,n]. For the sake ofsimplicity, we assume that all sub-sequences have the same lengthl. We build the expanded sequence of displacement costs for neigh-bor ~v ; c~v , by concatenation of the sub-sequences c1

~v . . . cn~v selected

by the master sequence B:

8~v ;8r > 0; c~vðrÞ ¼ cB r

lb cþ1ð Þ~v ðhrilÞ:

By Proposition 5, the balls generated by these displacementcosts are such that:

8k > 0;DðO; klÞ ¼ DðO; ðk� 1ÞlÞ � N BðkÞ:

The ith sub-sequence occupies the radii (i � 1)l to il � 1 in theexpanded sequence and conversely, radius r corresponds to sub-se-quence with index i = br/lc + 1 starting at radius r � hril. Accordingto Proposition 6, the distance transform can be computed by prop-agation of the minimal absolute displacement costs bC~v . Minimaldisplacement costs are either equal to costs in the correspondingsub-sequences when these costs are finite, or deduced from thefirst value of a subsequent sub-sequence. The quantity bC~vðrÞ corre-sponds either to the value at index hril in the current ith sub-se-quence: cBðiÞ

~v ðhrilÞ þ r, or to the first value in next sub-sequencecj~v , where ~v is used: cj

~vð0Þ þ l jyBðjBðiÞ þ 1Þ� �

Þ, whichever is minimalaccording to Definition 10.

bC~vðrÞ ¼minfcBðiÞ~v ðhrilÞ þ r; ð29aÞ

cj~vð0Þ þ ljyBðjBðiÞ þ 1ÞÞ; j 2 ½1;ng; ð29bÞ

where i = br/lc + 1.Clearly, if a vector ~v is not used in the decomposition of the

neighborhood j, then cj~v is infinite and the vector can be omitted

from (29b). On the contrary, when a vector is used in all n neigh-borhoods, (29) is simplified to:

8j; cj~vð0Þ –1) bC~vðrÞ

¼min cBðiÞ~v ðhrilÞ þ r; cBðiþ1Þ

~v ð0Þ þ li; j 2 ½1;nn o

: ð30Þ

A further simplification holds when the displacement costs arealways finite for a given vector ~v , then we can omit (29b) in (29):

8j; cj~vðlÞ –1) 8r P 1; bC~vðrÞ ¼ cBðiÞ

~v ðhrilÞ þ r: ð31Þ

If B is periodic, then so is c~v , with a period multiplied by l. Using(29), we can avoid an actual expansion of the master sequence B byconcatenation of sub-sequences. On the contrary, bC~v can be effi-ciently computed on the fly, when needed by Algorithm 1, for peri-odic sequences B with long periods or, a fortiori, for aperiodicsequences. However, for short sequences, it can be desirable to pre-compute c~v once and for all.

4.4.1. 2D caseConsider the following decomposition of the translated 2D

neighborhoods:

D1ðO;1Þ ¼ D1ðO;0Þ [ D1ðð0;1Þ;0Þ;D1ðO;2Þ ¼ D1ðO;1Þ [ D1ðð0;1Þ;1Þ [ D1ðð�1;1Þ;0Þ [ D1ðð1;1Þ;0Þ;D2ðO;1Þ ¼ D2ðO;0Þ [ D2ðð0;1Þ;0Þ [ D2ðð1;0Þ;0Þ [ D2ðð1;1Þ;0Þ;D2ðO;2Þ ¼ D2ðO;1Þ [ D2ðð0;1Þ;1Þ [ D2ðð1;0Þ;1Þ [ D2ðð1;1Þ;1Þ;

where D1(O,2) and D2(O,2) are equal to the translated neighbor-hoods N 01 and N 02. The intermediate disks D1(O,1) and D2(O,1) aredepicted in Fig. 5a and c. This decomposition is summarized bythe construction values S1 and S2, as defined in (19), and shown inTable 2 (where S(0,0) is omitted). The corresponding displacementscosts, deduced from (20) are shown in Table 3. Note that (30) holdsfor vectors (1,1) and (0,1) as well as (31) for (0,1).

Using these two set of sequences, any combination of Minkow-ski sums of N 1 and N 2 can be obtained. Take the octagonal dis-tance with 2-periodic sequence B ¼ ð1;2Þ. The direct applicationof (29) gives c~v values shown in Table 3c. An example of DT00 isshown in Fig. 4c.

N. Normand et al. / Computer Vision and Image Understanding 117 (2013) 409–417 417

4.4.2. 3D caseThe same method can be applied in 3D: from a decomposition

of each of the neighborhoods, and a sequence B, an extended se-quence is built for each of the vectors concerned. Fig. 6 illustratesa possible decomposition of 3D neighborhoods that uses only ninevectors with the corresponding construction values shown inTable 4.

Algorithm 3. Obtention of a regular (centered) DT from a trans-lated DT0.

Data: DT0X: translated distance map of XResult: DTX: centered distance map of Xforeach p in DT0X domain, in raster scan do

if DT0X(p) = 0 thenDTX(p) 0;

elseforeach j do

r maxf1; DT0Xðpþ~tjÞg;//Get the minimal r P DT0Xðp�~tjÞ such that B(r) = j

r jyBðjBðrÞÞ þ 1;while r 6 DT0(p) doDTXðp�~tðr � 1ÞÞ r;//Get the next r such that B(r) = j

r jyBðjBðrÞ þ 1Þ þ 1;end

endend

end

5. Conclusion

In this paper, a path-based pseudo-distance scheme, where dis-placement costs vary both with the displacement vector and withthe travelled distance was presented. This scheme is generic en-ough to describe neighborhood-sequence distances, weighted dis-tances as well as generalized distances produced by Minkowskisums. It was shown that a set of displacement costs can be pro-vided in a minimal form, where each displacement vector is as-signed a non-decreasing sequence of costs, without altering thedistance function. These non-decreasing sequences are directly ap-plied in the distance transform algorithm to keep track of the costsof minimal paths from the background. An application to a trans-lated neighborhood-sequence distance transform in a single scanwas presented along with a method to recover the proper, cen-tered, distance transform. Combined methods provide partial re-sult with a minimal delay, before the input image is fullyprocessed. Their efficiency can benefit all applications, where

neighborhood-sequence distances are used, particularly inpipelined processing architectures, or when the size of objects inthe source image is limited. It was also shown that, by furtherdecomposing the Minkowski sums involved in the neighborhooddistance transform, the count of displacement vectors can be re-duced. In 3D, instead of using a total of 26 displacement vectors,or even 32 as required by the direct application of the translateddistance transform, a full transform can be computed with onlynine vectors.

The pseudo-distance presented here is strongly linked to theproperties of non-decreasing integer sequences studied by Lambekand Moser. First, the Lambek–Moser inverse connects the iterativeconstruction of disks with the displacement costs propagated inthe distance transform. Next, by allowing to iterate through valuesof integer sequences, it permits to compute the displacement costson-the-fly. An implementation in C language is publicly availableat http://www.irccyn.ec-nantes.fr/normand/LUTBasedNSDistanceTransform.

References

[1] A. Rosenfeld, J.L. Pfaltz, Sequential operations in digital picture processing, J.ACM 13 (1966) 471–494.

[2] A. Rosenfeld, J.L. Pfaltz, Distances functions on digital pictures, Pattern Recogn.1 (1968) 33–61.

[3] G. Borgefors, Distance transformations in arbitrary dimensions, Comput. Vis.Graphics Image Process. 27 (1984) 321–345.

[4] U. Montanari, A method for obtaining skeletons using a quasi-Euclideandistance, J. ACM 15 (1968) 600–624.

[5] R. Strand, Weighted distances based on neighbourhood sequences, PatternRecogn. Lett. 28 (2007) 2029–2036.

[6] J. Lambek, L. Moser, Inverse and complementary sequences of naturalnumbers, Am. Math. Monthly 61 (1954) 454–458.

[7] A. Ostrowski, J. Hyslop, A.C. Aitken, Solutions to problem 3173, Am. Math.Monthly 34 (1927) 159–160.

[8] S. Beatty, Problem 3173, Am. Math. Monthly 33 (1926) 159.[9] A. Hajdu, L. Hajdu, Approximating the Euclidean distance using non-periodic

neighbourhood sequences, Discrete Math. 283 (2004) 101–111.[10] É. Thiel, A. Montanvert, Chamfer masks: discrete distance functions,

geometrical properties and optimization, in: International Conference onPattern Recognition, vol. III, pp. 244–247.

[11] P.-E. Danielsson, Euclidean distance mapping, Comput. Graphics ImageProcess. 14 (1980) 227–248.

[12] R. Strand, B. Nagy, C. Fouard, G. Borgefors, Generating distance maps withneighbourhood sequences, in: A. Kuba, L.G. Nyúl, K. Palágyi (Eds.), DiscreteGeometry for Computer Imagery 2006, Lecture Notes in Computer Science, vol.4245, Springer, Berlin/ Heidelberg, Szeged, Hungary, 2006, pp. 295–307.

[13] N. Normand, Convex structuring element decomposition for single scan binarymathematical morphology, in: I. Nyström, G. Sanniti di Baja, S. Svensson(Eds.), Discrete Geometry for Computer Imagery 2003, Lecture Notes inComputer Science, vol. 2886, Springer, Berlin/ Heidelberg, Naples, Italy, 2003,pp. 154–163.

[14] X. Wang, G. Bertrand, An algorithm for a generalized distance transformationbased on Minkowski operations, in: International Conference on PatternRecognition, vol. 2, pp. 1164–1168.

[15] X. Wang, G. Bertrand, Some sequential algorithms for a generalized distancetransformation based on Minkowski operations, IEEE Trans. Pattern Anal.Mach. Intell. 14 (1992) 1114–1121.

[16] E. Deutsch, Number of hex trees with n edges and having no nonroot nodes ofoutdegree 2, in: N.J.A. Sloane, S. Plouffe (Eds.), The On-Line Encyclopedia ofInteger Sequences.