Pattern Recognition
Pergamon Press 1968. Vol, 1, pp. 33 61. Printed in Great Britain
Distance Functions Digital Pictures
on
A. ROSENFELD and J. L. PFALTZ University of Maryland
(Received 25 October 1967) Abstract This paper describes algorithms for computing various functions on a digital picture which depend on the distance to a given subset of the picture. The algorithms involve local operations which are performed repeatedly, "in parallel", on every picture element and its immediate neighbors. Applications to the detection of "clusters" and "regularities" in a picture, and to the dissection of a region into "'pieces", are also described.
1. D I S T A N C E F U N C T I O N S LET A be the set of all pairs of integers (i,j). The f u n c t i o n f f r o m A x A into the nonnegative integers is called (a) Positive definite, if f (x, y) = 0 if and only if x = y. (b) Symmetric, if f (x, y) = f(y, x) for all x, y in A. (c) Triangular, iff(x, z) < f(x, y)+f(y, z) for all x, y, z in A. If f satisfies (a--c), it is called a distance function. Proposition 1. If l a n d g satisfy (a), so do f + g and m a x ( f g); similarly for (b) and (c).
Proof: Letf(x,y)+g(x,y) = 0; then s i n c e f > 0 and g > 0, we must havef(x,y) = so that x = y . Clearly f ( y , x ) + g ( y , x ) = f ( x , y ) + g ( x , y ) , while f(x,z)+ g(x, z) < f(x, y) + f(y, z) + g(x, y) + g(y, z) = f(x, y) + g(x, y) + f(y, z) + g(y, z). The proofs for g(x,y)=0,
max(f, g) are analogous. COROLLARY. If fl . . . . . f, satisfy (a), (b) or (c), so d o f t + ... +fn and max(fl . . . . . f,). Proposition 2. f[(i, j), (h, k)] = li - hL and g[(i, j), (h, k)] = I J - kl are distance functions.
Proof: (a)-(b) are clear; as for (c), note that f[(m, n), (p, q)] = f[(m+r, n), (p+r, q)] for any m, so that it suffices to prove f[(i, jk(h,k)]
Proposition 3. The set of (i,j) at distance < r from (0, 0) is: (a) For dl: A diamond (i.e. a square with sides inclined at +45 °) with vertices at (0, _ r) and ( + r, 0) (b) For d2 : A square (with sides horizontal and vertical) with vertices at (r, + r ) and ( - r , _+r).
Proof." (a) This is the set of (i,j) such that li[ +lJl -< rz thus ]Jl -< r, and for any such j we h a v e l j ] - r < i < r - l j l . 33
34
A . ROSENFELD a n d J. L. PFALTZ
'5.3.1.9.7.5.3.1.9.7.5.3.1.9.7.5.7.9. I. 3.5.7.9.1.3.5.7.9.1.3.5.7 5.3.1.9.7.5.3.1.9.__7.5.3.1,k~.7._5__.5.7.9.1.3.5.7.9.1" 3.5, 7,9,1.3.5. .3.1.9.7.5.3.1.9.7.,r.3.1.~.7.5.3.5.7.9.1.3.5.7.9.1.3,5.7.9.1.3.5 3.1.9.7.5.3.1.9.7.~, .3.1.9.7. S, 3 . 3 . 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . ~ . 7 . ~ 9 - 1 . 3 . ~ .1.9.7,5.3.1.9.7.5.3.1.9.7.S.3.1.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3 1.9.7. S.3.1.9.7.5.3.1.5.7.,~.3, |. 1.3.§.7.9.1.3.5.7.9.1.3.5.7.9.1. .9.7.5.3.1.9.7.5.3.1.9.7.5.3.1.9.1.3.5.7.9.1.3.5.7.9.1.3,§.7.9.1 9.7.~. 3.1.9.7.5.3. ] .9.7..5.3.1.9.9.1.3.5.7.9. |.3.~.7,9.1.3.5.7.9. .7.5.3.1.9.7.5.3.1.9.7.5.3.1.9.7.9.1.3.5.7.9.1.3.5.7.9.1.3.5.7.9 7.5.,~. 1.9.7.5.3.1.5.7.,~.3.|.9.7.7,9.1.~,~5,7,9.1.3.5.7.9.1.3.~. 7. • 5.3.1,9.7,5.3.1.9.7.5.3.1.9.7.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3,5.7 5.3.1.9.7.5.3.1.9,~ .5.~. ~.S.7.~¢.~,7.9.1.3.5.7.9.1.3.5. ;.9.1.3.5. .3.1.9.7.5,3.1.9.7.~.3.1.S.7.5.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1,3.5 3.1.9.7.5.3.1.9.7.,s .3. |.9.7.5~.3.5.7.9.X.3.5.7.9.1.3.5.7.9.1.3, • 1.9.7.5.3.1.9.7.5.3.1.9.7.5.3.1.3.5.7.9.1.3.5.7.q.1.3.5.7.9.1.3 1.9.7.5.3.1.9.7.~.,~.|.S.7.5.3.1 1.3.~,7.9.1.~.5.7.$.1.3.5.7.9.1. • 1.9.7.5.3.1.9.7.5.3.1.9.7.5.3.1.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3 3.1.9.7.5.3.1.9.7.,~.3, | .9.7.5.,~.,,~.5.7.9.1.3.5.7.9.1.3.§.7.9.1.3. .3.1.9.7.§.3.1.9.7.~ .3.1.~.7.5.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3.5 5.3.1.9.7.5.3. ~.~}.~.~. |.$.]~.5,7.9. [ , 9- 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . 5 . • 5.3.1.9.7.5.3.1.9.7.5.3.1.9.7.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3.5.7 7.5.3. 1.9.7.5.3.~.~LT.~.3~ILg~7.7.9.1.3.5.7.9.1.3.5.7.9.1.3.5.7. .7,5,3.1.9.7.5.3.1.5.7.5..~.
1.9.7.9.1.3.5.7.9.1.3.5.7.9.1.3.
S. 7.9
9.7.5.3.1.9.7.5.3. ] ,9.7.5.3.1.9.9,1.3.5.7, 9 . 1 . ~ . 5 . 7 . 9 . | . ~, 5 , 7 . 9 . .9.7.5.3.1.9.7.5.3.1.9.7..~.3.1.9.1.3.5.7.9,1.3.5.7.9.1.3.5.7.9.1 1.9.7.5.3.1.9.7.5..~. 1.5.7.~,3.1. |.3,5.7.9.1.3.5.7.9.1.3.5,7.9, 1. .1,9.7,5.3.1.9.7,5,.~, 1.9.7,5.3.1.3.5.7.9.1.3.5,.7.9.1.3.5.7.9.1.3 3.1,9.7.5.3.1.9.7, ~ .3. |.9.7.5.3.3,5.7.9. ~. 3 , 5 , 7 ~ , 9 ¢ 1 . 3 . ~ . 7 - 9 . 1 ~ ) ~ .3.1.9.7.5,3.1,9.7,5.3.1,S.7.5.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1.3.5 5.3.1.9.7.5,3.1.9,~.5,3,1.5,7.5.5.7.9o 1.3.5.7.9. I . 3. S. 7 . 9 . 1 . 3 . 5 . .5.3.1.9.7.5.3.1.9.7.5.3, ].9.7.5.7.9.1.3.5.7.9.~,3,5,7.9.1.3.5.7 FIG. 1, City block distances (d~) f r o m a single point.
~ . q . 1 . 5 . 3 . X- q - T - 5 5 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 To?- 1.3-. 5.7.9.L 1.9.7.5.3.1.9.7.5.........................., °.5.7.9.1.3.5°7-9.1 T- 9.7.5.3. !. 9."/~5.~33333333,333333333333333333.5.7.9. l. 3.5.7.9.1 1.9.7.5.3. l.q. 7.5.3.... °.,, ........ .........°3.5.7.9.1°3.5.7.9.1
1.9./.5,3o 1.9./.5.3. lllllI 1.9.7.5.3.1.9°7.5.3.1.°.
IIIIII
lllllllllll.
°. - °.. --.-.
....
3 . 5 - 7 - 9 - 1 ° 3 - 5 - / , 9 -I
...1.3.5.7.9.1.3.5.7.9.1
1-. 9 ~ 5 ~ . - ~ . 9.7.5.3.1. 9999999999999999999.1° 3.5.7.9.1.3.5.7o9.1 1.9.7.5.3.1.9.7.5.3.1.9............. °...9.1°3.5.7°9.1.3.5.7.9-1 l~q~7[~.~J .~Tq. 7~. ~1~. q. 777777777777777.9. I . 3.5.7.9.103.5°7.9.1|:9.7.5.3.1°9.7.5°3.1°9.7
.............
7.9°1.3.5.7.9.1.3.5.7.9°1
~ . 9 . T. 5 . 3 . 1 . ? . 1.5-, 3, 1 , 9 . 7 , 5 5 5 5 5 5 5 5 5 5 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . 5 . 7 - 9|. !1.9.7.5.3° 1.9. T.5.3.1.9.7.5 ......... 5.7.9.1.3.5.7.9.1.3.5.7.9.1 r~Q-.~.ST3~~.T. 9.7.5.3333333.5.7.9.1.3.5.7.9. | • 3 . 5 . T. 9--~ 1.9.7.5.3.1.9.7.5.3.1.9.7.5.3..°..3.5.7.9.1.3.5.7.9.1.3.5.7.9.1 ~ . Q ~ r . ~ - . ~ 3 . T . ~ ] v ~ . 5 ~ I j ~ Q ~ . 7 . 5 . 3 . l [ 1.3,, 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . 5 . T. 9 . ~ [.Q. 7o5.3.1.9.7.5.3.1.9.7.5.3.1 1.3.5.7.9.1.3.5.7.9.1.3.5.7.9.1 X. 9 . 1 . 5 . 3 . [.9, 7.5.3.1.9.T. 5.3. |l 1.3.5.7.9. I. 3.5.7.9. I. 3.5.7°9. ! i.9.7.5.3.1.9, 7.5.3.1.9.7.5.3 ..... 3o5.7.9.1.3.5.7.9.1.3.5.7.9.1 1 og~7~.-~.I.7~.~T~'~. 1.9 o7.5. 3333333.5.7.~-~. 1 . 3° 5 o7.9.1.3 o 5.7.9,1 1.9.7.5,3.1.9.7.5.3.1.9.7.5..... °...5.7.9. h3.5.7°9.1.3°5.7.9.1
1 . 9 .~T. 5 ~ ~F.~I~.9 - . ~ / ~ . ~ 3 T . 9 . ~ ; ~ 5 5 5 5 5 5 5 5 5 5 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3. S. 7 . 9 . l 1.9.7.5.3.1°9.7.5.3.1.9.7 ............. 7°9.1.3.5.7.9. I. 3.5.7.9. l X. ?. T ° 5 . 3 . I . 9 . 7 . 5 . 3 . 1 . 9 . 777777777777777.9.1.3.5.7.9.1.3.5.7.9.1 1,9.7.5.3° 1.9.7.5.3.1.9........° °.......9.1.3.5.7.9.1°3°5.7.9.1 F.-Q. 7 ° 5 . 3 . 1 . 9 . 7 . 5 . 3 . 1 ~9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 1 . 3.5.7.9.1.3.5.7.9.1 1.9.7.5.3.1.9.7.5.3.1.,......... .......... l. 3.5.1.9.1.3.5.7.9.1 1 otI~,7.5T3~,IT9~7,~5-. ~T[I).yl 1 1 1 1 1 1 1 1 1 111 l l 1 1 1 . 3 . 5 . 7 . 9 . l. 3.5.7.9.I 1.9.7.5.3.1.9.7.5.3 ......................... 3.5.7.9.1.3.5.7.9.1 1.9.1.5.3.1.9.7.5.33333333333333333333333.3333,.5.7.9.1.3.5.'l'.9.1 1.9.7.5.3.1.9.7.5....... ................ . ..... 5.1.9.1.3.5.7.9.1
1~ . 7 ~ ' J ~ .
g ~ / ~ ' 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 . 7 . 9 . h 3° 5 . 7 . 9 o I FIG. 2. " S q u a r e " distances (d2) f r o m a single point.
Distance functions on digital pictures
(b) This is the set of have-r
(i,j)
35
such that max(lil, IJl) ~ r, so that IJl ~ r, and for any s u c h j we
Figures 1-2 show the distances dl and d2 from a single centrally located point. For clarity, only the odd distances are printed out modulo 10, while the points at even distances are represented by dots ; the original point is blank. Proposition 4.
d3[(i,j),(h,k)]= m a x ( l i - h l , ~ l i - h l + ( i - h ) ) - ( [ ~ ] - [ ~ ] ) + k - j ,
is a distance function, where [x] means the greatest integer not exceeding x.
Proof." If d 3 = 0, since li-hl > 0 we must have li-hl = 0, so that i = h; hence max(k-j,j-k) < O, i.e. Ij-kl -- 0, so that j = k. Symmetry is clear, since interchanging (i,j) and (h, k) just interchanges the second and third arguments of the max. As for triangularity, note that for all (i,j), (h, k), (m, n) we have i-h
i-m
m-h
m
h
while
li-hl 2
_
_
~
li-ml +Ira-hi 2 2
by Proposition 2. Adding, we have the triangularity of the second argument of the max, and similarly for the third argument, while the first argument is triangular by Proposition 2 ; now use the Corollary to Proposition 1. The set of (i,j) such that d3[(i,j), (0, 0)] _< r is approximately a (0, 0). [To see this, use the fact that d3[(i,j), (h, k)] =
hexagon
li-hl+max(O,k-j-[l~2hl],j-k-[li-h-]2+l]),
if i is odd ;
[i-hl+max(O,k-j-[li-hl+l-],j-k-[~]),
if i is even.]
centered at
Figure 3 shows the distances d 3 from a single point, analogously to Figs. 1-2. Figure 4 similarly shows the distances d 3 from a single point to the points of a "staggered" array in which, on alternating rows, only odd numbered or only even numbered elements are used. Note that this array can be regarded as hexagonal, since each element has exactly six "neighbors," two on its own row and two each on the rows above and below it. Proposition 5.
g[(i,j), (h, k)]
= [2(1i- hi +l J - kl + 1)/3] is a distance function.
Proof." I f g = 0 we have 2(li-hl+lj-kl+l)/3 < ~, so that li-hL+lj-kl < O, proving positive definiteness, while symmetry is clear. For triangularity, as in Proposition 2 it
36
A. ROSENFELD and J. L. PFALTZ
• 7.5.3.1:?.7.5.3. ! :~.7.555~555555555555.7,9o • 7,5,3,1,9,7,§,3,1,S,7,5,,,,,,,,,,, .... 7,5,3, 7,5°3,
l~,9,T, 5,3°1 ,~,7,..o 1,9,7,5,3,1,~,7,~,3
1 o3.5.7.gol.3o5.7, 1,3,5,7, ?, 1,3,
5,7,9,
q 5o7,
33333333333333,5,7,Q. i,3,5,7oqol, 3° 5,7, ............. 3,5,7,9,1°3, §,7,9,1°3°5,7
• 5,3,1,9,7,5,3,1,9,7o~o3, 1 |1111111111,3°5,7°9,1,3° §°7,9, 1°3o5°7 • 5,3,1,9.7,5,3,1,9,7,5,3, | ........... 1,3,§,7,9,1,3,5o7,9,1°3,5, _5,3~_b_9,7, §, 3,1,9 o7,5,3 ° 1,$999~99999,1,3, §,7,9°1,3,5°7, 9° 1° 3° 5° §°3,1°9,7 ° 5,3 • 1,9,7, §° 3, l,~ ......... 9,1,3, 5.7.9. I. 3,5,7,9, 1,3,5 • 3,1,9,7,_5•3, 1:9,7,~ •3 o1,~ ,77777777°9,1,3,5o7,9° 1,3o5•?°9., 1,3, 5 • 3, 1,9,7, 5•3,1,9,7,5,3 •1,9,7 ....... 7,9° 1,3,5• 7°9o 1 °3°5°7,9°1,3, 3,1,~° 7°5,3,1,9•7,5,3,1,9,7,55~555,7°9, L°~,~,7°9~.1°3,5,7°9, 1°3° 3,1°9,7°5,3,1 •9,7,~ •3• 1•9,7°5,,, ,°5,7,9° 1,3,5,7,9.1°3,5°7,9,1,3 • 1,9•7,5,3,1.9•7•5,3°1,9•~,5°333~,5,7,9°1,3,5•7°9, |,3,~,7,9, 1, 3 • X,9,7,5•3,1 °9°7,5 ,~ • 1,9o7°5,3°, °3,5°7°q°1°3,5°7°9°1,3o5°7,9,1° 1°9°7° 5,3, 1•9•7.5•.~, 1,q,7•'.°3o 11o3°5,7,Q° 1,~,5,7o9,1o3,5°7°9°1, 1.9.7.5.3.1.9.7•5.3.1•9°7.5.3.1 1•3.5°7°9.1.3.5.7•g.1.3.5.7.9, 1 1__._.9.7.5.3 • 1.9.7.5.3.1 .$.7.~. 3.11.3. ~, 7.9.1.3.5.7.9.1,3.5.7.9, ;. • 1.9.7.5• 3.1.9.7,5.3.1,9.7,5.3...3.5.7.9.1.3.5.7.q.1.3.5,7.9.1. - 1.9.7.5• 3• 1.9• 7.5.3.1.9.7.5.3333.5.7.9.1.3.5.7.9.1.3.5.7.q.1.3 3• 1.9,7.5.3• 1 •9.7.,~ .3• 1.9•7.5. .... 5.7.9.1.3.5.7.9. |.3.5.7.9.1.3 3• 1.9• 7,5•3.1.9.7•~,3.1;9.7.555555.7.9.1.3.5.7.9.1.3.5,7.9.1.3. • 3, 1.9.7.5•3.1.9.7•5.3.1.&.7 ....... 7.9.1.3.5.7.9.1.3.5.7.9. |.3. • 3.1 •9.7.5,3, 1.9.7 •5.3,1.c;.77777777.9.1.3.5.7.9.1.~1.50.7.9. |,3.5 5.3.1,9.7.5.3.1.9 •7.5,3 • |.9 ......... 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . 5 . 7 . 9 . 1 . 3 . 5 5.3.1~_9.7.5.3.1.9.7 • 5.3.1 .c;999999999.1.3,5.7.9, ;.3.5.7.9.1.3.5. • 5.3.1.9.7•5•3•1.q.7•5•3. ! ........... 1.3, 5.7.9.1.3.5.7.9. h 3.5. • 5.3,1•9•7.5• 3.1.cJ•7 •5.3. ] 11111111111.3.5.7,9,1°3o5.7.9o 1.3. §. 7 7.5.3.1•9•7.5.3-1-c.7.-~•3 ............. 3.5.7.9.1.3°5.7.9.1.3,§.7 7.5 • 3.1.9.7.5 •3.1.c;.7.',. 33.~333~3~33333.5.7.9.1.~1.~5~7,9, • 7.5.3.1•9.7.5.3.1•9.7•5 . . . . . °. . , •. . . . 5.7.9.1.3.5,7.9.1.3,3.7. -7.5.3.1.9•7.5.3•1•9.7.55~555555555555.7.9.1.3.5.7.9.1.3.5.7.9
F I G . 3. " H e x a g o n a l " • _. ~ • .•_ _ e _ s. . I • c; c; c; 7 • ." • 3 • 1 • q . . . 7 • ~ , 3 • ! • 9, 7 7 1 • 5 • 3 • I • 9 • 7 . . • 3 • 1 ~ . 7 . ." . ~ • .: • I • q , 7 • ~ . •
:
.
3
•
•
3
. •
I 1
.~ •
• •
1 •
distances
9 . 7 . ~ .
9 9 $ 9 . . . . . 7 7 77 . . . . . ~ 5 .~ 5 . . . . .
S • 7 . 5 . 3 . . . c; • 7 , 5 . 3 . 1 1
9
•
7
•
5
,
~ ,
I
I
. •
(; 9
c
•
~ &
;
S •
,
• •
•
•
~
7
•
9
•
]
•
• 3
| •
•
*
t •
•
7
~
,
3
•
,
~
•
I I
|
3
•
1
, .
,
•
~
,
% ~
9
,
?
.
~
. . . . . . . 7 / 7 7 7 T . . . . . .
7 ~ _ ~ ~ 5 5 o § . . . . .
7
•
,
-~ •
" •
,
I
~ ,
~
~ •
•
I
3
I ~ $ . I .
~ •
,
•
9
7 •
=
•
• 7
. 9
• I
-~ •
9 •
]
. 4
•
? .
9
. 3
~
7
3
~_-
,
•
.
•
5
,
3 .
I
,I ~ .
5
~
•
3
3
•
3
•
5 •
• 5
3 •
• 3
3
I .
. •
9
•
.
•
•
5 '
I
.
L/_.
3
.
9
1
.
•
g
" 7 " ' 0 t ~_..~
7
.
•
7
7 ]" 1 " 9 . . . _~ . l , (; 9
J~-J~L~L-/L~9
FIG.
"
5
5
. . . . 7 7 7 7 . . . . . (~ c] 9 ¢]
4. H e x a g o n a l
. 3
5
@_9
5 .
, . 3 .e 5 , 7 , , 3 ° 5, 7, , I . 3 . 5 . 7 9 • I . 3 . 5 . "/ 9 , I , 3 , 5 , . 9 , 1, 3 , 5 • ;
.
1
7
5
,
.5 5
7
.
•
. 7
9 L9
,
| s
.
3
1
.
.
.
5
.
5
5
5
5 ~
• .
,
3
, l
.
~ I ,
7
,
3 •
I
5
, 3
,
§ , .
.
5
1.j__tJ I
I
. .
,
5
,
9
._L .
,
7 ,
~
3 3
, 5
.•
!
1j
9 •
7
5
3
I
~ ,
.
,
,
9
,
.
7 7
. .
9
•
I
.
3
.
5
.
7
.
9
.
3
•
5
.
7
.
9
. . I
$ •
.
.
•
. 5
I I
. .
, •
3 3
3 3
. •
• o
5 5
) 5
, .
7
• ,
7 7
7
• .
, .
9 9
9 9
, •
•
.
i
I
I . j_
i I
,
. •
.
.~ 3
~
.
~ 3 .
• t • ~_, 7 , 9 • I • 3 • 3 • 5 • 7 , 9 . I . 3 . : _~ . 5 . 7 , 9 , I . 3 . ~ 5 • 7 • 9 . I . 3 . 5 .
5
5
i 3
,
I I
.
9
|
,
~
_tl~_~_ .
•
.
9 .
9
9
,
° 7
•
,
°
9
7 .
l
9
9
. . . . . . . . . 7 7 7 7 7 7 "~ 7 . • . . . • • (~ Q ~ Q q Q Q Q
distances
9 9
I ,
9
5
5
. 9
,
-
•
.
9 .
°
9 .
7
, 3
7
9
3 .
.
. 7
,
3
•
l .
I--,LII . 3 I
7 °
5
. _9
o
• 5
,
Q .
.
5 ,
3
."
3
7
9
•
7
. 3
,
,
° 7
7 7
•
. 7
.
•
7
$
• 9
•
3 ,
1
9
7
.
5 5
9
,
. I
•
•
5
•
•
9
•
) •
.
1 .
~,
.
3
.
9
7
. . . . . . . . .
, J_$ 9 % I . . . . . .
"- 5
.
, 3
3
1 , ~ ° ~ ~ 3 ~ . 7 . 5 . . . . .
.
7 •
~.
~ .
~: • l • i , _ 7 _ ~ . ~ _ ~. . I I A I I 1 1 i l 3 • I • S • 7 • 5 , 3 . . . . . . . . . . 5 • ~ • 1 • $ • 7 . 5 , ,~ ~ 3 3 3 3 3 3 3 • -~ • .: • 1 • 9 . 7 . 5 . . . . . . . . . . .
~
.
9
•
•
t
, I
L •
, I
9 ,
7 5
~
•
7
3 1
array). .]
.
7
5
•
~
$ _ .9 9. 9 . 9 9 . . . . . 9 7 7 777 7 , 9 . . . . 7 • ~ ~ 5 ~ ~, . . . 5 • 7
~,7~
. . . . . . . . . . . 1 • 3 • 5 • 7 , 9 , I , 9 ~9~ 9 9 9 9 ~ 1 , 21 , ~ . 7 • 9 , 1 ~
• ~ • l_ , 9 , 7 • ~ , ~ , ], -~ • I • ; • 7 • 5 • 3 • I
5 :
, .
(Cartesian
9.
.
. . . . 1 1 1 1
'; • 7 • 5 • 3 • i • S • 7 . . . . . . . _, ~ • 7 • r- • 3 • | , 9 , 7 7 ~ ~ T 7
I
•
-~
5 =~
. ~
". ~
,
• 5
] I
, o
.
• •
•
7 7
~
? 7
q
. o
$ 9 9. 9 . 9 . . . . . 1 7 7 I 7 . . . . . .~5 5 ~ . . . . .
. . . . . . 1 1 1 1 1
-~ • 1 . S • 7 _ . ~ . ~ ~ 1 • 9 ~; -~ • I • 9 • 7 • ~ • 3 . I . 9 . . • I • ~; • 7 , ~ , ~ , 1 , (; • 7 • l • ~; • 7 • 5 • 3 • I • c; • 7 . I
(d~) f r o m a s i n g l e p o i n t
|.3,
1
5
5
,l
~ 9
~
i
~
.
§
~
. . 7 • g . I • 3 . 5 , ] 7 7 7 7 7 ,,~_. ].. 1-S "--1 . . . . • 9 . 1 . 3 . 5 . 7 " Q t) (J Q Q 9 . 1 . ~1 . ~ . 7 .
from a single point
(staggered
array).
Distance functions on digital pictures
37
suffices to prove that 3
-
3
+
3
~"
Now li-hl + l j - k l < Iil +lhl +lJl +lkl. If this inequality is strict, we have li-hl + l j - k l
2+2(Ihl+lkl+l)
2
3
3
3
as required• Thus it remains only to consider the case where li-hl+[j-kl = l i l + l h ] + [Jl +[k[, so that
2(li-hl+lj-kl+l) 3
2(lil+lJl+lhl+lkl+l) 3 2(lil+lj[+l) 3
If the fractional part of the left m e m b e r is 7, 2 or if the first two terms in the right m e m b e r is not more than ~, same is true if the fractional part of the left m e m b e r is in the right m e m b e r are not both ~. Hence we need fractional part of the left member is 0 or ½, and those m e m b e r are ½ and ] or are both ~, i.e.
2(Ihl+lkt+l) 3
2 3
sum of the fractional parts of the the desired inequality follows. The 7, and those of the first two terms only consider cases in which the of the first two terms in the right
(1) 2([il+lJl+lhl+[k[+l)=O or l ( m o d 3 ) ; 2(1i1 +[Jl + 1) = 2([h[ +lkl + 1) = 2 (mod 3) (2) 2(lil+lJ[+lhl+lkl+l) = 0 ( m o d 3); 2(1il +l J[ + 1) = 1 (mod 3) and 2(}hi+lkl + 1) =-- 2 (mod 3) (or vice versa). In case (1) we have [il +ljl + 1 = Ih[ +lkl + 1 = 1 (mod 3), i.e. Iil +lJl --- Ihl +lkl = 0 (mod 3), so that 2(1il +lJl +lhl +lkl + 1) -- 2 (mod 3), contradiction. Similarly, in case (2) we have ]il+[j[ = l ( m o d 3 ) and Ih[+lkl = 0 ( m o d 3 ) , so that 2(lil+[jl+lhl+[k[+l)= 1 (mod3), contradiction. COROLLARY. d4 = max(g, d2) is a distance function. Readily, the set of (i,j) such that g[(i,j), (0, 0)] < r is a diamond with vertices at
(0+i l) and (+I 10)
38
A. ROSENFELDand J. L. PFALTZ
Indeed, this is the set of (i, j) such that [2@ +~_jl+ 1)] < r, so that IJl-< ~ --for, if IJl
we would have
I2(li'+~J'+1)l-> I(2[~1+4)/31 > I(2(~-~) +4)/31=r+l" Moreover, for any such j we have 2@ +lJl + 1) 2 < r+_~, 3 i.e. Ill < 3r/2-ljl. It follows that the set of (i,j) such that d4[(i,j), (0, 0)] _< r is an octagon with vertices at (r,+[2]),
(-r,_+[2]),
([~],+r),
and ( - I 2 ] , + r ) .
1.o9..7oo5oo3oo1.o~oo7..5~555~55555~55oo7ooS..L..]°o5oo7oo9.ol 1og..7..5o.3..1oo~..7..5o.o ..... o..... oS.oToo~oob, o3,eSooToogoI 1.~.7..5..~..]..S..7..~..~3~3~33333o.5..7..9..|.o3o.5..7.9.[ I.~.7.5.3..I..g..7.o5..3. o11111111111oo3oo~oo7.~ooloo3.5o7.~oI I.~.7.5.3.1..S..7..5..~..1..., ....... I..3..5..7..9..I.3.5.7.Q.1
1.S.7.5.3.1.9..7..~oo~.o1..9~9~9~9S9.oloo3.o5.o7ooSolo3o5o7o9ol 1.~.7.~.3.1.9.7.~..~._1~.~ ......... 9..1..~o.5o.7.So1.~.5.7.9.1 1o~o7o5.3olo9.7.5o.~o.1.o~o.7777777oo9..1oo3.o5o7oSolo3o5o7oSol 1o~.7.5~3e!~7o~.~..1..9..7 .... ,,,7,,Q.olo.3oS.7.~.I.3oS.7o_9_LL 1.~.].5.3.1.~.7.~.~.1..9..7oo5~.o7.oS..1.~o~o7oSolo3o5o7o9ol IoS.7.~.3.1.Q.7.~.~.I.S..~..~ ..... 5..7..9.1.~.p.7.$.|.3.5.7.~.1 loS.7.5.3.1.9.7.5.~.l.~.7..5..~3..5..7.Q.l.~.5.7.S.l.~.5.7.S.1 1.~.7.5.3.1.9.7.~.~.I.~.7.5..3...~..5.7.9.1.3.5.7.~oI.3o5.7o9.1
1.~.7.5.3.1.9.7.~..
~.1.~.7..~..s..1..~.5.7.9.1o~.~.7oS.1.3.5.7o9ol
I.S.7.5.3.1.9.7.~.~.I.S.7.~.~.I 1 o ~ . 5 . 7 . 9 . 1 . ~ o 5 o 7 . S o l o ~ o 5 . 7 . 9 ,
L
Io~.7.5.3.1.9.7.5.~.I.~o7.~.3o.I..~o5.7.9.1o3o5o7oSolo3.5.7o$ol I~.7.fi,3~1.9.7.5.~.1.~.7.~.o)...~..5.7.9.1.3.~.7.~.1.3.5.7.9.1 1,~.7.5.3.1.9.7o5.~.1.S.7..5..~3o.5..7.~olo3.5o7.9oI.3o5o7.9ol
I.S.~.5.3.1.9.7.~.~.|.~.~].oS.oo..5.,7..9.1.3.So7.SoI.~.5.7._9~X 1.S.7.5.3.1.9.7.~.~.1..9..7oo5~$55o,7..S..1.3o5.7o$ol.3.5o7oSol I,So7,5o3. l.9~7o~,~..Io~_~7.
......
7ooSo.I.o3o5o7oS.Lo3o5.7o9.1
1.~.7.5.3.1.Q.7.~..3..1.o~..7777777..9.,1..3..~.7.S.1o3o5o7o9,1 1~o7~.3.1.9.7.o ~.. . . . . l o . S . . . . . 9 o o | . o ~ o o ~ , . 7 . $ , 1 o ~ , 5 o 7 . 9 , 1 1 o S . 7 . 5 . 3 . 1 . 9 . . 7 , . ~ . . 3 . . 1 . . 9 ~ S ~ 9 9 9 9 9 . . I o . 3 . . 5 . o 7 . . S . 1.3o5o7.So 1 I.~.7.5.3..I..S.,7..5..3..IIIIIIIIIII..3..5o.7o.9o.I.o3.5.T.9oI
.
1.~.7.5..3..1..~.~.~.3..~....,......3..5..7.,9..1..)..5.7.9.1 1-~.7-.5.-3..1..~..7..~..~3~3~3..5..7.0~0,1,,3,.5o,7,5,1 I.~..7..5..3..I..5..70.5.... . . . . . . . 5..7..~..1.~.~5o.7,,9ol .
.
.
.
.
m e g
•
FIG. 5. "'Octagonal" distances (d4) from a single point.
Distance functions on digital pictures
39
[This is not a regular octagon ; the sides have the right orientations, but the wrong lengths. N o t e that for r = 1 the octagon degenerates into a diamond.] T o see this, note first that from d2 we have IJl < r, and for any s u c h L also Iil -< r. IflJl < It/2] and ril < r, we have
I2('il+]-3Jl+l)]<_12(r+Er/2]+
1
= Ir+
=r.
so that d4 _< r is also satisfied. On the other hand, if [r/2] < IJ] and 2(lil +lJl + 1 )q < 3 3
r,
we have
3r
3r
lil < ~ - - I J l < ~ -
< r,
so that dE < r is also satisfied. Figure 5 shows the distances d4 from a single point.
2. A L G O R I T H M S
FOR THE DISTANCE FUNCTIONS
In this section we describe algorithms for computing distance functions dl-d4 by performing repeated local operations. T o this end, we first show that these functions have certain special properties. Proposition 6. Distance functions dl-d3 all have the following property : For any distinct x, y in A x A, there exists z e A x A such that d(x, z) = 1 and d(z, y) = d(x, y ) - 1.
Proof: The set of(u, v) e A x A such that d,[(i,j), (u, v)] = 1 is readily (a) For dl : { ( i - 1,j), (i+ l,j), ( i , j - 1), (i,j+ 1)} (b) For d2: { ( i - 1 , j - 1), ( i - l,j), ( i - 1 , j + 1), ( i , j - 1), (i,j+ 1), (i+ 1 , j - 1), (i+ 1,j), ( i + l , j + 1)} (c) For d3 : { ( i - 1 , j - 1), ( i - 1,j), ( i , j - 1), (i,j+ 1), (i+ 1 , j - 1), (i+ 1,j)}, if i is o d d ; { ( i - 1,j), ( i - l , j + 1), ( i , j - 1), (i,j+ 1), (i+ 1,j), (i+ 1 , j + 1)}, if i is even. Let d,[(i,j), (h, k)] = d, r = 1, 2, 3, where d > 0. In case (a), ifh < i, then d l [ ( i - 1,j), (h, k)] = d - 1 ; if h > i, then dl[(i+ 1,j), (h, k)] = d - 1 ; if k < j, then d l [ ( i , j - 1), (h, k)] = d - 1 ; and if k > j, then d~[(i,j+ 1),(h, k)] = d - 1--where at least one of these must be true since (i,j) ¢ (11,k). In case (b), similarly, if i,j, h, k are related as indicated, then dz[(U, v), (h, k)] = d - 1 for the indicated (u, v): Relations
i < i < i< i=
h,j h,j h,j h,j
< = > <
(u, v)
k k k k
(i-l,j-1) (i-l,j) (i-l,j+l) (i,j-1)
Relations i > h,j > k i > h,j = k
i > h,j < k i = h,j > k
(u, v)
(i+ l,j+l) (i+ l,j) (i+l,j--1) (i,j÷l)
40
A. ROSENFELDand J. L. PFALTZ In case (c), analogously, we have Relations
i i i i i i
< < = = > >
h,j h,j h,j h,j h,j h,j
< k >_ k < k > k < k >_ k
(u, v), i odd (i+l,j) (i+l,j-1) ( i , j + 1) ( / , j - l) ( i - 1,j) (i- 1,j-l)
(u, v), i even (i+l,j+l) (i+l,j) ( i , j + 1) (/,j-l) (i-l,j+l) (i-l,j)
N o t e that d4 does not have the property of Proposition 6. In fact, readily the set of
(u,v) such that d4[(i,j), (u, v)] = 1 is the same as for dl. Let ]i-hi = ]j-k] = 3; then d4[(i,j), (h, k)] = 4, but none of the (u, v) are at distance 3 from (h, k). However, d4 has a weaker property which we can use instead : Proposition 7. Let d4(x, y) = d > 0 ; then there exists z such that d4(z, y) = d - 1, where dl(z, x) = 1 i f d is odd, and d2(z, x) = 1 i f d is even.
Proof." As usual, it suffices to prove the case where y = (0, 0). Let x = (i, j), so that d = max{'i" 'J[' [-2('i'+[J'+ 1 3 l) }" I f d = [i[ is a strict maximum, we can decrease d by 1 by taking z = (u, v) where [u[ = [i[- 1, v = j ; similarly, if d = ]j[ is a strict maximum, we can take u = i, [v[ = [ j [ - 1 . If [i[ -- [2([i[ +[j[ + 1)/3] > O, then readily [i[ > [j[, so that [u] = [i[- 1, v = j decreases d by 1 unless [i[+[j[ is divisible by 3; similarly if [j[ = [2([i]+[j[+1)/3] > 0 , using u = i , [v[ = [ j [ - 1; while if[i[ = [j[, then [2(]i[ +,j[ 1 ! ]+3 is a strict maximum. Thus we are done unless [i[ +[j] = 3r (say); but then [2([i[ +3[j] + 1!] = 2r, so that in the remaining cases d is even, and we can decrease it by 1 by taking [u[ = ]i[ - 1, [v[ = l j [ - 1 . We can now define the desired algorithms. Let B be a binary picture, i.e. an m by n matrix (bu) = (b!°') in which each b u is 0 or 1. Let d be a distance function which has the property of Proposition 6, and l e t f b e the local operation on B defined by
f(b u) = min{b,dd[(u, v), (i,j)] _< 1}. Let Bo be the set of (h, k) such that bhk = 0, and let
d[(i, j), Bo] = min{d[(i, j), (h, k)]l (h, k) ~ Bo} be the distance from (i,j) to the nearest element of Bo. (We assume from now on that Bo is nonempty.) Let b!~+ i, = f(b!~)), r = O, 1....
Distance functions on digital pictures
41
Proposition 8. b15) = 1 for all r < d[(i,j), Bo]; 0 for all r >_ d[(i, j), Bo].
Proof: Since B is a binary picture, clearly b!~) < 1 for any r; and once it becomes 0, it remains 0. The P r o p o s i t i o n is true if d[(i,j), Bo] = 0, i.e. if (i,j)~ Bo, since then h!q) = 0. Suppose it proved for all (h, k) such that dI(h, k), Bo] = s - 1 , and let d[(i,j), Bo] = s. By induction hypothesis and Proposition 6, we have b~],- 1 ~ = 0 for some (u, v) such that d[(u, v), (i,j)] = 1 ; hence b!~) = 0 by definition off. It remains only to show that we cannot have b~ = 0 for any (/1, k) e B and any r < dE(h, k), Bo]. But indeed, if not, let q be the smallest such r, and let b~h')~ = 0, where q < d[(h, k), Bo]" clearly q :~ 0. By triangularity, we have d[(u, v), Bo] > d - 1 for any (u, v} such that d[(h, k), (u, v)] < 1 ; hence q - 1 < d - 1 <_ d[(u, v), Bo], so that by the minimality o f q we have b~,- 11 = 1, whence b~ ) = 1 by definition off, contradiction. vlJ
COROLLARY. Ifd < d~, then x7,.+, J_ur=O h(,) viJ --
=
d[(i,j), Bo] for all (i,j)e B.
Proof." This distance must be less than m + n.
11 1111 IIII 1111 1111 IIII 1111 III 11 II II Ii Ii 111 111 II I fill 1111 Ill 111 ii 111 II II II II I I I Ii 11 I 11 III 1111 Ill I 111 II I II 111 I 111 I
I 11 111 11
11 111 111 1111 1111 111 11 11
11111 11111111 111 111 11 11 11 11 11 111 11 11 11 11 II II 11 11 11 11 III 11 11 11 II II 111 111 1111111 111
1 1 I I 11 II 11 II II 111 111 111 111 11111 1111111 11111111
111111111 IIIIIIII111 111111111111 111111111111 11111111111111 11111111111111 11111111111111 1111111111111~ 11111111111111 11111111111111 111111111111111 111111111111111 1111111111111111 11111 111111111111111 111111111111111111111 111111111111111111111 111111111111 11111111 111111111111 1111111 11111111111 11111
FIG. 6. Test picture.
42
A
ROSENFELD a n d J L PFALTZ
In particular, the hypotheses of Proposition 7 and its Corollary hold for the distance functions dl, d2 and d3, so that the foregoing defines local operations (call themf~ ,f2 ,f3) .+. whose repeated application gives rise to a picture (~,=o b!~)) in which the (i,j) element is the distance from (i,j) to the nearest zero in B We can obtain analogous results for the distance function d4 by using Proposition 7; in fact, we can readily prove
~e3.1.g.7.S.3.1,99..77,,SS,t~,~.jl,jLg.7.b..33333.S.t..q.l.3.S.7. g.l.3~5~ .3.1.9.7.5.3.1.9..77..5~..33..~.5.7..7.5.33 .... °3.5.77.g.l.3.5.7.g. lo3. S 3.1~907.5.3.1.9,77.,§5..33..11.].5.77.S.3..1t111.3.5..7.g.1.3.5.7.9.1.3. .1.$o7.5.3.1.9.7..55..3~..11 1.3.5..5.3.11 1.3.$5.7.9.1.3.5.7.9ol.3 1.g.7.5.3.1.9.7.55..33..|| l.~3,~,~t~'3~L I~,~J..~I,9, L.]~S-1.9,L,. ,q.l.S.3.1.q.l.5..33..II 11.~.~.~.3.1 1111 lo33.5.7.9ol.3.5.7.9.1 9.7.5.3.1.9.7.5.33..11 11,,~.5.~.3,]11-~.,L1 1~,3.~r~l.cl.1~3.~.9. .7.~.3.1.g.7.5.3..11 11..33.S.5.3.1 1..3333..1 11.3.5.7o9. h3.9.7,? 7.5e3~!.9.7.5~3, I L . . . . ~ |~ ~ J ~ J , ~ .5 • 3 . 1 1.33...,33.1 1.].5.7.9.1.3.S.7. • 5.3.1.;.7.5.3.1 11..~3..55,,5.3.1 |.3.555S..3.1 1.3.5,7.9.1.3.5.7. 5.3.1.9.7.5.3.1 ll..3~,,~..~,~,2tl ~L.~.5...J.3.z l,l,5~Id,hl,.O,l. ,3.1.g.7,~.3.1 11..33,,~5,.777,S,3.1 1,3,5,7.~,3,1 1.3.5,7.g.11,3.S,7 3.1.9.7.S.3,1 l..33..S~,,77,,,l[~a~tl 1.3.SL,jd, t 1,3,.5~l,J,l, lt l, 5, • 1.~.7.5.3.1 1.33..55..77..g9.7.~.].1 1.3..55~.3,1 1,3.5.7.9..g.l.3. b 1.9.7.5°3.1 1.3~.55..7~..9g.?.~.S,~.1 1.33...33.1 1.3.5.7.9.9.9.1.3. .9.1,5.3.1 1.3.55..77..g9..1.~.7.5.3.11 1..3330.1 1.3.5.7.9.9.7.9.1.3 9.7.5.3.1 1.3.S.77..9;..ll.l.g,7~j3t~L 11-..11 1,3~ttZ~,9,/~,gtl~ • 7.~.3.1 1,3.~.7..gg..11..3.1,9.7.5.33.1 111 1.3.507.g.9.7.S.7.9.1 7.5.3.1 1 1.3.~.7.9..||,.3~,3,l,~tTj~,~3~L_ _ Le3eS.7_t .~.7.5.S. 7.9. • 5.3.1 1.3.5.7.9.110.33..5.~.1.9.7.55.3.1| 11.3.5.7.9.g.7.5.3.5.7.9 ,S.3,1___]~t~t~.7.9.1.33..3~.S.~.l.q.¥..S.3..l11..3.S.7.q.q.7.q*3.3.~.7~ • 5.3.1 1.3,5.7.g.l.3..,3.,3.~.3.1.q,TT.S.33...33.S.7.q.9.7.~.3.1.3.5.7 • 5.~.L 1.3.5.7o9.1.3..~.1,.1.~.5.3.1,gg.7.55...55.7.9..9.7.5o3ol 1.3.S. ~.3,1 1,3,5,7.9.1,3,3,1. S.l.?~.l..9.7..5SS..l.51~l-q~7.5.3.~ 1-3-5. 5.3.1 1.3..5,7,g.l.33.l,g..g.l.3.S.3.n.g.77...77.9. hg.7.~.3.11 1.3.5. ~5~_J~)_t~,7.9.1..l.q.7_~.g.l.3.s.~..l.q..777..q...g.7.s.3.1 1.].s_7 ,3.1 1.3,3.3,5.7.g.ll.g.7..7.q.l.3.5.33.1.gg...g?..g .7.~.3ol 1.3.5.7. • 3 .1 1 . 3 3 . 1 1 . 3 . 5 , 7 . g o l . S . . S . ? . 9 . 1 . 3 . S S . 3 . 1 1 . . . l . g . 7 7 . . S . 3 . 1 • 3.1 1.33,1 1.3.5.T..7,~.3~05.l.S.I.3.55.].~LLI.9.7.°SS.3,J,I 5.3.1.3.3.1 1.3.5.7.?.~.3..3.~.7.9.1.3.55.33.1.9.7.55..3,1 .~.~.3e~,~3_t~|t3.5.77.S.].ll.3,~.7.q.l.3.s.3.1.q.7.5..3].l 7.~.3,555.3.1.3,5.77.S.~.1 l.~.5,7.g.l.3.3.l.g.7.S.33..l .7.~.5...5.3,3.~5.77.5.~,1 1.3,S,~,9,1L3Ol.9.7.~.3..11 9.7.5.333.5.3.55.5.7.5.~.1 1.3.5.7.9.1.1.g.7.~.3.11 ,7,~,3,,.3.5,5~,3.5,7,~,3.1 1,3,~1.9-11-~Jl. 5,~ 7,5.3.111.3.55.3.3.5..5.3.1 ll.~.~.7.g.il.q.7.5.3.1 e~3e]L~__l.3..3.1,~,S.,~.3.~L~,S.7.g.l.l.g.7.S.3.1 7.5.3.1 1.3.3.1 1.3,5..5.~.33.5,7.$.1.1.g.7.5.3.1 7.~,3"1 1"33,1 1,3,S,~.~,,~.I.~.L,I.q.7.5.3~I-. . . . 7.5.3.1 1.3.3.1 1.3.5.7.~.55,7.g.1..|.9.7.5.3.1 ,7.5.3.1.3.5.3.11~3,~,?T.~,.~,?~Lul, LT.S.3.L ........ 9.7.5.3.3.5.3.3.1.3.5.71.5o.5.7.9.1.. 1.g.7.S.3. | .g.2.5.3.5.3.3, 3.3.5.77.5.~.~.5.7.g. 1.1.g.7.5.3. ! log.7.5.5.3.1.3.3.5.77.s..3..3, c..7.g. 11.g.7.5.3.1 .1.S.7.5.]. 1 1 . 3 . 5 . ~ [ 1 L S j ] . 1l . ] l ~ . 7 . q . 1 l . g . 7 . S . 3 . 1 1.9.7.5.3.1 1.3.5.7.5..~.1 1.3.5.7.g. Ueg.7.5.3.1 .g.l.S.3.1 1 . 1 . ~La_7~t~.~~i.. ! .-~. q . " / . q . . q . 7- q . 't'~. ! • 9.1.5.3.1 1 . 3 . 5 . 7 7 . 5 . ~.1 1..~. 5 . 7 . g . g . 7 . 5 . 3 . . . . 1 !. 9.7.5.3.11.3.5o_~1.5.3.1
[email protected].]. ! I 111 . 1.S.7.5.3..3.5.55o7.5.~ . 1 1.3.5o7oo7.5o3.1 1 30 L t . 7 . 5 . 3 3 . $ . 5..~. 7.5.'~ • 1 1 0 J . 5 ~ 7 , 7 - ~ - ~- 1 . 3o 1 0 g . 7 . 5 . . 5 . 5 . 3 3 . 5 . 7 . ! . 3 . ] 1.3.5.77.5.3.1 ~tJL3.1.9.L7. SS. 5 . 3 ~L~. 5 . 7 J e ~. I ] . ~. ~ . 7 7 . ~ . 1-- 1 It .5.3. h9.7..5.3. 11o3.5.1.5.3..3.5.7.7.5.3. 1 1.1 • 5.3, 1,g,7,5.3,1 1.3.5,7.5,33..~,7,g,7,~,3,1 1..1
FIG 7
C i t y b l o c k d i s t a n c e s (d])
from the b l a n k s
1o3.5.7.9 1~3.5~7.~ 1.3.~.?°9. 1 . 3 . s. 7 . g . 1 1.3.5.7.9.1. 1.3,~5.7.9.1.J 1.3.5.7.9.1.3 L.3. S.7~.~.J.J 1.3.5.7.9.1.3 1.3.5.7.q.1. 1.3.5.7.9.1 L. 3.S.7.~.L 1.3.5.7.9.1 1~3.5.1.9~ 1.3.5.7.9, 1.3.~.?.g. 1.3.5.7.9. 1.3.5.?.g 1.3.5.7. t _ "~. Ii. 7 1.3,5. l _ l . ri h3.b 1.3.5.7 I.t.q.? 1.3.5.7 1.3.5.7.
Distance functions on digital pictures
Proposition
9 . L e t b l ] k+ ~ =
fl(bi~(2k) ), k
= 0, I,
" b (ij2 k +
.....
2)
43
£ i k ( 2 k + 1)~ j2~uij ,,
=
k = 0, 1,. .. Then
bl~~ -- 1 for all r < d4I(i,j), Bo], and = 0 for all r >_ d~[(i,j), Bo]. COROLLARY.
~ ' m + n h(.r) =
d~[(i,j), Bo] for all (i,j) ~ B.
The results of applying these algorithms to the binary picture in Fig. 6 are shown as Figs. 7 10, respectively.
3o.11..999.,.777o..555...33333333°555.°.33333333333,.55.°77.o°9.1.3.5.7o °°1Lo°99...777...555,..333 ...... 3.55.,333 ......... 33°.SS..77T,Q°L°3.$.7. .lL°+99.,F/l.°.55~,..333.,.LLLL.3.5..33,..LLILLLL.,33..55...?.g. Lo3.5°7, I~E..~..77...555... ~..--[l~-L.~...~]..lll L I . . 3 3 . . 5 5 5 . T o 9 , L. 3 . 5 . 7 . 1..79..77..555.,°333...Iil 1.3..33..11 ll..33...5.F.?.l.3,5.Y. ..99..?T..55,..333...111 11L.3.33..II LIlL lL..333.5.T.9ol°3.S°Tt ,gq..lT..55..333,..lll 111..°3.3..11 LiL..Lil 11,..3.5.7.9.1.3.5... 99,.77,,55..33,,.111
111...333.3,11
9°.77.,55..33..LLL • 11,,55**33.,1L
111...333.,.555.3.
77..55..33..11 ?..55..33..lL
II ......
LIL...313...3.1 l
lLL..,333...555.5.3.1 lL...t33...555...5.3.1L
5.3.°1 .o3°~1 .33.1
• ~.L
• 3.L
....
1.3.5o/.9.1°3
33..1
L.3.5.1,9.1
LL.o33.]3..I LL,.333..11 LI .....
'lit.
11
Ill
..... .......
L.3.5.T.9, llLllllL L°3.5.T.9 ........ . L.3,5.1.9999979999 1.3.5.Z.,,,...o... LI.3.5.7777TtTTTTT7
11..3,5
.............
ll.33..55..T/T...9.7..5.333..11 ILL 11..33.5.55555555555o l..3..55..7T...999.//,5...33..IL L1..33..5.5,°...°.o.5. 11.33.55..77..q99.9..7.555..33..11L 111.°33..$5.5,3333333.5. L..3..5..rr..99.,.?9.T.,.55..33.,,llLll.,,3~,.55..5.3,.,,.3,5, 1L.33.55.77..99..L..9.777..55..333.,~..~3~.~55~55~ 3.iLL.3.5. L
L..3..5..7..99..IL1.9...77..55...333333333,°.55.55°..3.1 1Lo33°55..77.9...,..,g99,o~7..555 ....... ....555.55°.33~.1
1.3.5. 1.3.5. L . , 3 . . ~ 5 ~ . . r . 9 9 9 9 9 9 9 9 9 9 9 9 . o I T . . . 5 5 S 5 5 5 5 5 5 5 5 5 5 . , , 5 . . 3 3 . .1. .I3 . 5 .
.3..I • 3. LI
.3. L
L,.3
l..33.,55,,.777,,.7.55.3.,.ll
•5.3,.1L • 5.3°11 $5°~.I 5°.3.l S.~°L
111.3.5,?.9,1.3.5555
1l,33 .... 33. L |.,33°..33.1
°.55°.33..LL Ll..~33..,55~.,,7.5.3..L •55,.~3..11 1 1 . . 3 3 . . . 5 5 5 . . . 1 7 7 . 5 . 3 3 .L .5,.33.--~ I[..33..5S~...777.T.5_.3.111
.5.33..11
11
1L,.3333,.11
I I . 3 3 . . . . ~b.7 . . . . . . . . . . . . . . . . 7~7.,..,..,.,, ..... ,5.33,.111 1.3.5. i . . 3 3 3 ~ 3 . . S . r ~ Z 7 7 Z Z Z r T T Z T 7 7 Z . . . r Z r ~ 7 7 T r ~ T T r ~ . . 5 5 5 . 3 . . ~ LL L . 3 . S . 1L . . . . . .
5o 5.7 .............
° T7 . , . o . o ° . ° ° o ° .
~
° ~55j~.L[
1[ ° 13 ° 5.
I,..lll..3.5.7.555555555555.°77.979999°.°TT7..55..333.1 11..33.5. 11.3.1 1 1 . 3 . 5 . ? . 5 . . . . . . . . . . 55..T.q...9..TTT...55..33...I I..33..5.
• 3. L L..3.I
1.3.5.7.5.33333333,.55.7.g..99.77.,.555,.33..1L1
• 3.111.)3.1 • 3,.°..33.11
L . 3 . 5 . 7 . 5 . 3. . . . . . 3 3 . . 5 . 7 . 9 , 9 g . . 7 , . 5 5 5 , , . 3 3 . . L L 1.3.5.7.b.3.1111..33.5.7.9.9..77.55...333..11
.... ,,..33 .....
3.55555.).L
L.33..55,
LL.3.5.7.99..7..55.33°..LlL
55.3)33333333333 ..... 5,3.L L.3.5,7.g9.77.55..3..1Ll .5.3. ...... 3.333333~.,,3oll 1.3°5,7.99.7.o5..33.LL .5,3o1L11L.333 ..... 33.,3.,1 LLL.3.5.7.g9.?.55°33..1 o5.3.1 L . 3 3 . . LL L . . 3 , . 3 3 . l L L . , , 3 , $ , 7 , 9 9 . 7 . 5 , . 3 , . 11 •~ . 3 o l | L.33,LL LI.3,,.3 ..... 333.5.7.gg.7.5.33.L1 .5.3o.l 1.33.L L. 3 . 5 . 3 3 3 3 3 3 3 . . . 5 o 7 . 9 9 . 7 ° 5 . 3 . . l .5.3). L LL.33.1 L.3.5 ......... 555.7.99.7.5.3. • 5..3,L[1.,33.lL LL.3.55555555555,,,?o99.7.5.3.1 .5S.3 ..... 333.,1LL..3 ........... 55.77 .... 7.5.3.L • .5.333333 ......... 33,.3333333J..5.T7..TTt.5o3.L
i.5....33..L(l.33~33...3 ?.5555o3..1L T. . . . 5o3.11
TTTToS. 3.I °..To5.3.1
......
L..3.S..77.
LL
11.3.$5o°77 1.3..55..7 l, 33..55.. 1..33..55o 11..33..55 11..33.o5 11..33.5 1lo.3,5 11.3.S 1.3.5
33.5..T.rT...5.3.L
3,Llll.o3,55oT17..555.3o11 1.3.5555.33°I L1.3..5.77..55o.,3,.II
1.3.5.,5.3.,1
99.7°5.3.IL11..3,5,.$, 3,l
L L . . 33..5o 77. L . . 33o.55. T . . l . . 33,55o.7.9 11o.3o55o T I . 9
1L.3.o5.7o,9 L. 3 3 . 5 . T T . .
L.) . . . . . . .
11.3.5..5.3,ll
11.3.,55.. 1L..3.55..7
1.33.5.7..55..3333..1 L..3.5.7,55.,33...,oll
L L . 3 . 5 , 7 ° 5 . . 3 3 . , IL1111
1.3.5
.9. T.5.33333333 ....... 3..lL . 9 . To5 . . . . . . . 33333333.33..1|
L.3.5.?.~.3,.11
IL.3.5 ii..3o5
1,3.5.7.5.3,|1
,9. To555555,33...,..3,o33,.IILI.3.5.?°5o3.1
,9.?, ..... 5.3..LLIL.3...33 ...... 3.5.?.5,3.1 .9oTTT??T°5,3.LI L.3,5..33333333.5,7.5.3.LL
FIG. 8. S q u a r e d i s t a n c e s (d2) f r o m t h e b l a n k s .
11 11L l.lL
1.o33.5 i.3~..s 11.3.o55
44
A. ROSENFELD and J. L. PFALTZ
7..~..3..l..99...77...5~...]33~.~.7..~...3~333333.~5.77..g.l.3.5.?.9.1|q .55.33.11.qq..777..5~,.~.~..~ ....... 3..5..77.9.1.3.~.7.9.1.. .5..3..1..~..77...~...~...111.3.~.~..3...|11111.~3.5~..7.$.1.3.5.?.q..9 5.3~.II.qq.77..553..3~3..111 1.~.~.33.111 1..3..55.7.9.1.305.7.qg$. ..3..1..9..7..55...33...11 1.3.5..]..1 11.33..5.7.9.1.3.5.?.... 33.11.~.77.55..33~..111 11.~.5.~3.11 1111 1..33.5.7.g.1.3.~.77777 3..1o.$..7..5..~3...11 111..~.5.~..1 111...11 11..3.5.7.q.1.3.5..... • 11.g~.77.55.33..1t1 11..,3~.~11 l~._~..|l 11.3.5./±~J.3.5555S5 • 1..q..?..5..3..ll 111..233..q.3.1 11.333033..1 1.3.5.7.9.1.3 ...... 1.qq.77.55.~3.11 11.~.~3...~55.3.1 1.3.....33.11 1.3.5.7.9.1.33533~. 1.~..?..5..~..1 J11..~3~..55~.5.3.1 1.3.5555..3.1 1.3.5.7.9.1.......3 .q.]?.55.?~.11 11...~...5~ .... ~.3.1 1.3..5.55.3.1 1.3.5.7.q.1111111.3 • $.]..5..~..1 11..~2~..~55..7]].~.~.1 1.3~.555.3.1 1.3.5.7.9........1. 9.?.55.33.11 1..32...5~...]7..~.5~.1 1.~3 . . . . 3 3 . 1 ~_~_._7 Qt~q_~9~qt|. 9.?.5..3..1 11.33..55~..13~...~.5.?.1 11.33333..1 1.5.5.T.........q.l • 7.!.33.11 I..~..5~...~7...q~.7.~.~.111 1...3..11 1.3.5.7.77777777.9.I • 7.~.3..1 1.3~.5~..7~..~9.~.7.5.3...1 111..11 11.~.5.1.7 ...... .7.9. 7.5.3.11 1.3..5..77...~ .... ~.7.5.~33.II III 1..3.5.7.7.555555.7.9. 7.5.3.1 ! 1.3.~5.17..~q..111.~.7.~...~...1 11.33.5.7.7.5.....5.7.? • 3.~.1 1.3.5..7..Sq...11..1.~.?~5~.~.111 |J_~.~.~.7~?~33~3~.1.9 • 5.~.1 1.3.5.77.q~..111..3.1.9.7...~..3...1111..33.55.7.?.5.3...3.5.?. • 5.2.1 1.3.5.7..~..11 ....... 1.q.727.55.~33 ..... 33..5..777.5.3.11.3.5.7. • 5.3.1 I.~.5.7.~.1111111111|1.~...?..5...33~..~5.377..5.3.1 1.3.5.7 5.5.11 I.~.5..7.q. II ............ ~.??.555 ....... 5~..7.7.5b.33.1 1.3.b.7 5.~.I 1.3.~50.7.9.1.~q~9~...q..7...~555~55..77.7.5..3..1 1.3.5.7 5.3.1 1.~ . . . . 5 . 7 . ~ . . q . . . . . . . . . . O...qq.7?~u~u~..L7.ZZ~.~Lli ~l.~tZ 5.].I 1.33~33.5.7.q.q.~???~71~?.~...~...7717777777..7..5.3..l 11.3.5.1 • 3.1 1.?~...3.5.7.~.? ........ 7..~.1.~.... ....... 77.55.3.11 1..305.?. • 3.1 1.3~.ll.3.~.?.q.7.55~55.??.~.l...qq~$qS...?l..5..3.1 11.33.5.7. • 3.1 1.~.1 1.~.~./..7.~ ...... ~..?.~.111 ...... ~.773..55.33..1 1.3..5.7.g • 3.1 1.?~.1 1.~.~.7.7.~.~:33,~5.7,~.1.1111..~.?...55..3..11 1.3.55.7.9 • 3.11.~.~.1 1.~.5.73.~.~ .... ~..~.7.~.1...I.~9~7~*~,~..~1~__~,~..5~,7.~. 5.2...~..?.1 1.2.~.77,5.~.111.~.5.7.~.1..1.~..7.5...33..1 11.3.5.77.9. 5.3233.5.~.11.~.5 .... 5.2.1 1,,2,5,7,~,1,1,~,77,5,333,,11 1..3.5.7..9.1 • 5... ..... ~...~.55~5,~,~.I 11.3.5.7.~.11.~.?..b.~...11 11.33.5.7.~.1 .~5,3~333 ..... 5.5.2.1 1.3.5.?.q.l.q.7.55.~.lll 1.3..5.7.q,.1. 7.~.3 ..... 3 .... ~33.5.~.~.1 1.~.~.7.~.I.9.7.5..3.I 1.33.5.?.9.11. • 5.~.1111.~..33...~,5.5.~.1 ll,~,~.~.~. I.~.7,5~]3.1 ..... 1..3.5.7.?.1~3 • 5.~.I 1,3,3,,11,~,5,~,3,11,,~,5,?,q,1,~,1,5,3,,1 I1.3.5.T.q.I. • 5,~,11 1,33,11 1,3,5,~,J,,,3~,5,7,~,1,q,7,5,3,11 1,3.5.7,~,I. 7.5.3.1 1.33.1 1.3.5.5.~233..5.7.q.I.9.7.~.3.1 1.3.5.7.99. I 7.5.3.1 1.3.~.1 1.2.5.5 . . . . . ~ . 7 . ~ . I . ~ . 7 . 5 . 3 . 1 1 1.3.5.7oo9.1 .7.5.3.11.~..3.1 II.2.5.~55555~..7.~.I.q.7.5.3.1 1.3.5.7T.~. At.IJ~_u ?- 9~L 9.7.5.33333...3...33.5.5.23233.~.7.~.1.q.7.~.3.1 L.33.55.?.9 I,.3.,5o7,9 • S.7.55.3..1 1,3.,.55.5.~.111.~.5.7.~.~..7..5.3.1 11.33.5.1. • ~.~.5.~.11 1.~.55..5.2.1 1.2.5.7.~.77.55..3.|1 I..3.5.7. • S.~.5.3.1 1.~.$...~.2.1 1.3.~.?.~.7..5..33~.1 11.3.5.7 1.3.5.7 I.~.7.~.3.111.3.5...5.~.1 1].2.5.7.7.5..3..11111 1.3.5. 1.~.7.5.~ .... 3.555555.].11 i.3.5.77.5.33.11 1 1.3,~, • 1.~.7.5.~3~]3 ...... 55.1..1 1.3.5.37.5.3..1 II.3.5. • 1.~.7.5 ...... 3~33~.55.2~.!1 1.3.5.7.5.3.11 1, • 3 e.5~3 3.1.q.7.55555.3 .... 2.55..3..111.3.5.7.5.3.1 II 1.33.5.7 ~.1.~.7 .... 5.3.111.3.555,33 .... 2.5.77.5.3.1 111 1.3.5.7. • ~.1.S.777.~.3.1 I.~.5.5..~3~.5.7.7.5.3.1 1..1 11o3.5o7. F I G . 9. H e x a g o n a l
distances
(d3) from
the blanks
Distance functions on digital pictures
~,,~,,3,,!,,S?,,,77,,,~,,,]33~,,~ ,,~,,3,,1,,9,**77,,,~,,,3~,,,,3,,5,,5.,~3
....
45
~,,,3333333,,5,,7,,,9,,L~_3,,~,,7,9 ....... 3.,5,,77,,S,,1,,3,°5.7.q
.,5,,)~,1,,g,,77,,,55,,,~3,,,11,o3~5,S~,~,.,11111..3.,5,,,7,,9,.I,.3,5,7,? 5,,~,,1,,**,7,,,5S,,,~,,,11 1,3,5~,,3,,11 1,,3,,55,,7,,9,,1,3o5,7.9 • ,3,.1.,q.,7.,5~,......~ ,11 1.3~5,.~.~I .... 1**3....,~o7.~1~7,~ • *****************3***** L1.,3...3.,1 1111 1..3~..5**7.9.1.3,5.777 ~..I..~..7..5..~3,..11 11,..~...~..!, ll..*~!i_ ~ . . ~ _ ~ , _ I ~ . ~ * § .... ,,1,,~,,7,,~,,3,,,11 11,,,3~,,,3,.1 I,,,33,,,I 11..3,5,7,9,1.3,55555 • I..9..7..5~.3.,II~..,]3,..5,3.1 1.,3~..)~.,| 1.3.S.7.9.1,3 ...... I..~..7**~**]**I II..,3~.,.~E~.3.| 1.3 ...... 3..I 1.3.S.7,Q.I.333333. • ,~,,7,,5,,3,.1 Ii,,,~,,,55,,5,3,1 I . ~ , , ~ , ~ , I 1,3,5,7,~_,Lu,~_ou~ • ~,,7,,~,,~,,1 11,,,~3,,.~ .... 5,3,1 1,,3,5,,E,3,1 1,3,5,7,q,1111111,. ~,,1,,~,,~,,1 I,.,33.,.~5..,7i.S.3..I 1,3,,~,~**1 _~,~5,7,~ .... ~,,~, ,,7,,5,,~,,! l.,33,..5~...!7,~,5,,~,1 1..~ ..... 3,1 1,3,5,7,Q~S$9S99,.1 • 7,,5..~.~1 _1_..~:~ .~.,.7~.~±~,~| 1..33.33,,1 1.3,5,7 ......... 9,, 7..E..3..1 I,,~,,EE,,,~],,,~,,~,E,3,,II 1,,,3,,,1 1..3.5.7.7777777..~. • ,5,,~.,! 1.3,.~°..77.,.qq,~.7.Eo.~...l ~L.~*_/L~I.~.*5*77~*~.~.7*.q .E..3..I l..3.E.,77.,,qq.,,9.~..5..33..l 111 1..]..5..7..55555..7.. • 5,~..1 1 1.3..5.?.,.q~..,l.~..7..E,..3.¢I |,.3,,5**7,,5, .... 5,,7. • 5,~.1 l,,3,5,,7.qq,,,lll,,~,,7,,EE.,3,,|l 11,°3,,~,,7,,5,,333,,5,,7 • E,],I 1,3..~7,.**,]1.±.l,,q,.7,~ ,E.,3,,,111,,,3,.5,,77,5,,3,,,3,.5.7 • E.~.I
l,.~.5,.7,q..J
5..3.1 5.~..1
• .3.1 • • • •
3..1 3.) ~*] 3.]
......
l..q,,77..E..3~,
....
33,,5..7.7.5.3..1..3.5.7
l.~.*5.7..q.llllllllll..q,.,7,,E,.,3~3~3...5**7,7.,5.3,1 1..~,5**7,q
...............
~q,,7,,~S
.....
1,~,~,7
,.E5,.7,7,,~,.3,1
1,3.5.7
1,3.5.7
1..~...5..7,.q~.,.,.,.,..~ .... q,.77,**,..,..77.7..5..3..11 1.33~3..5.~7 .... ~777~77~..~**,eT77777777.~.7.~..Q..! 1..Y..,3..5..7.,7.....**.7..9.**.9~ ............ 7..5.3..I 1.3**l,*~..E*7*7..SES~55..7.*** .... *gSgqqS...77..5..3.1 I*.3.1 I*.3*E°77..E ..... ,~..7.**..I ...... ~..77...5..3..I
• 3.1 1 . ~ 3 . 1 •3,,I,,~?,I
1.3.5,7.,E..3?~3..~..7.,S..
1~3~.7 /..3..5.7 l*.3..5..7 1.3.°5..7.
|1l..~..7...55..3..11
1,3,5**7,,
I , ~ . 5 ° 7 . E , , ~ . . . . 3 , ~ 5 , , 7 , , 9 , l l,.~., 7,, E E , , , 3 , , l 1..3.5.7..q • .2...~.3..1 1 . ~. ~ , 7 . ~ . ~ . . I 1 ~ . ~ . . E . . 7 . ~ . | . . ~ . . 7 . . ~ . . . 33 . . I 1,.3..5.7.S. 5..~3~...~..1..~.~...~.~.1 1..3..5,7.q,1,9.,?..5..33.,,1 1**3,.5,.7,q. • E ........ 3..*~**EE,.E*~,] 1..3*E.7****.5.]**~..3.,*~] I.t3..~*~7.*~* • *~..333~.333 ..... E.E,~,I 1,3,5.7.q..9..7.5,,3,.1l 1.3..5..7..9.. • E..3 ..... 3 .... ~3~,.~E.~..I !.3~,7,*,~.L~,5,~ol ~,_,~.5..~.9.=1 • E.~**I~I..?**3...3..E..~.I ll.,3.5.7.q.q.7..5..3.1 1..3..5.7.9..1 • 5.~.1 1.-.~..1.,~.....*~1...~.5,7,~q,,7.5..]..| 1..3.5.7..9.1 • 5,~**1 1.~3.*1 1o.3.5.,3...]~..5..7.**.7..5.3..1 1.3.5..7.Q.| •E,,3,I ..5,3.1 7.5.3..1.
1.73.1 1..~3.1 ~.3..I
1.3.E~..3~3...S~.~..gS,7.~I l.?,~,~ ..... ~,,7.,q,~,7.5,3.,1 1, ~ ' I.,.~,.E: ...... c...'/..q..~.7.E.3°
7.5,. 3,** ?. 333.. 7...~..333.3...3 . . . . . . .~. . . . Ec _ .7,,5 .... _~..1..333,,5~,,.
~
l
.......
X.3.5..7..9
~ ~-~3.,E,
~ ....
,7,,5,5,7.~,3.1 3,,5,,7,$,S,7,5,3,1
. . 7 . . E . . 3 . . 1 1 . . s . . , E .~ , . : . , 11 , , ~,_, ~,, 7 , q ~ j 7 . 5 , . . , , 1 ~..~.E.3..1 1.3.~E..E.'.I 1 . . 2 , ~ , 1 . . . . 7,,~.,,3,,I ,q,~,5,.Sol 1,3,E,,E,~,I I,~,~7,,7,,5,,333, I ,~,~,E.-~.I 1,,~.5,,~,3,.1 1,3,,5,7,7,,5.,] ..... l . q . ~ . ~ ? . . I I.. 3.±~ o.E. 3. I 1..3.E.77..S..3.. lllll .~,~.5..3 .... 3..EE~E.3..I 1,3,5,7,,5**3,,1 1 .~.~..5..3-~33 . . . . . . . 5 , , ~ , , 1 }L~,7,5.,3,,1 .*..7..~
1,3,,5,'~L~J~ 1,.3.5,7,9.,
.~3.s~..E..3..l
1.3..5,,7,,: l.,3.,5,,7,
1..3..5.. . . . .
1.3.5. 1.3.5.
].3.~.7.~.~.,1
..q..7..~ESE..s.... , . S , ~ L ~ . ~SL ' g I | * , 3 . E . 7 . ~ . 3 . I I . . ~ - . . 7 . . . 5 . . 3 . . I I . . 3 , E : ..3 .... 3 . . 5 . 7 . ~ . ] . I .1..9.,77.5.3..1 I..~.E.~.. ~33~.,~,,7,5,3,, 1 FIG. 10. O c t a g o n a l
1~.3..5. 1,,3,5,
1, .3,,5, II 1,1
l,,l
d i s t a n c e s (d4) f r o m t h e b l a n k s .
J~3..
5..~
1.3.5..7 1.. 3,5,.J.
46
A. ROSENFELDand J. L. PFALTZ
3. APPROXIMATIONS TO EUCLIDEAN DISTANCE As shown by Figs. 1-5, the "octagonal" distance function d4 is a better approximation to Euclidean distance on A × A than are the "city block," "square," and "hexagonal" distance functions d~-d3. In fact, it is an adequate approximation for many purposes, particularly if(as in Fig. 6) the distances to Bo never get very great. Figure 11 shows nearestinteger Euclidean distances from a single point (0, 0)--in other words, d[(i,j), (0, 0)] = d means that d - ½ < ~ < d+½. [It is interesting to note that "nearest integer to Euclidean distance" itself is not a distance function. For example, let (i,j)= (1, I), (h, k ) - - ( - 1 , - 1 ) ; then ~ / ( i - h ) 2 + ( j - k ) z - - x / ~ , the nearest integer to which is 3, but x / ~ + ] -2 = x / ~ + k ~ = x ~ , the nearest integer to which is 1, so that triangularity is 1[L..o.99999999999oooo1|[ 1|°..9999 ....... .o..~999p,.1[ 1|o..9~ .... 77777777777 .... 99...11 LL..99...777 ........... 777...99~.[| 11..99..777...55555555555...777..99..1l ll,99..77...55~5 ......... 5555..~77e. Q~_LL [..99.77..555 .... 333333333 .... 555..T7.99..l 1..9..77..55..3333 1..9..7..55..33
.........
3333..55..77.,9..L
lllllllll .... 33..55..7..~..[ I..9..7..5..33...III ......... Ili...33..5..7..9..1 II.9..7.55..3..111...999999999...I11..3..55.7..9. I1 1.9..7.5~.33..II..999 ......... 999..11..33.55~7..9. I ....
1.99.7.55.33.11..99...777777777...99..11.~3.55.7.99.1 II.9.7..5.33.11.99..777 ......... 777..99. II.33.5..7.9.11 1.9.77.5.33.11.99.777...5555555...777.99.11.33.5.77.9.1 I..9.7.~..3.11.9..77..555. ...... 55~..77..9.11.~..5.7.9..1 1.9.7..~.3.11.9..7..55...3333333...55..7..9°11.3.5..7.9.1 1.,9,7.5.3..1.9,.7..5,.~33, 333,.5..7..9,1~!3~5~ff~9_-~ 1.9.'7.55.3.1.99.7..5..3~..IIIl111..33°.5..7.99.1.3.55.7.9.1 1.9.7.5.3.11.9.7..5.33..II, ...... II..33.5..7.9.11.3.5.7.9.1 1.9..7.5.J.I.9.77.5.33.1/..9999999..II.33.5.77,9.1.3.5.7..9.I 1.9.7.5.3..I.9.7.5..3.1t.999 ..... 999.11.3..5.7.9.1..3.5.?.9.1 1.9.7.5.3.1.9.77.5.3.11.~9.,77777..9~.II.3.5.77.9.1.3.5.7.9.1
1.9.7.55.3.1.9.7.5.3.1.99.7..55555..7.99.1.3.5.7.9.I.3.55.7.9.1 1.9.7.5o3.1.9.7..5.3.1.9.7..5 ..... 5..7.9.I.~.5..7.9.1 3.5.7.9.1 1.9.7.5.3.1.~.7.5.3.1.99.7.5..333..5.7.99.1.3.5.7.9.1 3.5.7.9.1 1.9.7.5o3.1.9.7.5.3.1.9.7.5..3...3..5.7.9.1.3.5.7.9.1 3.5.7.9.t 1.9.T.5.3.1.9.7.5.J.l.9.7.5.3.111.3.5.7.9.1.3.5.7.9.1 3.5.7.4.1 1.9.7.5.3.1.9.7.5.3.1.9.7.5.3.111.3.5.7.9.1.3.5.7.9.1 3.5.7.~.I 1.9.7.5,3.1.9.7.5.3.1.9.7.5..3...3..5.7.9.1.3.5.7.9.1.3.5.7.9.1 1.9.7.5,3.1.9.7.5.3.1.99.1.5..333..5.7.99.1.3.5.7.9.1.3°5.7.9.1 1.9.7.5.3.1.9.T..5.3.1.9.7..5 ..... 5..7.9.1.3.5..7.9. I.3.5.7.9.1 1 . 9 . ? . 5 5 . 3 . 1 . 9 . 7 . 5 . 3 . 1 . 9 9 . 7 . . 5 5 5 5 5 . . 7 . 9 9 . l . 3 . 5 . 7 . 9 . 1 . 3 . 5 5 . T.9.1 1 . 9 . 7 . ~ . 3 . 1 . 9 . 1 . 5 . 3 3 . 1 . 9 . . 7 7 . . . . . 7 7 . . 9 ~ J . ~ 3 . 5 . 7 . 9 . I . 3. ~ 7 . 9 , 1 1 . 9 . 7 . 5 . 3 . 1 . 9 . 7 7 . 5 . 3 . I I . 9 9 . . 7 7 7 7 7 . . 9 9 . l I . 3 . 5 . 7 7 . 9 . 1 . 3 . 5 . 7 . ~, I 1.9.7.5.3..1.9.7.5..3.11.999....~999.1|.3..5.7.9.1~.3.5o7.9. I 1o9..7o5.3.1.9.77.5.33.11..9999999o.11.33.5.77.9.1.3.5.7..9o1 1.9.7,5.3.11.9.7..5.33..11 ....... 11,,33.5..7.9.11,3.5.7.9.1 1.9.7.55.3.1.99.7..5..33..IllIIlI..33..5..7.99.1.3.55.7.9.1 1..9.?.5.3..1.9.,7..5..~33 ....... 333e.5..7..9.1..3.5.7.9~1 1.9.7..5.3.11.9..7..55...3333333...55..7..~.II.3.5..7.9.1 I..9.7.5..3.11.9..77~.555~..,...55~..?~,LI1O3,O5.7o~o.l 1.9.77.5.33.11.99.777...5555555...777.99.[1.33.5.77.9. l 11.9.7..5.33.I1.99..777 .... ~ ~777,~99.~.~3.5..7.9.11 1°99.7.55.33.11..99...777777777...99..1t.33.55.7.99.1 !.9..7.55.3~..II..9~9...~..°~999,.I1..33.5~.7..9.1 tl.9..7.55..3..111...999999999...111..3..55.7..9.11 ~,,9''7-,5,~3~,,~Ll,~''e~'L,.II1,L~3..S.LZ*,9,,I 1..9..7..55..33 .... IIIIllI11....33..55..7..9..I 1..99.77..555 .... ll.9~..77,,,55~5
333333333 .... 555,.77.99..1 ......... 5555...77..99.11
11.o99..777...55555555555..o777.o99°.ll II.,o99oo.oT?T?7777777o.oo99..o[l ~.~999...~ ....... 9999...11
III ....
QQQQ9999999 . . . .
III
Fzo. 11. Nearest integer to Euclidean distance from a single point.
Distance functions on digital pictures
47
violated. Similarly, "greatest integer not exceeding Euclidean distance" is not a distance function, as shown by the example (i,j) = (2, 3), (h, k) = ( - 1, - 1).] The algorithm for computing d4 was obtained by alternating the algorithms for dl and d2, and is a better approximation to Euclidean distance than either of them. This suggests that other distance functions, and perhaps still better approximations, might be obtained by "mixing" these (or other) algorithms in other ways. In this section we show that octagons are the best "circles" which can be obtained using only isotropic local operations of the type used in Propositions 8-9. We also show that arbitrarily close approximations to regular octagons can be obtained. Let O(h, k) be the octagon with vertices at (k, _+h), ( - k , _+h), (+ h, k), and (++h, -k), where 0 N h _< k. Note that if h -- 0, this octagon degenerates into a diamond, while if h = k, it degenerates into a square. It is easily verified that Proposition 10. Let B -- (bu) be a binary picture in which Bo ~ O(h, k), where h > 0, and let C = (f,(bij)), D = (f2(bij)), and E = (f*(bi~)), where f * ( b 0 = min(bii, bi_t, ~ ,, bi l.~+l,bi+t,j_l,bi+i.j+i). Then C o = O(h,k+l), while Do = Eo ~- O ( h + l , k + l ) . This proposition implies that if d is a distance function which is computed by iterating the isotropic local operations fl ,f2 and f * in any sequence, and if the locus of points at distance < r from a given point is an octagon (with h > 0), then so is the locus of points at distance < s, for any s > r. We assume here and from now on that the border elements of all pictures considered are nonzero, so that the octagons and other figures described are all contained inside the picture. Proposition 11. Let P be a picture resulting from the application o f f , ' s , f2's and f*'s, in any sequence, to a binary picture B in which Bo is a single element. Then unless no JE'S were used, and no fl followed any f * , we have Po -~ O(h, k) for some 0 < h _< k.
Proof." By Proposition 10, as soon as such an octagon is obtained, the following stages are all such octagons. It thus suffices to show that when f2 is applied after any sequence of J]'s and/orf*'s, o r f l is applied after a sequence of (fl's followed b y ) f *'s, the result is such an octagon. But readily, if h f~'s are applied to B followed by k f*'s, the result is congruent to the octagon O(k, h + k) with some of its elements deleted, no two of them horizontally or vertically adjacent (see Fig. 12; all of the missing elements are on the boundary of the octagon if h > 0). Application o f f , then gives the octagon O(k, h + k + 1) with no elements missing, while application off2 similarly gives O(k + 1, h + k + 1).
f*'s
b) One fl followed by four f*'a
555555 a s ~ s a 5 ~ ~ ~ ~ 5
55555 55~5AS~5s55 ~ 3 ~ A 3 Aa
A 2 2 2 a 5 ] I i ~ 5 a 2 0 2 a 5 3 1 1 ~ 5 a 2 2 2 A
55]]2]2]]55 *a22122~a 55331013355 AA22122~ 55332323~55
55~s~s~as55 ~332~3~ 55332123355 A~21OI2AA 553~2123355 S~3233A~
5 3 ~ 3 ~ 5
AA3A3A3AA
55AA3A~AA55
a ~ ~ s ~ 555555
55~5~5A5~55 55555
55~5~5a55 5555
a) Five
c) Two fl's by three
followed f*'a
5555 55~SaSa55
FIG. 12. Results of applying f t ' s followed by f * ' s to a picture containing a single zero (numbers indicate the steps at which elements became zero).
48
A. ROSENFELD a n d J. L. PFALTZ
.99.7..5.33.1 ..9.77.5 ........... 5°77°9° ;Q; 7 ; . 5 . 3 3 . 1 . . 9 . 7 7 . 5 . . ~ J ~5.773~):3-~-
.1.33.5.o7o99.
TJ;5 - i T-g ~ ;.7..5.33.1..9.77.5.. 3 ......... 3. o5.77.9.. 1.33.5..7.c ~/~. ; 5 ~ j : r . - ~ - g - . T ' / r . 3 . - . I j : ~ [ l ~ [ 1-[-1-F[. ~ o . 5 . 7 7 o9 o . 1 . 3 3 . 5 . . 7. '.. 5.33.1..9.77.5.. 3.11 ....... 11.3..$.77.9.. I. 33o5. • ] . 5 . 3~. [ . . 9.77 . 5 . . 3 . [ l . 9099999 , [l. 3 .-.5. ~7.9; 5.33.1..9.77o5..3o l 1.9 ..... o o9. i 1.3..5.7~.9o
.5. ~.1..9.77.5.. 3.11.9.. 5.). 1o9.77o 5. o3.11.9o.7
.-1 . 3 3 . 5 . . . 1.33.5.
~17~7..9.1i. 3 , . 5 . 7 7 , 9, . 1 . 3 . 5 . ..... 7..9.11.3. o 5 . 7 7 . q . 1 . 3 o 5.
5.3.1.9.7.5.3. l 1.9.. 7.55... 55.7..9. il. 3.5.7.9. 1.3.5. 5.3,1.9.7.5. ]. 1.9.. 7.S5. 333,$5.?..9. ~. 3.5.7.9.1-3;5.5.3.1.9.7.5.3.1.9.7.55.3... 3.55.7.g.I. 3.5.7.g. 1.3.5.
5.3.1.9. ?.5.3.1.9. ?.~.3,. |;~. 5. ? . g . l . 3 . 5 . 7 . 9 . 1 - 3 ' ~ - . 5.3.1.9.7.5.3.1.9.7.5.3.1 1.3.5.1.g. 1.3.5.7.9. I. 3.5. .'5.-3;I .~):.~=~F. 1-9 .~/;~..-~'J.~ • 7.9. t • 3.5.7.9.1 . 3.5. .5.3.1.9.7.5.3.1.9.7.55.3... 3.55.7.9.1.3.5.7.9.1.3.5. . 5 . 3 . 1 . ? . 7 . 5 . 3 o 1 . 9 . . 7 . 5 5 . 3 ~ 3 . S5. i . . 9 , i . 3 . 5 . / . g . 1.3.~. ,5.3.1.9.7.5.3. ll.q..7.55...55*7..9.tl.3-5l.g.l.3.5. 5.3.|.~).7.5..3.11.9..1.55555,?..9-I[i~.'5-7-~-[-3-5. .5.3.1.9.77.5. • 3. i 1 . 9 . . 7 . . . . . 7..9. l 1.3.. 5.77.9.1.3.5. - 5 . 3 Z [ ~.~) .1/7-. 5 i . ~ : 1 I ~ r . . ~ 7 7 7 7 7 . • 9 . 1 1 . 3 . . 5 • 7 7 . 0 . . l . 3. ~. 5.33.1.. 9.77.5..3. l L.9 ....... 9 . l L. 3 . . 5 o 7 7 . 9 . o i . 3 3 . 5 . .5.33.1.. 9 . 7 7 . 5 . . 3 . I l - 9 9 9 9 9 9 9 . [ l . ~ . . 5 : 7"t. e)o, i . ~ j ) . 5 . . ' . . 5 . 3 3 . 1 . o 9 . 7 7 . 5 . . 3. I 1. . . . . . . tl. 3..5.77.9.. 1o33.5. • 7..5.33.1..9.77.5..3.1[1111111.~..5.77.g..[.~J~:5.. 7. ;. 7..5.33. I..9, 77.5.. 3 ......... 3. o5.77.9.. 1.33.5.. 7.c ;~F~7o i S . ~ 3 , 1 - . , 9 . 7 7 . 5 . . 3~ 3 3 3 3 3 3 3 . o 5 . - T T . 9 . . 1 • 33 o-~..-~7~. ~ 99.7..5.33.1..9.77.5 ........... 5. ~7.9..1.33.5..7.99, . ,@,@.7 . . q . ~ . . I ° . g . 7 7 . 5 5 5 5 5 5 6 5 5 5 5 . 7 7 . 9 , , o 1~, J 3 - o 5 , , ~ ]
FIG 13 Octagonal distances
(fl,f2,f~
r e p e a t e d ) f r o m a single p o i n t
eo.e
•
t . T~'o 5 . . 3 . . - - I . '-i~o 7 T . 5 . . . . . . . . . . . . . 5oTT.gg.i..3..5. ~'7. ~ 77 • 5 . o 3 . . 1 . 9 ~ o 7 7 . 5 . . 3 3 3 3 3 3 3 3 3 3 3 . . 5 . 7 7 . 9 7 o l o . 3o . 5 . 7 7 '7. b.. 3.. t.99.77.5..~JW; ......... 3..5.77.~.i**3..5.7 '.5.. 3.. 1.99.77.5..3.. tllllllll..3..5.77.99, lo.3..5. 5o . 3 . . I . - , ~ . 7T. 5 . . 3 . . ! . . . . . . . . . I . . 3 . o5.77oC,~, i . . 3o • ~ 5 . 3 . . 1 . 9 9 . 7 7 . 5 • . 3 . . 1.99999999qo I . • 3 . . 5 . 7 7 . 9 9 . I . . 3 o h 5o3oio9o IT. 5.o 3 . . 1.99o 7 7 7 7 7 7 7 . 9 9 o I . o 3. o 5 . 7 7 • g . I . 3.5 5 . 3 . ~ : . ~ 1 . T ' . ~ . - . a 3 ; . t . g e ,r.lP? o . - - . . . T T . 9,~,. i . . 3 . . 5 . ? . c , . i . 3 . 5 ~ 5° 3o t . 9 . 7 . 5 . 3 . . 1 . 9 9 . 7 7 . 5 5 5 5 5 . 1 7 . 4 9 ° I . . 3 . 5 . 7 . 9 . I . 3o~ 5.3.1.9.7.~.3.1.9.77.5..333..5.7r.9. l. 3.5o 7.9.1.3.5 5-.~.I o9. ?oh. ~.t .9. T.~..~o~. 3 . . 5 . T . ~ . ~. 3 . ~ o T o ~ . i . 3° ~r 5.3. l.). 7.b. 3.1.9.7.5° ~.. l.. 3.5.7.9.l. 3.5o7.9.1.3°~ 5 .%. t . ? . 7 . 5 . 3 . t . 9 . ~ . 3 . ) . t - t ~ 3 . ~ , ~ -. g . i ; 3 - . ~ . / ~ . ~ . i . 3 . 5 5°3o 1 . 9 . 7 . 5 ° 3 . 1 . 9 . 7 . 5 . 3 . . [ o . 3 . 5 . 7 o 9 o i • 3 . 5 o 7 . 9 . I o3.5 5.3.1.9. ?.5.3. L.~.7.5.. 5...3..5.i.q.1..~.5. ?.,~. i.3.5: 5.3. 1.9.7.5.3. 1.9.77.5..333..5.77.9.1.3.5. 1.9.L.3.5 5. J . 1 . 9 . ~ . 5 . 3 . I . 9 9 . T T ~ : ~ . 5 . 7 ~ o 9 9 . l . ~ . 5 . i.9.t.~.5 5.3.1.9.7.5.3..1.99.77.55555.77.99. I.. 3.5.7.9. I.3.5
5.3. l.9.77.5.. 3..1,q9.7777777.99.1..3..5.77.9.1.3.5 5. 3.i.-?,-;.77.5..3..1.:i-; ....... :,c,.i.o3..5.7T.9~.i.3.5 5 . 3 . . t . 9 9 . / 7 . 5 . . 3 . . 1.999999999. I . . 3 . . 5 . / 7 . 9 9 . I . . 3 . 5 5 ; .~)-,;-,,-l~.~t~. 77.5-;-.-3..~1-; . . . . . . . . l • . 3 . . 5 o 7 7 . 9 : i . i~,. 3 . . 5 .5.°3.. L.99.77.5.. 3.. II lllllll.. 3..5.77.99.1..3.°5. ~i 57.~o 9 9 • : / L t . 5 . i 3--. • • • . . . . . . . 3..5.7i-.~. i.. 5..5. / T7.5.. 3o. 1o99o 7?.5.. 33333333333. ° 5 o 7 ? . 9 9 o l o o3 o o ~ o T T .T7o b°. 3.. i. ~. 77.5.. • .... ° ..... 5.7T.9~.i..3..5o77° g . 7 7 . b . . 3 ° . l . ) 9 o 7 7 . 5 5 5 5 5 5 5 5 5 5 5 5 5 . 7 7 . 9 9 . l . . 3 o . 5 .T7.9 F I G 14 O c t a g o n a l d i s t a n c e s
(fl,f2,f~,f2,fl
r e p e a t e d ) f r o m a single p o i n t
Distance functionson digitalpictures
49
By Proposition 11, an octagon is the best approximation to a circle which can be obtained by iterating f~, f2 and f * in any sequence, since an octagon is certainly "better" than an octagon with deletions. Clearly any octagon O(h, k) can be obtained using a suitable sequence o f f l ' s and f2's--e.g, k - h fx's followed by h f2's. The (Euclidean)length of the horizontal and vertical sides of O(h, k) is 2h, and the length of its diagonal sides is (k - h)x/2. Thus O(h, k) can never be a perfectly regular octagon, but it can be made to approximate such an octagon arbitrarily closely by taking 2h/(k - I1) to be a good approximation to x/2. The octagons obtained using d4 (i.e. by alternating f l and J2) are not very regular, since for r even their horizontal and vertical sides have length r and their diagonal sides have length (r/2)x/2, while for r odd these lengths are r - 1 and (r+ 1/2),,/2. A more regular octagon can be obtained by repeating a sequence off~'s and j2's in which the ratio of the number ofj~'s to the number off2's is closer to x~" The octagons obtained by repeating the sequence (fl, f2,f~) are shown in Fig. 13; those obtained using the sequence (fl,f2, J l , f z , f l ) are shown in Fig. 14. 4. APPLICATIONS OF DISTANCE F U N C T I O N S The following applications of distance functions illustrate the importance of using functions which approximate Euclidean distance reasonably closely. (a) Cluster detection Let P be a binary picture containing a scattering of O's, some of which are grouped into clusters, as shown by the W's in Fig. 15. Let W ) be the binary picture in which p!~) = 0 if and only if d[(i, j), Po] -< r, where d is a distance function. Let W '~ be the binary picture in which p!~'~ = 0 if and only ifd[(i,j), p~r~] >_ s. We can think o f P ~'~as "expanding" each zero in P into a "disk" of radius r, and of W 's~ as "re-contracting" the set of zeros in P~') by s. In particular, taking s = r, it is clear that the disk in P~') which arises from an isolated zero in P re-contracts into an isolated zero in W 'r~. (In fact, readily P~o~'~ ~_ Po for any r.) On the other hand, if there is a cluster of zeros in P, the expansion process (for sufficiently large r) will "fuse" it into a solid mass of zeros, and the re-contraction will leave a central core of this mass intact. Figures 16-17 show the p~3~ and p~3,3~ which arise from the P of Fig. 15, using the distance function f3. (One clearly wants to use a distance function which is as Euclidean as possible, so that the "closeness" required to define a cluster will not depend strongly on direction.) The clusters which are detected by the foregoing procedure become sparser as r increases. If there is no prior information about expected degrees of sparseness, one can construct P(~") for a range of r's. Any connected component of zeros in P(r") whose area is large compared to r 2 must arise from a cluster of zeros in P. (b) Elongated part detection A procedure exactly "dual" to the foregoing can be used to detect elongated parts of a connected set of z~ros in a binary picture P. Let Qt'~ be the binary picture in which ql~~ = 0 if and or,y if d[(i,j), P - P o ] > r, and let Qt"~ be the binary picture in which qtr,~l = 0 if and only if d[(i,j), Qtd)] < s. In effect, Qtr) contracts the set of zeros in P by r ij steps, and Qt'"' then re-expands the zeros by s steps. Readily, Qg.O ~_ Po for any r; let 0 ~'*~ be the b'nary picture in which ~)~o "''~ = P0-Qg"). Then any connected component of
W W
W
W W
N
W W W
N
W
Fl6. 15. Test picture containing clusters of W's.
W
W
W W W W w
W
W W W
W W W W W
*
e*, e *
,
**
,
*
**
****
** , * * * , * *** # ~( e , e e 8 o • • • , • , o , e • e * • • • , * e * * o • e • • ¢ e * e • • • • x • • e • * e * • • 8 * e * • • • • • e e • * e •
***
* e exee,
,
**
**
**
xe**
,eel,
•
, ,
x
•
**x****
•
,e,
FZG. 16. Hexagonal "expansion" of Fig. 15, three steps.
****
* * * *
*
o*
*
ee* ,
* e * e e * * * * * e e X * e e * * * e e e e e x e e e * * e e e e e e e * e e *
o e e * e e e * e e o *
•
* * * x * * e x * e * * e i x *
*************************** • * *****************************
X * e e * •
re•
se*I°eX *
* *x*e*ee,
* * * x * * *
50
*
•
* * • ,
* * * * * * , ~ , ~ , , e * * e x . * * * ~ , 0 0 1 1 4 . 1 1 . I . I * 0 . I . 1 1 1 . I * + 0 0 . * . 1 1 . . 1 1 1 1 1 1 * * * ~ * * * * * * o O e * * * * * e * e o * t * * e * o X * * * * * i o * *
*
,eee,
•
•
,
* * * *
e
**
.
*°**xeeeee*
*Xeo*X
X
X ************************
*xee*o**lee********
•
X * • • * * * • x,eeeex
• * X
FIG. 17. Hexagonal "recontraction" of Fig. 16, three steps.
X*
**i
X • o o o e O X
,e * * • * * * • • * * * • * X * * X o e * e e e * e e * e e e X e e e e e X
X X
• * * e e
e o * * e * * o * * * * . 0 . * X * * * * * • * * * e e * e e * e e o * e e X
* ~ e e e e e x e e e e e e e e * e e e e • * * e e e e x e e e e e * e e e * * e e e l e o * e e e x e l • X * e e X e * X e * X e e * e e * e * X
X
X
, * * * * , * * e e l , , * * * * e * * e ~ e * e e e x , _ e _ * _ *
x * e e e * e e o e * * * o e e e x * * * * * * e * * e x * e e , e * * * * * * * •
*
X
•
• X
e e e e e e X e e *
•
•
*
X *
*
* *
* *
X e e e o e e * e e e e e* • e * * * X X
Xeleeel • e
X
X
* * * * * X • 0. ** * * * * * e* * X* -
* *
* * * * *
*
* *
• * * *
X * * * * * • ** *
* * •
* •
******,Xee** *
•
•
•
-
*
*
•
*
-
***
FIG. 18. Hexagonal contraction of Fig. 17, one step.
,
*
• *
** ** * * * * e * * * * e , x *
*e
51
*
x
,
* * * x * e e e e . , .
e
X * e * * e x e * e e * * * e * * e * e * * X e e * * * e * * * * l e e * e * * * * *
-
*
*
*
*e*lee*,
e
* * **
x
*
o
****x**
*
x
*
e
e*e****
* * * e * * e * e e e * * * e e e * e x * * e * e * * * e e e e * * * * * e * * *
*-
e
*
* Xe*
-
-
*
52
A. ROSENFELDand J. L. PFALTZ
t'el,lee,X, ,
*
*
,
• *
• •
*
*
*
,x**lle*oe,
, •
*
I
X * * • X * * * * i * i • * X , , , , , , * * , i • * • lee*el
*
• *
* *
• *****ee***e,e, -
,
,
,
*
, •
*
*
* * * X X * I * * , •
* *
•
l*****l
X * •
* •
X
I*,X, X •
*
********x
* * * * * * e * •
,
* * * * * * * e
* * * * * * * * * * X e e * * * * * * x * * * * * * e * * - * * * * * * * * * * * * * e , e *
* * * * * * * * * * X * * * * * * * * * * * * * x * * * * * * * * e * * * * * * * * * * * x * * * e e * x * * * l * * x * * x * * * * e * * e * * * * * * * * * * * e * * e *
*
x
X o * * e * * * * * * * * * * * * X * * * * * * * * * * t * * * * e * e l * * * * x * * * * * * * * • * * * * * * * * * x*****x • ** ** •
FIG. 19. Hexagonal re-expansionof Fig. 18, one step.
zeros in Q~r,r~whose area is large compared to r2 must be elongated, since every point of it is at distance at most r from its complement. [The "duality" of the cluster and elongated part detection procedures can also be expressed as follows : Inside a cluster of O's, the set of l's is everywhere elongated.J Figures 18-19 show the Q(1) and Q(1.~) resulting from the P of Fig. 17, again using f3. (Here too the importance of using a near-Euclidean distance is clear.) Note that this procedure will eventually (as r increases) detect any elongated part of Po, no matter how wide; it does not depend on the elongated parts having a narrow range of widths ("strokes," "tracks" and the like). The contraction/re-expansion process is somewhat analogous to, but simpler and probably more effective than, the "skeleton" process for detecting elongated parts of objects proposed by ROSENFELDand PFALTZ. (x) (c) Regularity detection A process of expansion and re-contraction can also be used to detect "regularity" in a scattering of zeros--i.e, near-constancy of the distances between near neighbors. For
Distance functions on digital pictures
example,
(i,j)
let
rij
r f o r w h i c h n(r,r ,~ij +
be the smallest
constant
a region
in which
~ 0. ( R e a d i l y , ,.~j n ~'''+
"sparseness" < r.)
is i n s i d e a c l u s t e r o f z e r o s o f
Intuitively,
1)
53
rij
We call
the zeros are regularly
distributed
radius of fusion. Such regions can thus be detected
this radius. The radii of fusion for the picture
L
1 1
1-
l
m L
II
l
I - - [ L L
1
l l
I
I
l--
|
L
I 1
II
I
l
-I-l
l
L
l
1
II
l
l
l
I
I
l l
l
l
1
ii
l I
l . . .I . L.
I
1
1 l
II l
l
1 1
l
1
l
It
1
11 t
1 l
l
l
I
-i- . . . . . . . . 1 l 1 l
L 1
l
1 l--|
l
l
l
I
I
1-
II
i n F i g . 21.
I
1
L
a relatively level slicing
l L L . . . . . . . . . . . . 2 .... F l I i I l I I l L LI l I L ....... ~1. L----l t l L l 1 L LL ! l L I I
1
!
will have
by appropriately
in Fig. 20 are shown
1 1 11
1) ~ 0 m e a n s t h a t radius of fusion at (i,j).
the
l l
I
L-T I
L
I
L
I
l
l
l I
I
L
l L I
LL l
t I
L
......
1 I
l
l ll
l
I
I I
I
I t
I
V
1
ll
1
l
1
i-
l
1
I I
I
I
l
---qI
I I
l
I
I
I
1 I
I
II
l I
FIG. 20. Random point pattern.
5. PATH C O U N T I N G In this and the next section we describe other types of functions on a digital picture which depend on distance to a subset. Let S be any subset o f A x A. By a d-path of length r from (i,j) to S, where S is a subset of A x A and d is a distance function, is meant an r + 1-tuple (io,Jo), . . . . (i,,j,) such that (io,Jo) = (i,j); (i,,j,) is in S; and d [ ( i s _ l , j s _ O , ( i s , j~)] = 1, 1 < s < r. For example, if d = dl, each element of a path is a horizontal or vertical neighbor of the preceding
54
A. ROSENFELD and J. L. PFALTZ
3 4 5~35434 33 434 43455 ~555~444344433~222223 43334 54333J4 ~4444444444444332222223~5~43J~333 ~4443335 44444444444444443~222222333333332~ 544443235 444444444444~4-~-~"~r~44)~y31J'3~l~rS"~554444432~ 53444444444444442223444443333332224444444443~225 ~444444444444444~2344444443353~22~444444432~23 54444~44444444442~4444444442Z2~2222444443~22~3 544444444444444~444444444~333~Z~ ~44444444444443~Z~444444444~333333~Z2~ZZ~Z ~4444444444444Z~4444444333JZJ33333333~333~ 5~4444444444442~2444443333~3333~333333~Z333~3~ ~4444444444444~444~333333333~3333~3~333~3~ $~44444444444442~22~2~33~33]~3333333~333~33333b ~4444444444444~444~33~33~33~31~3333~333~'34 ~444444444444444~44444443~333~3~333]~33~3~ ~44444434444444444444444443~33~2~2~333~3~3~b ~44444333444444444444444444J33~£~3~3~3~3~ ~44444434444444443444444444~3~333~$ ~44444444444444~3444444433~2~3~34444~334 ~444~4444444444~J3~44433~33~3334444444443~ ~44444444444444~31333~333~3332~344444444444~2 ~4444~44444~3~3~3~4444444444444
3~55~5432~2333.333322~2~333~23333333333444444t ~543~333333333~3333332~33~333333444443~ 5~555~5543333333~3332333333332~2233~2344444442 ~b5~%~5~444433333333333333333~2~34444444444 ~G~544444333~33333333~333~2~3444444444424 ~55~444333~33333~33~3~222~3444444444443~4 5~5~5555~444333333333333~33~444444444444332 ~5~5~b~443333333333~Z~33333~444444444443333 555~b5~5~5~4335333332~3333334444444444433334 55~5~5~$~333333333~33~33444444444443~334 ~5~5~56333333333332223333444444444333333~ 5~5~5~5433333333333~3333344444444433333~ ~4~5565~43~333333444333~3323344444443333333~ ~445~5~433~333334444433333333344444333333334 ~4445~433333333444444433333333344433333333334 5~444433333~334~5~44333~33334~55653333334 ~5Sb~43333333455~55~544334~5554 ~533534 ~ S333333455 ~434 §5333 ~5 45b ~54
FIG. 21. Radii of ~ s i o n ~ r Fig. 20.
element, so that the path can be regarded as a series of horizontal and vertical "steps." If d = d2, diagonal steps are also allowed ; if d -- d4, they are allowed only at every other step. For d = d3, the path can be regarded as a series of steps on a hexagonal grid. Note that a d-path can cross or even retrace itself repeatedly, and that it may pass through the set S many times. Let Cl be the set of elements (h, k) in the binary picture C such that Chk = 1, and let N~(i, j) be the number of d-paths of length r from (i, j) to C 1 . Let gd be the local operation defined by gd(Cij) =
and let c~ ) be the
~ Cur, d[(u, v), (i,j)]=l
(i,j) element of the picture obtained by applying gd to C r times, i.e. =
~v
d[(u, v), (i, J)l = 1
where ~hk ~o) m e a n s Chk.
,
r
=
1,2 . . . .
,
Distance functions on digital pictures
55
Proposition 12. cl~) = N~r)(i, j). Proof." This is clear for r = 0, since the number of d-paths of length 0 from (i,j) to C1 is 1 if (i,j)e C1, and 0 otherwise. (This is why the set was taken to be C1, rather than Co as in Section 2.) If it is true for r - 1, its truth for r follows from the fact that any path of length r from C1 to (i,j) consists of a path of length r - 1 from C1 to exactly one of the (u, v)'s, together with the step from (u, v) to (i,j). (This argument is valid even if not all of the (u, v)'s are inside the picture.) In short : Repetition of the local operation gd generates a stack of integer-valued pictures C (') -- (eli)), r -- 0, 1. . . . . in which c~]) is the number of d-paths of length r from C1 to (i,j). Knowledge of the number of paths of each length from any point to a given set S is of interest in the following type of situation: Suppose that every point of S has a certain effect on each of its neighbors, and that this effect is transmitted from neighbor to neighbor, with attenuation at each step. Then the total effect at the point (i,j) is given by an expression of the form £a,N('~(i,j), where a, is the magnitude of the effect due to a single point after attenuation along an r-step path. (The transmission of the effect is assumed here to be instantaneous.) Processes of this type have been considered in connection with the study of lateral inhibition in neural networks (e.g. BEDDOES et al.(2)). To get an idea of the convergence properties of ~N(~)(i, j), suppose that S consists of a single point, which we may assume without loss of generality to be (0, 0).
Proposition 13. The number of dr-paths of length r from (0, 0) to (i,j) is N~r)(i,j) =
r-li+jl 2
" r-li-jl 2
,
where the binomial coefficient (r) is defined to be 0 if x is not an integer or is not in the interval [0, r].
Proof: This is evident for r = O; suppose it true for r - 1 . Then by definition of gd, we have ( r - 1 ) ( r - 1 ) ( r - 1 ) ( r - 1 ) N~r)(i,j) =
r-l-[i+j-ll 2
r-l-li-j-ll 2
I r-' If r l
+ r-l-li+j-ll 2
=
r-l-li-j+ll 2
I( r t l r r-l-li+j-ll 2
x
( r - 1 ) ( r-l-li-j-ll 2
+ r-l-li+j+ll 2 r-1 + r-l-li-j+ll 2
+ r-l-li+j+ll 2
(r
+ r-l-li+j+ll 2
t] )1
•
r-l-li-j+ll 2
t( r, 1 r-l-li-j-ll 2
56
A. ROSENFELDand J. L. PFALTZ
The Proposition then follows from the following LEMMA.
a-l-lb+ll 2
+
a-l-lb-lr 2
~=
for all positive integers a and all integers b. Proof." If tb + 11 ~ a - 1 (rood 2), each of these binomial coefficients is zero; we may thus suppose that ( a - 1 ) - I b + 11 = 2k (say). We consider three cases (1) Ifb = 0, then a = 2k+2, and we must show that
k but since
~ k !
k+l!
(2k+1 (2k+l) k
!
k+l
this is just the familiar recurrence relation for the binomial coefficients. (2) If b > 0, we must show that
which is the familiar recurrence relation if k + 1 > 0, and every term of which is zero i f k + l < 0 . (3) If b < 0, we must show that
(a l)(al k
k - 1!
k!
which follows analogously. COROLLARY. Let a, < ( 4 + e ) - ' , where e > 0; then
EarN~')(i,j) converges for all (i,j).
Proof." N~r)(i,j) < 2r2' = 4 r i f r > 0; hence Za,Nt(,(i,j) < Y4,(4+e)_~ = l/( l _ 4 ~ e } _ 4+ee In short" An effect which falls off by a factor of more than 4 at each step has a finite magnitude at any point, even though it is summed over all paths of all possible lengths to the point. Similar results hold for d2-paths and d3-paths. Under some circumstances it may be of interest to consider only d-paths which do not pass through the set C1. Readily, the number of such paths of length r is just -,Jd~'0,where ~J~
=
r~ i~1~ and j ,
d!~~ =
~ d[(u, v), (i, J ) l = 1 cue ~ 1
~,-l~ ,
r = 2, 3....
Distance functions on digital pictures
57
In other words, this number is obtained by omitting from g~, except at its first application, any terms corresponding to elements of Ct. It may also be of interest to count the shortest d-paths from (i,j) to C1, which may be done as follows: Let e!~'= e!~-" --
ife!~-'~ :# 0;
Z d[(u, v ) , ( i , j ) ]
" ('-1' If eij = 0, = 1
where /o) -i~ = c~j. Thus if cij = 1, i.e. (i,j)e C1, we have e!~) = 1 for all r; while if cij = 0, we readily have e!~) = 0 as long as r < d[(i,j), CIJ, and thereafter it has a constant, nonzero value. Since a shortest path from C, to (i,j) is a shortest path from C~ to any point on the path, it follows readily that this constant value is just the desired number of shortest paths. 6. P O I N T C O U N T I N G We next consider the problem of counting the number M~')(i,j) of points (h, k) of the given set S such that d[(i, j), (h, k)] = r. Knowledge of this number is of interest in a situation where each point of S has an effect on other points which depends on their distances from it. The total effect of S on the point (i,j) is then given by an expression of the form ZarMtar)(i,j), where ar is the magnitude of the effect which a single point of S has on a point at distance r from it. It is interesting to note that M~r)(i,j) cannot in general be computed, even for r = 2, by twice iterating any isotropic local operation. To see this, consider the four pictures shown in Fig. 22, where the points of S are indicated by asterisks. Since each of the points @
l)
aa ~ aa .
2) &
•
4)
St
a
a
a
St
&
•
o
a @
FIG. 22. Examples showing that
M~2)(i,j)
cannot in general be computed using isotropic local operations (hexagonal grid).
marked " a " has exactly one neighbor in S, any isotropic Ioca! o p e r a t i o n f m u s t give each of them the same value a. Similarly, the points marked " b " have no neighbors in S, so that f m u s t give each of them the same value b. Thus w h e n f i s applied a second time, the points marked "b" and their six neighbors have the same values in each of the four cases, so that
58
A. ROSENFELD a n d J. L. PFALTZ
the " b " points must again all be given the same value by the second application off. Thus this value cannot be equal to the n u m b e r of points of S at distance 2 from the " b " (since this n u m b e r is different in each case), no matter h o w f i s defined. We now show that Mta')(i,j) can be computed using simple nonisotropic local operations. Let H(')(i,j) = {(i, j - r ) , (i, j + r)} be the set of points at distance r from (i, j)in the horizontal direction. Then readily we have (see Fig. 23)
H(1)(i,j - 1) L~ H(1)(i,j + 1) = H(2)(i,j) w H(°l(i,j)
H(ll(i,j-
I) n
H(LI(i,j+
I) =
H(°)(i,j)
and
H('l(i,j-1) w H(r)(i,j+1) H(')(i,j -
= H ('+ t)(i,j)w H (r- LI(i,j)
I) ~ H(')(i,j + I) = ~b
r = 2, 3 ....
H(1)(i,J-l) = {(i,J-2),(i,j)} H(~)(~,j+~) : ((~,J),(~,j+2)} a (2) (~,J) -- {(~,j-2), (~,j+2)} H(0)(~,J) - {(~,J)} H(r)(i,j-1) =
(i ,J-r-l),
(i, J+r-1))
H(r)(i,j+l) =
{.,j-
H(r+1)(i,j) =
{(i, J-r-l), (i, j+r+l)}
l I,
J+r+l)}
H(r-1)(i,j) = FIG. 23. Verification of the h o r i z o n t a l d i r e c t i o n set recurrence.
Let F be any additive set function, so that F(q~) = 0, and F(A w B) + F(A n B) = F(A) + F(B) for any sets A, B. Since clearly H ('+ ')(i,j) c~ H (r- ')(i,j) = ~b, r = 1, 2 . . . . . we have
F[n(2)(i, j)] = F[n(1)(i, j - 1)] + F[n(1)(i, j + 1)] - 2F[n(°)(i, j)] and
F[Htr+ l)(i,j)] = F[Htrl(i,j_ 1)] +F[Htr)(i,j + 1)] - F[H it- LI(i,j)],
r = 2, 3 , . . .
We thus have an expression for F[Ht'+'I(i,j)] in terms of previously computed F's of (i, j) and its two horizontal neighbors. Since the n u m b e r of elements of a given set S which are in H('I(i, j) is certainly an additive set function, we have thus proved Proposition 14. Let C be a binary picture, and let h!~) be the n u m b e r of elements of C, in {(i,j-r), ( i , j + r)}", thus h~°) ~ cij, and h"-ijILl = C i , j - 1 "Jr-C i , j + 1 • Moreover, we have h!2l -- h!,';- L+ h!~f+ L- 2h!°l, while h{r+l) '-Ij
=
h ~' }j , i . )j-- -• +h];}+ 1 - - h-',-L)
r =2,3,
•••
Using this result, we can now find an expression for the n u m b e r x!~) of elements (h, k) of C, such that dl [(h, k), (i, j)] = r. Let X(')(i, j) be the set of (u, v) such that dl [(u, v), (i, j)] = r.
Distance functions on digital pictures
59
Then readily we have X~')(i- 1,j) to Xt')(i + 1,j) to H ~'+ l~(i,j) = X(,+ 1)(i,j ) to X{, - 1)(i,j); X~')(i-l,j)nXt')(i+l,j)
= H t ' - l )(i, j),
r = 1,2 . . . .
(See Fig. 24, where the elements of X t ' ) ( i - l,j) are indicated by - ' s , and the elements of Xt~)(i+ 1,j) by +'s.) We can now apply any additive set function F to these sets to obtain an expression for F [ X ~+ 1)(i,j)] in terms of F[H ~'+ 1)(i,j)] and previously computed F's of (i,j) and its two vertical neighbors. We thus have
÷÷÷--÷+ -÷ ----
--+÷÷ -- ÷÷ +
-+ +
-_+÷ -- + ÷ ÷÷ ---- ÷ ÷ ÷ ÷ ------+÷÷--m
i
FIG. 24. Case r = 10 of the dt set recurrence.
Proposition 15. Let x!~) be the number of elements (h, k) of C1 such that dl [(h, k), (i,j)] = r. Then (1)
xij
=
c i - 1 ,j -}- ¢ i + 1 , j -{- c i , j - 1 q - c i , j + 1,
and X(r.,s + 1) ~___ x}r) 1 ,J _}_ X}~I
,J __ X!~ -1 ) _~_ h!~ +1 ) _ h!~ -1 ) ,
r = 1,2,...
(Clearly an alternative method of computing x!5) would be to first compute the number v!5~ of elements of C1 at distance r from (i,j) in the vertical direction, using the recurrence V(.r+ 1) = l){r) q_t){r) __u(rtJ I - l,j ~+ 1,j tj 1),
and then to compute =
aid-
1
1 - - .*~j
-- vij
-- ~ij
.,
For the distance function d2, the situation is slightly more complicated (see Fig. 25), but we can analogously prove
_
_
+4-+++++++++ 4-
4-
4-
4-
-
4-
-
4-
-
4-
-
4-
-
4-
-
4-
-
4-
-
4-
-
4-
-
4,
-
4-
-
÷
-
4-
-
4-
-
4- 4- 4- 4- 4- 4- 4- 4- -I- 4- 4-
--
m
FIG. 25. Case r = 5 of the d2 set recurrence.
60
A. ROSENFELDand J. L. PFALTZ
Proposition 16. Let dl~) be the n u m b e r of elements of C 1 in {(i + r,j + r), ( i - r , j - r)} ; then d!O, = Cij,
d(t) ij =
Ci+ 1,j+ 1 q- C i - 1 , j - I~
d}? = t~t+i)1,j+ 1 T± dt*( 1i -)
I ,j - 1 - -
--{o), 2aq
and d!~+') = d!~l j +, + ~ 1 . j - 1
- d!;- 1),
r = 2, 3 . . . .
Proposition 17. Let 61~) be the n u m b e r of d e m e n t s of C1 in { ( i + r , j + r - 1), ( i + r - 1 , j + r ) , ( i - r , j - r + 1), ( i - r + 1 , j - r)} ; then (~(0) u : ~(I) vij = x {I) o,
and ~r+l) v,j =6}~1,j+1 _[_6}r_)1 , j - l - v,~Ir-l) ,i ,
r= 1,2,...
Proposition 18. Let y!5) be the n u m b e r of elements (h, k) of Ct such that da[(h, k), (i,j)] = r. Then ~(i?) :
Cij;
Y l ] ) = Ci - 1 ,j - 1 ~- Ci - 1 ,j "~ Ci - 1 ,J + 1 ~- Ci, 1 - 1 ~- Ci,j + 1 "~- Ci + 1 , j - 1 ~- Ci + 1 ,j "~- Ci + 1 ,j + 1 ;
and y(, +1) = Y,.(,) ±y!~i.j_1_y!~-1)-a-A(,+I) AI').:I(') dl"-2), ij i - 1,j+ 1 T -- v i j v t j - - - - z j - - --tj -
-
r = 1, 2 , . . .
(Here too there is an obvious alternative a p p r o a c h in which the roles of the two diagonal directions are interchanged.) F o r convenience in describing an analogous algorithm for da, we regard it as applying to a hexagonal array, on which we define coordinates using the horizontal and 60 ° directions as axes. We then have (see Fig. 26) ÷ +++
+ + -0 + _ ~0
;+
og
-±0 -+0
-+0 -+0 -+0
- -0 +0 +O + 0 + --00 -+0
-+0 -+0 -+0
-+0
-
++0
0;+
-_
-
0 +
+
+++-
_:~0
0
--°o;;°_ 0++
FIG. 26. Case r = 6 of the d a set recurrence.
Proposition 19. Let z!~) be the n u m b e r of elements (h, k) of C1 such that da[(h, k), (i,j)] = r. Then = "i,j+l T
i--,,j--I +*'i+l,j--Z!; )-Z!;-l)
-~ C i - - r , j - ~ C i , j - - r ~ - C i + r , j + r - ~ -- Ci-r+ 1,j-- Ci,j-r+
--Ci-r+2,j-r+2,
1 --Ci+rr
:
C i , j + r - - i -~-Ci + r - l , j - ~ - C i - r +
1,j-r + 1 --Ci,j+r-2
2, 3 , . . .
l,j-r_
--Ci+r-2,j
1
Distance functions on digital pictures
61
Here the c's can be "computed" by repeated translation of the picture" _,j ~!2) can be computed directly in the same way. (One could also define an analogous algorithm using zlr~ -~r) 1,j+ 1") Evidently, these algorithms have little advantage over direct i , j - 1 , z!~ 1,j, and '~i+ computation of z!~) by repeated ("spiraling") translation of the picture, unless r is very large. The situation is even worse in the case of d4, for which an analogous algorithm would involve at least ten recurrence relations, as well as many single-point "correction terms." ,
Acknowledgement--Most of the work described in this paper was supported by Contract AF 19(628)-5949 with Air Force Cambridge Research Laboratories. The "'path count" and "point count" algorithms were first developed under Contract CST-131 with the National Bureau of Standards.
REFERENCES I. A. ROSENFELDand J. L. PFALTZ,Sequential operations in digital picture processing, J. Assoc. Comp. Mach. 13, 471 (1966). 2. M. P. BEDDOESet aL, Simulation of a visual receptor network, I.E.E.E. Trans. BME-12, 136 (1965).