January1995
Pattern Recognition Letters Pattern Recognition Letters 16 ( 1995 ) 97-104
El .~EVIER
A coding scheme for certain sets of digital curves Jovi~a 7,uni6 Faculty of Engineering, Institutefor Applied Basic Disciplines, Trg D. Obradovi?a6, 21000 Novi Sad, Serbia Received 8 July 1994; revised 31 August 1994
Abstract
In this paper we develop a coding scheme for sets of digital curves. We show that if a set consists of digital curves whose "'original curves" are graphs of continuous functions, having at most two intersection points, pairwise, on a given interval, then they can be uniquely coded by five parameters. Keywords: Images; Vision; Digital geometry; Coding scheme 1. Introduction
A digital curve is defined to be the result of subjecting a continuous curve to a particular digitization process. The continuous curve l will be digitized by the digitizing method in which the first digital points (points with integer coordinates, often referred to as pixels) below the curve l are taken. Obviously, this is equivalent to translating the curve ! by - 0.5 and rounding. So, if a continuous curve l is given by the equation y = f ( x ) , then the associated set of digital points for the curve l, called a digital curve is defined by L(I) = {i, [ f ( i ) J ) , i is an integer}, where LkJ is the largest integer not greater than k. In general, we will be dealing with finite subsets of digital curves, or more precisely, with digital arcs which are obtained by digitizing parts of curves lying between lines x = x ~ and x = x2 for some numbers xl and x2. Also, we can assume that Xl and x2 are integers. If xl = k and x 2 = k + n - 1 then, for the given curve l, the digital arc Ln(l, k) is defined as L,(I, k) = {(i, Lf(i)J), i=k, k + 1, ..., k + n - 1} ={(i, y,), i=k, k + 1, ..., k + n - 1}, where n is the n u m b e r of digital points in the digital arc Ln(l, k) (n is called the length of the digital arc L,(I, k) ) and yi=Lf(i)J, for i=k, ..., k + n - 1. Let us mention that obviously there are infinitely m a n y continuous functions y = h (x), whose digitizations yield the same digital arc. It is enough for the equalities Yi= Lf( i)J = Lh (i)J (for i=k, ..., k + n - I ) to be satisfied. One of the earliest problems considered in pattern recognition was the representation of the sets of digital (lattice) points which result from digitizing straight lines or line segments (Rosenfeld, 1974; Bongiovanni et al., 1975; Klassman, 1975; Arcelli and Masarotti, 1978). An analogous study for circles has also been carried 0167-8655/95/$09.50 © 1995 Elsevier Science B.V. All rights reserved SSDI 0167-8655 (94) 00079-4
J. Zuni6 / Pattern Recognition Letters 16 (1995) 97-104
98
out (Nakamura and Aizawa, 1984; Kim, 1984; Sauer, 1993 ). Similar problems have been of interest to number theorists and in fact some of the results date back to the time of Bernoulli (Graham et al., 1978; Boshernitzan and Fraenkel, 1981, 1984). The major contribution of this paper is to give a parametrization (coding scheme) for sets of digital arcs which can be inscribed into an integer grid of a given size, say m × n. Such representations already exist for the set of digital straight line segments (Dorst and Smeulders, 1984; Lindenbaum and Koplowitz, 1991; Melter et al. 1993). The basic motivation for this paper is to give a coding scheme, for a set of digital curves on the m × n grid, which is independent of the kind of curve being coded. Out first requirement is that for the digitized curve l there exists a continuous function y=f(x), such that the curve l is the graph of this function. If a curve, which is not the graph of a function, is to be digitized, then the curve must be separated into several arcs which satisfy the requirement. For example, the implicitly given circle ( x - a ) 2 + ( y _ b)2= r 2 will be represented as the union of two arcs, called half-circles: y2yl= b + x / r 2 - ( x - a ) 2 f o r x s [a-r, a+r] ,
= b - x / r 2 - ( x - a ) 2 forx~[a-r,a+r], while the hyperbola y = a~ ( x - b ) + c will be described as the union of two hyperbolic arcs:
yl=~_b+C
forxs(-m,
b) ,
a
Y2
~2--b_b+C f o r x e ( b , oo).
Let us mention that, as a consequence of this requirement, a digital arc does not contain two points with the same abscissa. The family of sets of digital curves (which are inscribed into m X n integer grid), for which the proposed coding scheme can be applied will be denoted by din. In particular the family ~,~ contains previously studied sets of digital curves: the set of digital straight line segments (Sin), the set of digital half-circles (Cm), as well as, other, frequently encountered, digital curves: the set of digital hyperbolic arcs (Hm), the set of digital parabolas (Pro), the set of logarithmic curves (Lm), the set of exponential curves (Era), etc. In addition the family dm also contains unions of these sets.
2. Coding scheme We first give two conditions which the sets from the family dm must satisfy (a) A set Am from the family ~¢,~is a set containing only digitization of curves, which are the graphs of continuous functions y=f(x) for x~ [0, m - 1 ]. (b) If I and h are two curves whose digitizations belong to a set Am from ~¢m, then they have at most two intersection points on the interval [ 0, m - 1 ]. It is easy to conclude, that for any integer m, the family dm is not empty. The sets from Mm, which are the most interesting for practical reasons, are the set Sm containing digitized straight line segments y = a x + b, the set Cm containing digitized half-circles Yl = b + x/r 2 - ( x - a) 2 and Y2 = b - x/r 2 - ( x - a) 2, the set Hm containing digitized hyperbolic arcs y = a~ ( x - b ) + c, the set Pm containing digitized parabolic arcs y = ax2+ bc + c, the set Lm containing digitized logarithmic arcs y = logp(x+ ¢t ) and the Em containing digitized exponential arcs y = a x+b. We continue with an auxiliary lemma.
J. Zuni~ / PatternRecognitionLetters 16 (1995) 97-104
99
Lemma 1. Let a sequence of nonnegative numbers satisfying 0~
and a~ + a 2 +...+a n = b l +b2 +'"+bn
be given and let ~( x ) be either a strictly convex function or a strictly concave function, which has a second derivative on the interval [at, a~ ] . Then ~(a,) +~9(a2) +'"+~o(an) # ~ ( bt ) +~(b2) +'"+~(bn) • Proof. Let us suppose that rp(x) is a strictly convex function having a second derivative on the interval [al, an], i.e. ~" (x) > 0. This means that ~' (x) is a strictly m o n o t o n e increasing function on the same interval. Lagrange's theorem implies that
~( a,) - ¢ ( b~) =~' (F.i)( a , - b , ) for some el from the interval (a~, bi) for i = 1 , ..., t and from the interval (b,, a~) for i = t + l , ~(ej) = m a x { ~ ' (el), ~' (e2), ..., ¢' (et)}, then ¢' (ej) < ~' (e~), for v= t + 1, ..., n. This gives
..., n. If
~( bl ) - q~(at ) + ~( b2 ) - ~( a2 ) + ""+ ¢( b,) - ~( at) = ~ ' (e,) (bt - a t ) +rp' (e2) (b2 - a 2 ) + ' " + q¢ (et) (b, - a , ) ~< (bl - a t +b2 - a 2 +'"+bt -at)~o' (ej) = (a,+l -bt+t +at+2 -bt+2 +'"+a~-bn)~' (ej) < (a,+l -bt+t )~' (et+i)+ (at+2 -bt+2)tP' (~t+2)q-
"'" "Ji-
(an -bn)q¢ (en)
= q~(at+ 1) - q T ( b t + 1) + ~ ( a t + 2 ) - ~ ( b t + 2 ) + " " + q~(an) - tp(bn),
which completes the proof, in the case of the convexity of the function q~(x). Iftp(x) is a concave function, then the proof is analogous. []
Remark. From the p r o o f of the previous l e m m a it follows easily that: ~"(x)>0
= ~(al)+"'+~(an)>~(bt)+'"+~(bn)
~"(x)<0
=~ ~ ( a t ) + " . + ~ ( a , ) < ~ ( b l ) + . . . + ~ ( b n )
and
(the conditions of the previous l e m m a are assumed). Now, we can code the digital curves from a set of the family ~'m- Let A m be a set from the family ~¢m and let y=q~(x) be a strictly convex (concave) function on the interval [0, m - 1 ]. Then a digital arc Ln(/, k) = { (i, y,), i = k, k + 1, ..., k + n - 1 }, which is obtained by digitizing the curve/, which is the graph of the function y = f ( x ) , (i.e. y~= I f ( i)/, for i = k, k + 1, ..., k + n - 1 ), will be coded by five parameters (n, k, a, b, c), where • n is the n u m b e r of digital points of the digital arc Ln(l, k); • k is the abscissa of the left point of the digital arc L,(I, k); while the parameters a, b, c are given by "~k+n--I ~k+n-IIU C~i]. • tz=/--,i=k Yi = i=k ~, ..J,
t~ X'k+n--l" Zk+n--lil Cti~l. lyi= i=k U ~ Id~
• v=.~i=k • C = ~ k ,=k +n-
__~k+ n-I lq~(i)Y,-i=k
~(i)Lf(i)J.
1O0
J.Z.uni( / Pattern Recognition Letters 16 (I 995) 97-104
(Note: k+ n - 1 ~
Theorem 1. Let ~o( x ) be a strictly convex (concave) function having a second derivative on the interval [ 0, m - 1 ] and let Ln(p, k ) = { ( i , y~ ), i = k, k + l ..... k + n - l } and L~( q, t ) = { ( i , y; ), i= t, t+ 1, ..., t + s - 1 } be digital arcs, having the given codes (n, k, al, bl, Cl ) and ( s, t, a2, bE, C2), respectively. Then L.(p,k)=L~(q,t)
~
(n=sandk=tanda~=b~
andbl=b2andc~=c2).
Proof. The direction (n =s and k= t and al =bl and bl = b2 and cl =c2)
Ln(p, k) =Ls(q, t) ~
follows from the definition. The opposite direction will be proved by contradiction. Suppose that the digital arcs Ln(p, k) and Ls(q, t) are obtained by digitization of the arcs p and q, which are the graphs of the functions y = f ( x ) and y = g ( x ) , respectively, i.e. y~=Lf(i)J, for i = k , .... k + n - 1 and y; = Lg(i)J for i = t ..... t + s - 1. We start with an interpretation of the sums k+ n-- I
E
k+ n-- 1
[f(i)J,
i=k
k+ n-- 1
E
i[.f(i)J and
E
i=k
~0(i)[f(i)J,
i=k
which appear in the proposed code. For convenience and without loss of generality, we can assume that yi>0 for i = k , ..., k + n - 1 and y j > 0 for j = t , ..., t + s - 1 , otherwise a translation by -mink~k+~_ 1, t~j~t+s-1 {Y~,~, 0} in the vertical direction can be applied. ~tk .Ct x1~~ ~ k+,1,Y i - is the number of digital points below the digitized arc and above the x-axis; • v " ~ ik+,=k ]\ i 1 i=k ki = +kn - - 1 i IL J~cl • ~ iXl 1 1 ~ y k+ i = k n - - 1 iy i -- can be understood as the sum of the abscissas of all digital points lying between the digitized arc and the x-axis; is the sum of the values of the function ~0(x) at all digital points lying • ~k+n-~,,tixl i=k W ~ ) L J4"¢ixl ~ ) l ~ Y~+~-l~o(i)yi between the digitized arc and the x-axis, where {(i, [f(i)J), i = k , ..., k + n - 1} ={(i, y~), i = k , ..., k + n - 1} is the digital arc obtained by digitizing the graph of the function y = f ( x ) . On the contrary, let us assume that there exist two different digital arcs L , ( p , k) =((i, Lf(i).], i = k , ..., k + n -
1)
and
Ls(q, t) ={(i, ~g(i)J), i=t, ..., t + s - 1},
and that the associated codes, (n, k, a~, bl, c~) and (s, t, a2, b2, c2) are equal. From the equalities of the given codes we have n = s and k= t, as well as k+n--I
a~=
~
k+n--I
If(i)/=
i=k k+n--I
bl=
E i=k
~
~ i=k
(1)
k+n--l
i[f(i)~=
~
i[g(i)l=b2,
(2)
i=k
k+n--1
Cl=
Lg(i)~=a2,
i=k
k+n--I
~0(i)[f(i)/=
~
~o(i)~g(i)J=c2.
i= k
We consider three different cases.
(3)
J. ~unid / PatternRecognitionLetters 16 (1995) 97-104
101
Case 1. I f the curves p and q do not have an intersection point on the interval [0, m - 1 ] and yield different digital arcs, it follows that there is a digital point between them, with the abscissa belonging to the interval [0, m - 1 ], but this contradicts ( 1 ). Case 2. The curves p and q have one intersection point on the interval [0, m - 1 ] and they give different digital arcs. If we assume f ( 0 ) >/g(0), it follows that in the area A' below the curve p and above the curve q there is at most one digital point (with abscissa belonging to [0, m - 1 ] ), as well as that there is at most one digital point belonging to the area A" above the curve p and below the curve q. From ( 1 ) it follows that the n u m b e r of digital points inside the areas A' and A" is the same. But this is a k+n--I • contradiction to (2). Namely, the part of the sum 5~k+~-1 i[f(i)J and the part of the sum Zi=k tLg(t)J, both taken over all digital points belonging to the area below both curves p and q and above the x-axis, coincide, since the part of the sum 57~ + ~ - l i [ f ( i ) J taken over all digital points from the area A' is strictly less than the part of k+n--1 the sum 57;=k l• ~ ( l ) J taken over all digital points from the area A" (see the interpretation which is given above). Case 3. I f the curves p and q have two intersection points on the interval [0, m - 1 ] and they yield two different digital arcs, and if f ( 0 ) >t g ( 0 ) , then, because of the condition ( 1 ), the numbers of points belonging to the area A' below the curve p and above the curve q and to the area A" below the curve q and above the curve p are the same. If this n u m b e r is u, let us denote the abscissas of the points from A' by a~, a2, ..., au and analogously, the abscissas of the points from A" by bl, b2, ..., bu. From (2) and (3) and the hypothesis, it is easy to conclude that O<~al <~...<~aj
a~ +"'+au =b~ +'"+bu and ~(a, ) + - . . + ~o(a,) = ~o(b, ) +--. +~o(bu), are satisfied, for some j, but this contradicts L e m m a 1.
[]
3. Comments and generalizations In the previous section we gave a coding scheme for a set of digital arcs of various kinds. The proposed code consists of five parameters. Four of them are strictly determined, while the fifth one can be chosen in several ways. Namely, the fifth parameter in the proposed code of the digital arc Ln(l, k), obtained by digitizing the graph of a function y = f ( x ) , can be calculated as 57k+ff-1 ~0(i)[f(i)J, where ~0(x) is an arbitrary strictly convex (concave) function on the interval [0, k + n - 1 ]. Such functions are: y = x " (for o~# 0 and a # 1 ), y = logp(x + 1 ), y = a ~, y = a r c t a n x, etc. So, the function ~0(x) can be chosen by practical reasons. Example. Let three curves l, h and t be given by the equations y = e x, y = 2 + s i n x and y = n x - 2 . 7 respectively. Let us consider three digital arcs:
LT(l,O)={(O, 1), ( 1 , 2 ) , (2, 7), (3, 20), (4, 54), (5, 148), ( 6 , 4 0 3 ) } , L7(h, 0 ) = { ( 0 , 2), (1, 2), (2, 2), (3, 2), (4, 1), (5, 1), (6, 1)},
Ls(t, 1 ) - - { ( 1 , 0), (2, 3), (3, 6), (4, 9), (5, 13)}, which determine a set A7 from the family ~v. - If the function ~o(x) from Theorem 1 is chosen to be equal to x 2 then the digital arcs from the set A7 are
J. Zuni6 / Pattern Recognition Letters 16 (1995) 97-104
102
coded in the following way: L7(l, O) as (7, O, 635, 3450, 19282); L7(h, O) as (7, O, 11, 27, 105) and Ls(t, 1 ) as (5, 1, 31,125, 535). - If ca(x) is chosen (more suitable) to be equal to x 2 - 1 l x + 3 0 , then L7(l, 0), L7(h, 0) and Ls(t, 1 ) are coded by: (7, 0, 635, 3450, 382), (7, 0, l l , 27, 138) and (5, 1, 31,125, 90), respectively. The key statement, which permits this kind of representation for digital arcs, is Lemma 1. It would be of interest to characterize those functions which can replace the strictly convex (concave) functions in the hypothesis. A more general coding scheme can be derived from the following observation: if a sequence of integers
O<~al <~a2<<.."<~at
~u(a,) + v ( a : ) +...+ g/(an) = v(bl ) + ~u(b2) +"" + g(bn) implies that
ca(a, )+ca(a:) +... +ca(an) ~ ca(bl ) +ca(b:) +'"+ca(bn), what are the characterizations of the functions ca(x) and ¥ ( x ) ? A partial answer is given by the following lemma. Lemma 2. Let a sequence of nonnegative numbers satisfying
O<~al <~a2<~..'~at
implies ca(al) +ca(a:) +'"+ca(an) #: q~(bl ) +ca(b:) + "'+ca(bn) • Proof. Let us assume that ~0(x) and g ( x ) are convex functions. It follows from the hypothesis that ca' ( x ) / v ' (x) is an increasing function, since ca' (x) < 0, ~u' (x) > 0, ca" (x) > 0 and ~u" (x) > 0 implies that
( ¢ (x) ~'= ¢' (x) ~' (x) - ~' (x)~," (x) ~' (x)/ ~,,2(x) > 0. By Cauchy's theorem
~(ai)-ca(bg) ca' (ei) q/(a,)-~u(bl) - q/(e,) for some ei from the interval (a~, b~) for i = l, ..., t and from the interval (b~, a~) for i = t + 1, ..., n. If
¢(~j)
~¢(~,)
ca'(~,)~,
g/, (gj), =max (g/, (el) ' "'" ~ )
then ca' (ej)/g/' (ej)
ca' (el)1) ( g(bl ) -- ~u(a~ ) ) + ~ca' (e2) (~U(b2 ) - q/(a2 ) ) + "" + ~ca' (et) ( ~ ( b t ) - g ( a t ) )
-- ~b d-(e
103
£ Zuni#/Pattern Recognition Letters 16 (1995) 97-104
( ~ ( b l ) -- ¢/(a~ ) + ~'(b2) - ~/(a2) + "'"+ ~/(b,) - ~u(a,) ) - -
= (~u(a,+,) - ~ ( b , + , ) + ¢/(at+2) - ¢/(bt+2) +.-. + ~/(a~) - ~u(b,) ) ~v' (eft
e'(e.)
~' (~t+~) (~'+~) + (~(a,+2) - ~u(b,+2) ) ~,, ~" (~'+~) (~,+2) +...+ (~(a,,)-~u(b,,)) ~,, ( ~ ) < (e'(a,+,)- ~'(b,+,)) ~' = ~a(a,+, ) -{a(b,+, ) + {a(a,+2) - e(b,+2) + . . - + {o(a,) - ~a(b~), which completes the p r o o f in the case of the convexity of the functions (a(x) and ~ ( x ) . If {a(x) and V(x) are concave functions, then the p r o o f is analogous. [] Thus one can use the following coding scheme for the sets from the family ~¢,n.
Theorem 2. Let Am be a set from the family dm and let (a(x ) and ~( x ) be strictly convex (concave) functions. I f {a(x) is a decreasing function and ~/(x) is an increasing function and the second derivatives {a" (x) and ~" (x) exist on the interval [0, m - 1 ], then any digital arc Ln(p, k) = { ( i, Yi), i=k, ..., k+ n - 1} (which is obtained by digitization of the graph of some function y= f (x ) ) from the set A m c a n be coded uniquely by the code ( n, k, a, b, c ), where • n is the number of the digital points of the digital arc Ln (l, k); • k is the abscissa value of the left point of the digital arc L~ (1, k); while the parameters a, b, c are given by • a - - ~ k + n - I t fli'~ 1__~Tk+n--l,, . i=k L.l~,~ld--z~i=k Yi,
k+~-l,,,li~l ai~l • b=~'i= k ~t, )LJ~ 13 = ~k+~-l,,,li~, i=k tll~ )Yi,. • C = Z ki=k + n - I v~ ,,tiXlJu~ CtiX! j j = Y i =k+n--I k ¢ ( l •) y i . Proof. The p r o • f is analogous to the p r o • f of Theorem 1.
[]
As a consequence of the previous theorem, it follows that two parameters of the proposed code can be modified by the choice of certain functions. Another problem, for further research, is to find a coding scheme for the family '~m of sets of digital curves which have n points of intersections with n > 2, on the interval [0, m - 1 ].
Acknowledgement The author is grateful to Professor Dragan Acketa for improving the proof of L e m m a 1 and for helpful comments and discussions.
References Arcelli, C. and A. Masarotti (1978). On the parallel generation of straight digital lines. Computer Graphics and Image Processing 7, 6783. Bongiovanni, G., F. Luccio and A. Zurat (1975). The discrete equation of a straight line. IEEE Trans. Comput. 24, 310-313. Boshernitzan, M. and A.S. Fraenkel ( 1981 ). Nonhomogeneous spectra of numbers. Discrete Math. 34, 325-327. Boshernitzan, M. and A.S. Fraenkel (1984). A linear algorithm for nonhomogeneous spectra of numbers. J. Algorithms 5, 187-198. Dorst, L. and A.W.M. Smeulders (1984). Discrete representation of straight lines, IEEE Trans. Pattern Anal. Machine Intell. 6, 450463.
104
J. ~uni6 / Pattern Recognition Letters 16 (1995) 97-104
Graham, R.L., S. Lin and C.-S. Lin (1978). Spectra of numbers. Math. Magazine 51,174-176. Kim, C.E. (1984). Digital disks. IEEE Trans. PatternAnal. Machine Intell. 6, 372-374. Klassman, H. ( 1975 ). Some aspects of the accuracy of the approximated position of a straight line on a square grid. Computer Graphics and lmage Processing4, 225-235. Lindenbaum, M. and J. Kopiowitz ( 1991 ). A new parametrization of digital straight lines. IEEE Trans. Pattern. Anal Machine lntell. 13 (4) 847-852. Melter, R.A., I. Stojmenovi6 and J. Zuni6 (1993). A new characterization of digital lines by least square fits. Pattern Recognition Lett. 14, 83-88. Nakamura, A. and K. Aizawa (1984). Digital circles. Computer Vision, Graphics, and Image Processing26, 242-255. Rosenfeld, A. (1974). Digital straight line segments. IEEE Trans. Comput. 23, 1264-1269. Sauer, P. ( 1993 ). On the recognition of digital circles in linear time. Computational Geometry: Theoryand Applications 2, 287-302.