On the parallel generation of straight digital lines

On the parallel generation of straight digital lines

COMi,u,rl;a (marines .xm) ~M,tm,:ImOCJ,:sm~(~7, (~7-83 (1978) On the Parallel Generation of Straight Digital Lines C A R L O A R C E L L I AND ANTONI...

986KB Sizes 3 Downloads 31 Views

COMi,u,rl;a (marines .xm) ~M,tm,:ImOCJ,:sm~(~7, (~7-83 (1978)

On the Parallel Generation of Straight Digital Lines C A R L O A R C E L L I AND ANTONIO I~'fASS~kROTTI

Laboratorio di Cibernetica del C.N./?., Arco Felice, Araples, Italy

Received July 26, 1976; accepted October 2, 1976 Several prec.edures have been devised to generate straight digital lines; among ethers an algorithm has been proposed in the literature which accomplishesthe generation in a parallel fashion. The main purpose of this paper is to show that the constructeddigital line possesses the chord property, and therefore is really straight. To reach this tom the geometrical properties of the generated digit~flline have been investigated and advantage has been taken of a theory developedin the past Lostudy regular arcs of digital contours. A cmnparison between the performances of the parallel Mg(,rithm and af a sequential one, showing the convenience of the parallel approach, is ~dsoincluded. ]. INTRODUCTION In image processing it is often, of interest to construct straight digital line segments. The generated segments, represented as sequences of digital elements or of codes, possess well-known struetural properties 71-3] and can be profitably employed in severM tasks, e.g., the polygmlal approximation of plane curves [-4] and the eonstruetiml of the convex hull in order to detect concavities in cellular complexes [5, 6]. Frorn a more general point of view an interesting paper recently appeared [7] dealing with a linguistic approach to the generation and the recognition of straight digital lines and deseribing, among other things, a parallel recognition process performed by a polyautomatlm. Among the representations of a straight digital line, for instance [8], the one employing chain encoding [9] is the most widely used. In this paper we will discuss the performance of a parallel algorithln [-10] proposed for the generation of a sequence of chain codes, representing the digitization of a real straight line with given slope. Our main purpose is to prove t h a t the algorithm really does generate a straight digital line. To achieve this goal, we will make use of the theory [-3] developed in the study of regular arcs of digital contours. After proposing a modified version of the parallel algorithm which always constructs regular straight digital lines, we give a hierarchical description, in terms of digital points, both for regular and nonregular straight digital lines and find t h a t the set of digital points obtained possesses the chord property ['2]. Finally, some comments on the computational cost of the parallel algorithm with respect to an optimized sequential one [11] are made and a paraphrased versh:m of the parallel algorithm split into two parts (the first 67 0146-664X/78/0071-0067502.00/0 Copyright, ~ 1978 by Aeademi~ Press, Ine, All rights of reproduction in any form reserved.

ARCELLI AND MASSAI%OTTI

68

extracting the parameters characterizing the line structure, the seemul regarding the generation of the sequence of codes) is also given. 2. ON PREVIOUS I~.ESULTS

Let us consider a bim~ry digital picture, i.e., a finite seL (ff l~ttice points or pairs of integers, where every point p can assume only two states, 0 and 1. We wilt call S the set of points having state 1 and will suppose that S is a digital arc ~12-] obtained from a real straight-line segment by means ()f the standard gridinterseetiou digitization scheme ~9]. In this paper we will mmsider the digitiz'> lions of real straight-line segments fornfing angles differenl; from multiples of 7r/4 with the axis of the abscissas and in particular we will work ia the first octant. This does not cause loss of generality since it can be shown [11-] that the results hold equally in the remaining octants. ]?reemat~ chain el)lies are employed in the folh~wing to represent digital ares and to investigate their structure. As is well km)wn ~t], the eh~fitl (;ode rel)resmfl',~l;iml of' S has the fl~tlowing propert~ies: (i) ig e(mtains eodes of no more than two different values/(it) the t,w() code va,lu('s differ by unity, modul~ 8; (iii) one ()f the code values always occurs singly ,'rod is as uniformly spaced as possil)le mnong codes of the other v:tlue. ()n tlm (~ther hand, frmn a quantitative point ()f view, S is a simple 8-emme(',ted (ligital are which possesses the chord property [2], i.e., for any two 1)(fint.s p, q in N, no point:, behmging to the real straight-line segment joining p with q, exists such t,h.~t its 8-distance, generalized to real arguments, frmn S is greater than or equal to 1. Let us recall here that, given two I)oints with coordinates (i, j) and (h, k), their mutual 8-distance and 4-dlstance are, resI)eeti.vely, defin(,d as (l~ = m a x ( [i - h l, [ j - lcl) a n d d~ = [i - h,I + IJ - k[. We wahl; l;c~ shiny that l~ c(mdition for the straightness of S can 'dso be l'ormulated by emmidm'ing the Imlygmlal line $ constituted by the sequence of chain codes rei)resenting S and by testing whel~her the chord property, in this case involving the 4-dist.ance and the 1)oint;s l~elonging to the polygonal line g, holds. As ,'~ matter of fael; in t~ previ(ms arl;iele [-3] we fom~d that digitM arcs, obtained as suhsets of digital eontom's, arc straight if and only for any two points p, q in S, no real point r belonging t o / ~ exists such that & ( r , g) /> 1. To prove that this property and the chord proI)erty, defined in [2], characterize in an equivalent way the digitization S of a retfl straight-line segment, we will show that for a~ly two pofi~ts p, q in S, i:he following holds : THEORE.~I 1, If

ds(r, S) < 1

Vr E pq

&(r, g) < 1

Vr ~ pq

then

and vice versa. For the proof, see the Appendix. From m)w (m, wo will consider the definition referring to ~ ,'~s ch~raeterizing the digitizations of real straight; lines and will uso the results found in [-3] ~o prove, by means of a s~ruetural .malysis, that the algorithm proposed in [10]

PARALLEL GENERATION

OF STRAIGHT

LINES

69

really constructs a straight digital arc, i.e., a digitization of a real straight-line segment. Let us recall some notions, which can be deduced from [-3], about chain coded digital ares: (1) Any arc, represented by a sequence of codes cl, c~, . . . , c,, with values el such that ei+l -" e~ /> 0 (or e~+1 "- e~ ~< 0) for every i, is defined as 1-monotonic. (2) A 1-monotonic are is a straight digital are if it is represented by (i) a sequence of codes with equal value or (ii) a sequence containing codes with only two different values; one of these values, ~, occurs only once and is placed at the initium (or at the terminus) of the sequence. In the second ease the arc can be represented by an ordered pair of vectors (~, ~.i> (or (~}, ~oI>), where the orientation of g' is the one common to the remaining codes and its modulus h ~ is given by the number of such codes. (3) Given a 1-monotonic arc (~, ~.'} ((~', ~)), the oriented real straight lim~ passing over ~'(~.9 divides the Euclideml pltme into two semiplanes, the positive one '~t its left and the ncgatiw~ one at its right. As a consequence the aro will be called positive or negative, respectively, depending on whether ~(~') lies in the positive or in the negative semiplane. For the sake of simplicity, in the following we will consider, uulcss otherwise stated, only positive arcs. This will not imply loss of generality since the same reasoning can be repeated in the case of negative ares. (4) A sequence of 1-monotonic ares, such that their :~'s and r are equally oriented and the terminus of an arc coincides with the initium of the succeeding arc, constitut~es a 2-n~onotonie arc if and only if the sequence ~.~, ~..?, . . . , ~.,} is l~lOllotonie~ i.e.~ : ~ >/ ~.i+~~, Vi (nenincreasing monotonicity;

briefly ~l = - 1 ) ,

;,~1 ~ ~.~+ 1, Vi (nondecreasing monotonicity; briefly t,1 = +1). (5) A 2-monotonic arc, sequence of ordered pairs (o l, ~}> (<~l, o~>) is said to be 2-regular if and only if u ~ = -{-1 (~ = --1). (6) A 2-regular arc is straight if and only if the following relations among the moduli of the ~Ys, hold: [h~ ~ -

h#l

+

<2

whenn)4,

(1)

[h~~-h,,~[ < 2

when n < 4 .

(2)

]h,~~ - h,~-~ ~]

As a consequence, disregarding the case in which ht ~ = h~~ . . . . . h~~, straight 2-regular arc is such that tither h ~ = h 1 = h~~ . . . . . h~ ~ or h~~ = h~1 . . . . . h,,_~~ = h,, ~ • 1. Let us now indieate by ~ J the :~ with modulus different from the others and consider the resulting vector ~o~ obtained by composing ~1 with its corresponding r ~. 5Ioreover, let us denote by ~.~the vector obtained by composing the remaining pairs (~}, ~oa) and having as modulus h~ the number (n - 1) of such pairs. Then the straight 2-regular arc can be represented by an ordered pair of vectors (~, :~'~)

or (x2, ~>.

70

ARCELLI AND MASSAROTTI

(7) B y the same considerations ~s in (3), positive (and negative) strMght 2-regular ares are introduced by making reference to ~2 and ;~2. Moreover, when a sequence of such arcs in considered, 3-monotonic ares and 3-regular ares are defined in analogy w i t h (4) and (5), respectively. Finally a 3-regular are is straight if and only if relations of the kind shown in (6) hold among the moduli h? of the avys. (8) The same reasoning as above can be repeated for k-regular arcs, k > 3. FurthErmore, it is worthwhile to recall here that, according to the t h e o r y developed in [-3], every positive (negative) s-regular are, 2 ~< s <~ k, is eomposed of (s - 1)-regular ares which are all positive (negative). L e t us now refer to algorithrn 1-10] proposed by Brons to eonstruet a sequence of codes representing the digitization of a real straight line with slope 0 < b/a < 1 and, recalling ~he grid-intersect digitizat, ion scheme, activating and passing ~;hrough two la~ice points : For the sake of simplicity, the origin of an ort, hogonal Cartesian s y s t e m and the point (a, b). Brons started frmn the observatkm t h a t a digital strMghg line must possess, as point(~d out b y Freeman [1], the three structural properti(~s listed at the begimfing of this section and gave a proeedm'e for spacing the come occurring singly as uniformly as possibh-, among ~he remaining codes. On the othm' hand, since the notiot~ of "as unifm'mly as possible" era:mot be fm'mulated in terms of a me'tsurable quantity, the sequence as possible" cannot be formulated in terms of a measurable quantity, the seque, nce of codes constructed by Brons can be regarded as a digitization of a reM straighl; line if and only if it is possible to prove t h a t the polygonal line g, representing the sequence itself, possesses the chord property in tlne sense specified above. The algorithm can be described as follows. Let us reduce, if possible, the slope b/a to an irreducible fraction and call it bo/ao. In t,his w a y the straight digital are joining the origin with (a, b) has a periodic structure and the length of ~ period is given b y the dmmminator a0 of the fraction. Since we work in the first octant, e v e r y period will consist of be codes 1 and ~'0 = (a0 - be) codes 0; moreover, the codes occurring a smaller number of times should be spaced as uniformly as possible among the other codes. This is achieved b y the following reeursive process : (1) (2) (3) (4) (5) (6) (7) (8) (9)

I.et c. = MAX(b., r.) ; call codes occurring c. times C.. L e t t. = MIN(b., r.) ; call codes occurring t. times D., If g = 1, generate the period C.'.D. and stop the program. Calculate n. = E N T I E ~ ( c . / t . ) . Calculate b,+, = c. -- t.n.. Caleulate r.+~ = t, -- b.+,. G e n e r a t e r.+~ subperiods C.',D., eall them B.+,. G e n e r a t e bo+~ subperiods C,~,,,+*D,, call them A, ~-i. Go to step 1.

We will now make some remarks in order both to reach a better insight into the spacing mechanism and to express the algorithm's steps by means of the notation used in [8-]. When to = 1, the constructed digital arc is a 1-monoi:onio arc with the code Do which occurs singly a n d is placed at the end of the sequence

PARALLEL

GENERATION

OF STRAIGHT

LINES

71

of codes, Therefore such an are is of type (;~1, ~t> and, by (2), straight. Conversely if to ~ 1, to = r~ -1- b~ ares are (~btained by coupling every code Do with no and no -5 1 codes Co. Such ares, coded B~ and A~, respectively, are 1-monotonic of type <52, ~ ) and, by (2), straight. The (~}, ~> arcs constructed at s = 0 are positive if a0 and b0 are such that the number of 0 codes is greater than that~ of 1 codes, while they are negative in the opposite ease. For sake of simplicity, in the sequel we will consider positive ares. At ~ = 1, the new codes A1 and B~ are examined and t h a t code occurring a smaller number of times is called Dx, while the remaining code is called C~. Then, if t, = 1, one 2-monotonic arc of t y p e (53, ~ ) , see (6), is constructed; otherwise, if h ~ 1, r~ arcs coded B2 and b2 arcs coded A2, 2-monotonic and of ~ype (;3, ~'-'>, are obtained by coupling every D1 with ~,1 and with n~ + 1 codes C1, respectively. The (3d, ~ ) ares obtained at this processing stage m'e 2-monotonic sequences of ()}, ~o~) ares and, by (5), t h e y are 2-regular if and mdy if ~ = - 1, i.e., the monotonicity of the h~'s is noninereasing. Since the moduli (hVs) satisfy the relation mentioned in (6), in the ease of 2regularity it is assured that the constructed arcs are straight; conversely, if the (~', ~ ) ares are not regular we cannot u s e the theory developed in [-3]. It is now easy to see that ~' = - 1 only if ~'~ < bl ; in fact in this case the last pair (;.~, ~ ) of tl~e sequence of the <~,i1, 6u%l>'sis SUCh thai; l).~'[ = [~.i'l -- 1, and conversely there result;s I~.~r = I~.,.~1 -F 1 when ~', > b~. Moreover, let us note that, since the 2-regularity of the sequence of the (a', ~ ) ' s is assured when the 2-monot o n M t y is noninereasiag, we could always obtain a 2-regular sequence if we considered an ordering (~.~, ~ ) when r, < b~ and an ordering (~,=,~}> when r~ > b~. The same considerations can be repeated for s ) 2; at stage s a certain nmnber of (s -5 1)-monotonic arcs are built up and such arcs are assured ['3] to be straight only if the regularity holds for all the arcs constructed at the preceding stages, i.e., only if r~ < b~ for every i < s. The global process is ~ parallel one in the sense that at every stage the constructed ares are independent (i.e., disconnected) from each other and only at the final stage the digital are, digitization of the given real straight line, is obtained. The c()nstrueti(m processes of a regular arc and of a nonregular are can be seen in Figs. la and lb, respectively. Finally let us note that, except for the last stage, in which it may happen that r, = b, ~ 1, we always have ~', N b,. 3.

REGULAR

CONSTRUCTIONS

We will show how it is possible to modify Brons' algorithm (B.A.) in order to obtain at every stage the construction of regular arcs. Recalling that, at stage s, a number t, of (s + 1)-monotonic arcs Cp,D~ and Cp, +l D~ are constructed by B.A., let us consider one of these arcs, for instance Cp,D,, and express it according to the notation used in [3] :
h,,/ = l~,J +

1

if r. < b~

hi' = h~ . . . . . .

]~,,/ = h J -

i

if ~'~ > b..

and

72

AI%CELLI AND MASSAI%OTTI Input

$=0

0 s 13

01, 021 , 0~1 i

-

__/

0'~1 ~

0~I,(:]I,0|

.~

-

,)

~)

s =l

_

(0~1) ;~ OI

~

:

(01)~ 0~I

_/ _I a
~>'IF

Fro. 1. Pan~llel oons~rucl-ion o~' ~, regular m'c (a) and of ~ nom'egu]ar ~u'c (b).

Moreover, leg us assume t h a t regular ares have always beell built up at the preceding stages. By (5), in the first case (s + 1)-regularity holds, while in the second case, r, > b,, this is assured only if we could construct the sequence D,C~% i.e., (a)~+~, ~J+~). Let us suppose t h a t the latter situation is verified and t h a t we have been abfe to build t. (s -t- 1)-regular sequences of type (~,H-~, X,+~). Then, at the following stage (s q- 1), B.A. will construct t.,+~ sequences of type (~+i, ~,~+i), <(a.+~, ~.~,+~), . . . <~+~, -l~+i~ ((~+l, ~. ,+i), where the relation between the moduli of ;.f+~ and ).~"+~ dei)ends on ~'s+l and b,+l and is the same as in stage s. B y (5), the previous sequence, which can be represented as (X~+2, ~+2), is (s -t- 2) regular if and only if ~+i = + 1 and this happens when r.+~ > b~+~. W h e n this is not the ease, i.e., r~+~ < b,+~, there will result ~"+~ = + 1 (and (s -F 2) regularity will hold) only if we are able to invert the ordering of the sequence. Therefore, while at the initial stage B.A. constructs only ares of type (~', ~o~), which are positive if r0 > bo, e.g., 0001, and negative if r0 < bo, e.g., 1110, at the successive stages the order of the pairs should be allowed to change if regularity is to be assured. At every stage, the generated regular ares are straight and are all positive or all negative depending only on whether the pair <~i, ~ ) is positive or negative. To summarize the above observations, let us consider the processing stage s, h a v i n g at its input r~ codes (~.', ~") and b, codes (~.*', ~o"), where h" = h*" - 1. T h e n the order of the pair (~."+~,(o'+~), to be constructed by a modified version of B.A., will depend b o t h oD the order of the pairs (~J, (o") and on the values of r, and b, ; specifically : (a) (b) (e) (d)

if if if if

(Xs, ~) (~J, ~) ((a~,;J) ((o",~.")

and and and and

r, < r, > ~'~ < r~ >

b~, b,, 1),~, b.~,

then their then then

(~2+t,~"+l), ((a~+i ~+i), ((a.'+1,;..'+1), (~J+~,(o"+").

T() express the above dependence, we will introduce tile function ~(b~ - r~) = -{-1 if b. > % = --1 if b. < r,., and the parameter 7r.; furthermore, we will n mdil'y

73

PARALLEL (?di~NERATION OF STRAIGHT LINES B,A. b y inserting the steps: (3.1) Calculate c~,; (3.2) If s = 0 take rr~ = q-l, otherwise rr, = 7r,_1"~; (8.1) If r~+l = b.+t generate the period A,+tB,+i if rr~ = + 1 period B~+~A~+~ if rr~ = --1 and stop the program;

or the

and by changing steps (7) and (8) as follows: (7) Generate r.~e~ subperiods with order C,~'D, if rr, = + 1 or with order D~C,". if ~r~ -- ~ 1 ; ealI them B.~+I. (8) Generate b~+~ subperiods with order C,"'+~D~ if ~r~ = + 1 or with order D~C~~,+I if Ir~ = - 1 ; call them A,+I. We calt now say that : THEOI~E.~ 2. The modified version of B.A. constructs, at every stage, d,igila~ ares which a~'e regular. For the proof, see the Appendix. lk~foreovcr, since it is a peculiarity of the construction that the relation in (6) among the moduli of the ~.~"'s is always verified, the following holds. COaOLLAI~Y 1. The modified version of B.A. constructs, at every stage, regular digital arcs which are straight. 4. STRAIGItTNI~SS AND BRONS' ALGORITHM In this section We will consider ',1 different representation of a digital are constructed b y B.A. Let us assmne that, at the beginning of the process, all the extremes of the Freeman codes involved in the construction are labeled v0. At the initial stage (s = 0) to ares are produced ; each ~me is represented b y a sequence of equal Freeman codes followed b y a single Freeman code with a different value, Then let us assume that every pair of coincident v0's, belonging to adjacent codes, becomes a single v0, t h a t the vo's placed at the initium and at the terminus of every arc are relabeled v~, and t h a t the vo's in which the codes with different value join each other are relabeled O0's. In addition an oriented straight-line segment, joining the pair of v~'s of every arc, is also introduced and considered as a first-order code (l-code from now on) representing every constructed arc. Generally at a successive stage s, s >/ 1, s-codes with extremes labeled v, are initially considered and t. sequences constituted by such codes are constructed. In every sequence all the s-codes are equal, except the last one, and the extremes of the sequence are relabeled v,+~, wlfile the v~ lying in the joining position is relabeled ~,. lX.loreover, an (s + 1)-code, obtained by considering the oriented straight-line segment joining the pair of v~+~'s, is associated with every sequence (i.e., with every are). Let us note t h a t : (1) as output of the stage s, t, triangles (see Fig. 2) with oriented sides and with vertices v,+~, v~+~, ~ are constructed in correspondence with every sequence of s-codes. All such triangles have one side with equal length

74

ARCELLI A N D

,,~,,:.:,..~

Vs-I

......~ . . . : ~ " ~

~

Vs

MAS,_AI~OI II

i vs

Vs

Vs-I

~

s+l Vs

Vs+l -%,--

J \

s-code %---

~r-

'"

s-code -v

"~s +l

/\

V ---''---/ s-code

.............

/ x----------v--------J

~ S+l

])'m. 2. Sequence, of s-(;odcs muL (s(n'rc,,spomllngposMve {MtmgIc, r~l.I.

and l:he same (:)rio,,lt:~l:i(m (ec~ineiding with t h e s-c.de with diffc,,'ent~ vahuO which will be referred (;(~ as o"+'; am~l:her side, the hmgest;, whioh eorresl>oncls t;o an (s + 1)-code; trod finally a third side which will be referred to as :~+' and is eomp()sed of an i,~teger number h "+' m' (h ~lt 4- 1), wiih h "+' ) 1, of s-ec~des, all equal. (2) Every triangle will l)c: inclieai;ed b y r,l~ and ealh,d positive (negative) depending (m whether the are c(mstitutc~cL by the Se(lueneo. (ff the e(mq)onenl: s-codes, i.e,, the pair (:x.~+~, (o"+'), is positive (negative), (3) Tlm two verti('es V, lm of every triangle r,+, were expressed during i;he previous proe(,ssing sl,~ges as vh, 0 ~ h ~< s; at the succeeding stage (s + 1) the ]al)el ()f evc~ry such vortex (!an further be inereascd (rely it' neither v,+, is placed in a joining position nor v,l~ is internal to the side ~,+2 of the succeeding trim@e r,+,~. (4) Besides the vertices v,+~, v,+,, /),, the only digital points which can be present, if h "+~ > 1, on every r.+~ are v.'s placed on the side )."+L Every pair of successive digil;al points on' ~."+~, the extremes included, and the pair (9,, v,l~), characterizing r are the extremes of s-codes and every one of them constitutes the longest side of a triangle r,. All such r~'s have an equal side ~)" and they all are either positive or negative. (5) Assmning there have been lc processing stages, we will say that the construction performed by B.A. is regular if and only if the triangles ~+~, 0 <~ s <~ lc -- 1, are all positive or all negative; in the opposite case the construetion will be called nonregular. (6) The k-code obtained at the end of the process represents the digital are constructed by B.A.; moreover, the digital points constituting such an arc have been labeled with values ranging from v0 to v~. To prove that the previous arc is the digitization of the given real straight-line segment, it; will be sufficient t:o slmw that the chord I>r(~perty hohls or, equivalently, that there, exisl;s a pair of p'tralM real straighl; lines i)l.v'x~Ci at a mu(;ual distance d,~ < 1 and enclosing all the points of tile digital arc. We inean tha(~ the digital are is enclosed between the two para,llel straight lines if every one ef its l)(fints either lies between or on the t;wo lines. In the case that the c(mstruction i~

P A R A L L E L G E N E R A T I O N OF STI~AIGttT LINES

75

regular, we know from [3"] that tile td)ove condition is satisfied. The two parallel straight lines are obtained in the l'ollowing way. The first is the line passing through the extremes of the digital arc, i.e., the two p()ints vk, and overlapping the /c-code; the second passes through the point r bearing maximum distance from the first line. This maximum distance can be computed, see Theorems 5.1 and 5.2 in ]-3"], in terms of the moduli of the sides o'+~, 0 ~< s ~< k - 1, and, since the condition mentioned in (6), Section 2, is always verified by construction, it is smaller than 1. On the other hand, Mince the arc constructed by B.A. is nat necessarily regular, let us now describe a general procedure to find the two parallel lines. We will denote by {~J,} the set of digital t)oints with the same label s and by a', 0 ~ r ~< k, the spamfing ol' the two parallel straight lines enclosing the set [.Ji=d{vk-~}. hdtialiy the two straight lines coincide, they pass over the /c-cede and enclose the set {v~,}; ~heir corresponding spanning is 60 = 0. The two vk's and 9k-~ constitute the vertices of vk, which is a positive (negative) triangle if, calling the straigh~ line passing over the /c-code, the poin~ ~_~ lies in the negative (positive) semiplane with respect to t. If we now disregard the simple case in which h ~ = 1, then other points vk-, exist on ~.k and, since ~k-~ is a vertex of rk, there results &(va.._l, t) < d,l(t)~_,, i) for every vk-1. As ~t consequence the straight line t, passing through/)k-, and parallel to i encloses, betweml itself and t~ the set {v/,} U {v1~-1}. Furthermore, the spanning ~t is given by (see Fig. 3) : ;L

~i =

b.

a~ = - - ~

wj:

_

oj,~lga -F w=~tga

if rk is positive, if r~ is negative,

where a is the angle between ~ and the x ~txis. Since the same re:tsoning holds for any kind of re, for the sake of simplicity in the following we will assmne that r~ is posibive. Consider the set {v~} (.J {v~_,}; then its elements can all be taken as poiires Ve_l (refer to (3) in this section) so that all can be regarded as vertices of triangles r~_,. Hence when scanning the arc, from the left to the right for instance, we can see that every pair of adjacent

Yl

~k vk

i" a.

0

x

~k

vk-, ~

0

x

t~

T

b.

FIG. 3. Positive (it) ~nd negaUive (b) rk with the corresponding ~i' in case of ordering (~.~,r

ARCEI~LI AND MASSAI[0TTI

76

0

x

Ii'l(L 4. l?c~sit,ion of v'k-,2when t,he rk-~'s are posil,ivo; (.he dots represent, lmhd.s v~,_,~. vk_l's eonsgil;utes the extremes (if the/(rages(; side (thr (k - 1)-code) of a r/r and is c(mneeted, by means of the sides ;.k-, and (~-', I:() the thir(l vertex ~a.-a. For all the r~.._.~'s, the sides (o1'-~ are equal and t;he sides ;~..-1 c()ntain all the l:)oinl;s of the arcs with label v~,._,~.Leg us c(msider the /)k-~ connected thr(mgh (a X''-t [,o ~)/~.-1and call it ~)*a._,,; two possibilities arise: (i) ~)*k-2 lies in the negative semiplane with respeel: t() l~ (i.e., all the "rk-t'S are posi[ive, nee Fig. 4). Then d4(/~'%-,2~i) -- d,j(~)*k_~,h) -F a~, while, the other v~,_,/s l)elonging t~ the same triangle rk-~ have, a sma]ler distance from i, since they are not in a vertex position. More(~ver, the remaining/)~_2's, (me fc~l' e,very rk-1 present in the arc, have a dis(;anee from ~ which, in smalle.r than <1,~(0%_2, i) i in fact they bear the, same dist, ance equal to d4('~*k-,~, Ij) fr()m their eorresp(mding vk_~, but, in turn these last points, being enclosed between Ztrod l~, have a disf,anco from i smaller t h a n 3~. Theret'ore 9%_,~ has a greater distance from t with. rest)e
-~.~~ v ~ Vk-1

V~

......

0

im

x

FIo. 5. Posilion of v**~,~when l,he rk-~'s tU'(~negaLive; ~he dot~ represen~ 1)oinksv/~_~.

PAI{ALLEL G E N E R A T I O N

OF S T R A I G H T LINES

77

(ii) ~%_,., lies iat the lmsitive semiphme with respect to h (i.e., all the rk_t's are negative, see Fig. 5). Then ew~ry ~,_~, being connected (m side ~-1 to a point vk-:, will lie in the posit;ire semiplmze with respect to h. Let us m:w lo:.~k for the v10_~ bearing maximum distance h'om h. Since tim set {v~} U {vk_l} is enclosed between / and l~, this vk-2 will be a point ~a-2, say 9*%_~, connected to a va, which now plays the role of a v~_~, placed on t. In fact, all the remaining G_,'s arc at a smaller distance h'om h, since they are connected to vr;_~'s placed inside the two lines h and f, and also the vk_,a's are at a smaller distance, since they are not in a vertex position. If we call 12 the straight line parallel to ~ and passing through ~9**k ~, then the set {vk} U {vk_~} U {vk_=} is enclosed between t~ and t,,. In this case there results ~2 = ~ + d4(~*%_=, ~) where, to obtain explicitly the second term, reference must be made to (b) almve by substituting ~o~~1 and o~,k-t Let us n(m, assume that the 1)revious reasonil~g holds j thnes, 1 4 j ~ lc - 1, and that two real straight lines t' and t", pm'allel to i and enclosing the set {sly} U {v/~_,} U "'" U {vl~_~}, have been f(mnd. Moreover let t" be the last construc{:ed line (hence t' c()ineides with ~ if the cm~struetion has been regular) and let 8J be dw mutual distance l)etween t' and t". We will take into account the ,~et Iv/,.} U [v/,,_~} U " " U {v~,_j} and will regard all its elements as v~_~-'s. Then we see tim{;, when following the are h'om the left to the right, every pair of successively encountered v~_/s constitutes the extremes of the longest side ((.he (k -- j)-cnde) ,)f ;~ triangle r~-a" and il~ in connected, by means of the sides :Xe-i and ~a~-{ to tile third w;rtex 0k_j_, of sttch a triangle. For all the ra-i's, the sides ~ - ; ~Lre (;qual and the sides Xk-~' e(mtain all the points v~_~_~. Sittcet" is the last cm~stru(',ted line, il~ (;on[,ains a poinl, ~3~_i which, in turn, in a vertex of a r~_j attd is emm('.ele(l, d m m g h ~k-./, be a.nother vertex ~*~-i--.t "[' r~;-s. If' ~%-~-~. lies in the, semiplane. ~:ptmsii-,e, wi/,l~ respecg to t"~ tx~ that un which t' is placed, thm~ the straighl, line t'" passing through. 9%_~-_, encloses between ii;sd[ ~md t' all the v~_a_~'s. This is due t~ the fact that, by construction, all such points arc connected, 1)y means of equal ~o~-~"s, to points v~_~.which are internal to the lines t' and t". Conversely let ~'%-i-~ be on the same semiplane on which t' is placed; then no p . i n t labeled v~_~._, can be present oz~ the opposite semiplaze. Let us now consider the point vh, h > lc - j, present on t' and let it play the role of a vl~_~..To such a point, which is a vertex of a r~_;, another vertex ~*%-i-~ is connected, having by construction maximum distance from t". In fact, calling t'" the straight line passing through ~*%_;._~ and parallel to t', it happens tha% due to the spatial rela.tim~ (involving the same o~-0 between every v~_i and the corresponding ~_~._~, all the remaining va_j_]s remain enclosed between t" and t'". The pair of parallel lines thus found has a spamfing 3>t = W -b a*, where the expression of 5* depends on the kind (positive or negative) of ra_~, according to relations (a) and (b) above. We notice that, if the triangles r~, r~;_,, . . . , re-~ are all of the same kind, the cm~struction is regular. Conversely, let us suppose that this is not true and that at a certain hierarchical level h.,/~ -- j < h < lc, the triangles r~, are for instance negative, while at all the remaining levels the triangles are positive. Recalling now that dm contribution ~+, given by the level h to the total spanning of the

78

ARCI,;I,I,I AN1) MASHAIt()TT[

y

Vh-i

l

~+ Vh

Vh 1

hl

/

0

x

a)

f

Vh-1

b) 0 _ ~ a. x ",,~h Fro. 6. Po,~itive 0~) m~d ]w,~t:iw; (b) rl, wi.t,h (,he ~;m'l'ospomting ~-t-in c~4(;(fl"ord(u'in~ (o ~,, :kh). pair of parallel lines including t,he digita.1 are, is exprutted by ~ r(,lal;ion of I:ype (b) involving ~.J' attd ~/', h't tit consider the modified verti.~l el! B.A. as g(mert~t;ing the arc. Then all of the consh'uc(:ion will be e(Im0 except, at h',vel h,, wlwrc posit, lye rh'S will be constructed. We kn()w tlmt tiffs is ~t(dfieved by inv(,rt, ing I,h(,~ ()r(l(u' between the sides, so thtd; for every rh ~he ()rdering ((0h, a/,} will l)(! e.nsidered instead of (M', (o/'). Bu(; if we 1()()1< at the spanning M in the e~se ()t' an ordering <~oh, M'), refer to Fig. (), we see (~ha~: c. d.

~+ = --wJ' + ~J'tga if -r~ is posi~iv(', ~+ = w/~ - ~J'lgc~ if ~'l, is n(tgative,

so that, since "relation (b) rel~ti()n (e)," it comes out tlmt no chang(; ()f ~-" occurs. Therefore, since the st~me reasoning c.m be re,petd:ed when rh is posit, ire, all the remaining triangles being negative, the, fc)llowing theorem it proved. ---

Tz-mor~m~ 3. Every nonregular digital are with assigned slope generated by B.A. can be enclosed between two parallel real straight lines bearing a mutual distance equal to that of a pair of parallel real straight lines e~closing a regular digital a'rc with the stone slope. Let us now observe that, due to the structural properties of the construction (i.e., condition (0), Section 2, is always satisfied), in the regular ease the spanning

of the two parallel real straight lines is smaller than 1 and, by Theorem 3, this is also true in the nonregular case. Therefore, whichever the kind of ecmstruction performed by B.A., the following holds: COROLLAICu 2. Every digilal arc ge'nerated by B.A. possesses the chord property. 5. COMPUTATIONAL COST

At ~his point it seems interesting to disetlss the eomput~d:im~fl cost of B.A. in comparison with ttmt of a sequential algorithm, As far as we know the seque, nti~fl algorithm proposed by Reggiori V l l ] can. be regarded as (me of the best results

PAI{ALLEL GENIsRAIION (IF STI{AIGHT LINI.....

79

in this field and {,herefore ig will be considered as r(,presentative of the second class. For the sake of simplicity the discussion will be restricted to straight lines with slope bo/ao, with b~, < ao/2, placed in the first half of the first octant; it can be easily verified that, from what was said in the previous sections and in [-llJ, no loss of generality results. Recalling that the digital line to be constructed will be composed of (a0 - b0) codes "0" and b0 codes "1," the Beggiori algorithm takes advantage of the structural hint that the length of a sequence of "0" 's can assume either c)f two values and uses this information to predict the position of the next code "1" in the digital line. Disregarding the generation of the chaiE once the positions ()f the codes " 1 " are known, the algorithm is found to require bo cycles; at every cycle the number of performed operations is constant and independent of the inI)ut data. In the ease ef B.A., we can regard a cycle as consisting (ff the sequence of operations performed between the definitions of t, and t,, ,; initially to = b0 and at, the last cycle atk = 1 is found. The value of t, indicates the m]mber of independene straight-line segments which can be constructed during the successive cycle s + 1, if I, r 1. The ratio t,+~/t~ shows the speed (~f convergence of B.A, ; ill det.ail, since t~H = MIN ( c , - t,n.~, (1 + n , ) t , - c,), t:here results:

(c2 L ij

1+

-

~2

o

Theret'c~re tk ~< (1/2 k) b0 and thc itUlllber of required cycles is given by lc ~< [log2b0]. If we now examiEe the ldnd c)f ot)erati(ms performed by B.A., we see tllat the algm'i~hm can be paral)hrased and split into two parts, Part 1 (refer to Fig. 7) is

)

2 FI('. 7. Procedm'efor sgraigh~-llnesgructm'eidentifical;ion

80

AItCI,]LLI AND MAS,_ARO.['II

E

r

.FTa

Fro. 8. Pro~:edurefor t,he genm't~t,itmof t,he r

in-eoded st,rt~,i~ht,line,

devol:ed to the identification of the hierarchical struet;ure of the line tu be eunstrueted; it consists of the gener'~i:im~ of the secluc:nees of natural numl)ers f0, fl, ...~ f/~ and f]0, gl, . . . , f/t,: frmtt whieh, once: givon I:he initial codes ("0" and "1" itt our ease), it is possible to eonstruet the desired straight line. Pm't 2, roughly corresponding to steps (7) and (8) of B.A, is concerned with the generalion, in a compact: form, of the chain (refer to ]r 8). The l)ehavior cff t,he t~wo parts ean be clarified by the following example. I~et b0 = 14 and r0 = ac~- b0 = 25, then Part 1 c(mstructs the sequences j' and .q as 2, 4:, 2 and 1, 3, 1, respectively; in turn Part 2 generates the ehain ((02i)401) ~ (0'al)'~01, where every ,'~pex indicates the number of times the corresi~onding al'gtltln}nt is repeated. To make a comparison between B.A. and the Reggiori algorithm, disregarding in both eases the part concerning the generation of the chain, we can observe that, while inside every cycle of both algorithms the computational cost can be evaluated as almost the same and as always independent from ehc value of the input data, the number of cycles is bQ in Reggiori algorithm and is at most [log,,bo] in B.A. The advantage of B.A is therefore clear. Moreover, if we want to consider also the part of B.A. devoted to the generation of the chain, we see that, with reference to Fig. 8, the number of cycles is now given by k + 1. As a consequence we can say t h a t the overall generation process, from tile initial sets of "0" and "1" to the explicit compact expression of the chain, is of the order of [-log.,b0].

APPENDIX Proof l

(a)

d~0', ,S') < 1,

v~' E ?~ ~ ddr, ~s) < 1,

vr E N .

Let us consider the squares having verl;iees with integer coordinates and edges of unit length. Then i1; follows from the hypothesis t h a t either r belongs ~o an

PARALI,EL GENI,31~ATION OF STRAIGHT LINES

81

Fro. 9. Case in which the chord p,'operty does not hold. edge of a square, wi~h at least one point of S as extreme or it lies inside a square having, since S is a simple 8-connected are, at most two points of S as vertices. While in the first case the implicatir is clear (iu fact d~(r, S) ) &O', g)), in the seemed ease we must consider two possibilities: (i) Two points of S are vertices. Since g is either an edge or a diagonal of the square, it folh)ws th.'tg the d4 distance frmn 8 of every point inside the square is always smaller than 1. (ii) Only one point of S is a vertex. Let us assume that a point r E exists such that d40', ,g) /> 1 and d~(r, S) < 1. Since r must lie on the dotted triangle shown in Fig. 9, it follows that ~Fq will intersect in a point r t one of the edges n , t eontaining the point of N. But in this ease d~(r', S) = 1, contradicting tlm hypol;hesis, and therefore the hnplie,~tion still holds.

(b)

ddr, ~) < 1,

Vr E N ~ ds(r, S) < 1,

Vr G N.

The validity of the implication can be easily assured on the basis of the d4 and ds definitions. Q.E.D.

Proof T o assure that, at every stage, regular ares are constructed, we will proceed b y induction: (a) s = 1. The input to this stage is constituted by to ordered pairs (~}, o 1} and the output must be t, nonincreasing sequences of such pairs. Therefore, the pair {~.I, o1> corresponding to the code D, must be placed at the beginning of the sequence if h~* = t~* + 1, i.e., if r, > b,, or at the end of the sequence if h~* = h~1 -- 1, i.e., r, < bl. In this way, ~he obtained sequences are represented b y the ordered pairs ((o'2, ).") and (;~2, o~=}, respectively. But in the first ease (r~ > b,) there results ~r, = 7r~'~t = ( + 1 ) . ( - 1 ) = - 1 and in the second case (v~ < b~) there results re, = ( + 1 ) . ( + 1 ) = + 1 , so that the desired ordered pair is always constructed. Let us now suppose that r~ = b= ( = 1) sequences B~. and A.2, with order ().2, ~)2}if re~ -- + 1, and order <~2 ~2) if rrl = - 1, have been generated, Then, to construct a 3-regular final sequence, we should generate a noninereasing

82

ARCEI,I,I AND MASSAR,OTTI

sequence A.,B., if the order is (~-0, o") 'tnd a nondeereasing sequence B,,A~ it' tim order is (~", 52). This is accomplished b y the progrtun step (8.1). (b) 8 = ~. The input; a/; this s~ag'e is composed of L,_.~ n-reguIar sequences of pairs (;~r o ''-t) and e v e r y sequence is represented either b y t h e ordered pair (;~'*, (o~> if r,,_i = -t-1 or b y (6) ", ~.'~) if r , , - i = - 1 . L e t us consider the ~wo cases : (i) (~.", ~)',} and ~r,,_i = + 1 ; thmt the existence of (n + 1)-regularigy al; l;tie o u t p u t of the stage n implies a nmfincre.'tsing ordering mnong the moduli lid' appearing in the sequence to be builb. I f r,, > b,,, this cmMition is satisfied by constructing a pair (o "+~, ;~"+~), since t h e code D,, appearing singly lllttst be placed ag the beginning of the sequence. (Jonversely, if r,, < b,,, D,, m u s t be placed at the end of the sequence, so th'd; a 1)air (~,,+l, o,,+,} is to bc cmlstructed. B u t in l;he first~ case It,, = r,,_i'o',, = (-t-1)' ( - 1 ) = - 1 a n d in the, s(,e(md case r,, = (4-1). ( q - l ) = + 1 , so ~tla~ t.he desired ()rdcred 1)'fir is always c(mstxucl;ed. (ii) (o", ~.") and ~r,,-i = - - 1 ; n o w a mmdom'(!asing re'de,ring amm)g tlie moduli hi" m u s t hold. Hen('.c the code D,, musg 1)e t)htced 'd, the begimfing t~r at the end of the. scque.nc(;, depe~nding on whet, hm' r,, < b,, m' r,, > b,,, so t;hal~ the ordered pairs (~o''+t, a,,-H) and (~."+~, ~,,-H) are resl)ectively lmill, up. 13u[; in l;he Ih'st ease ~r,~ = ~r,,_~.~',, = ( - 1 ) - ( + 1 ) = - 1 and in the see(rod cas~, ~r,, = ( - 1 ) 9 (--1) = -t-1; t:herefore tit(; desired m'dered pair is ahvays const;ruct(,d, Finally let us note that, I:o achieve (n -1- 2)-reguhu'ity wh(m 'r,, ~.~ --- b,, i ~ = 1, w(; mus~ getieral~e a period wlfich is a n(mincreasing (lmndecreasing) sequm~c(; il' the order of the pairs gem, rated at, steps (7), (8) is (a"+~ (o"-H), i.e., if r,, = -1-1 ((~,,-i.l, a"+'), i.e, if r~ = ~ 1 ) . This is obl;ained by cm~structing t,hc sequence zl,,llB,,t., ill ~r,, = -t-1 and the sequence B,,+ld,, I., it' ~-,, = - 1 . Q.E.D. ACKNOWLEI.)(JM I:,NTS Helpful discussions with A. Maggiolo arc gratefully acknowledged. T h e atithors are also indebted to Mrs. M. Iszo for preparing the manuseripl; a n d to Mr. U. Cascini for drawing the illustrations. REFERENCES 1. H. Freeman, Beundary encoding and processing, in Picture Processing and Psychopic,torics (B. S. Lipkin and A. i~osenfeld, Eds.), pp. 241-263. Academic Press, New York, 1970. 2. A. Rosenfeld, Digital straight line segments~ IEEE Trans. Computers C-23, 1974~ 1264-1269. 3. C. Arcelli and A. Massarotti, I~egular m'cs i~l digital contmu's, Computer Graphics Image Processing 4, 1975, 339-360. Erra,ttmb 5, 1976, 289. 4. U. l~mner, All iterative procedure for t,he polygonal ~q)proxlmat.icm of t)]'um mtrves, Compeller Graphics [re,age I)rocessh~g 1, 1972, 244-256.

5. D. l~u~ovitz, An algorithm fro"in-line gener~tkm of a cmivex cover, 6'omp~der Graphh:s Image Processing 4, 1975, 74-78. 6. J. Sldansky, MetL~uring concavit.y Oll t~ reebtmguh~r mosMc, IEEE Trans. Compulers C-21, 1972, 1355-11]{}5. 7. J. RoUhs~ein ~md C. Weimmb ParMlel mM sequeni, ial specification of t~ emfi,exl, scnsii.ive hmguage for s~raighg liae.~ on grids, Computer Graphics Image Processing 5, 197(i, 106-t24.

PAItALLEL GENE[~ATION OF STRAIGHT LINES

83

8. G. Bongiov'mni, F. Luccio, and A. Zorat, The discrete equation1 of the straigh~ line, IEEE Trans. Computers C-24, 1975, 310-313. 9. I-L Freeman, On the encodittg (~[ arbit.rary geometric e(m[igurati(Jns, IRE Trans. Electron. Compul. EC-10~ 1961, 2{}0-2(i8. ] 0. R. Brons, Linguist.it methods for the description of a straight line on a grid, Computer Graphics Image Processing 3, 1974, 48-62. It. G. B. Reggi~)ri, Digital Computer Transformation for Irregular Line Drawings~ Technical Report 403-22, New York University, 1972. 12. A. Rosenfeld, Arcs and curves ill digitM pictures, J. Assoc. Comput. Mach. 20, 1973~ 81-87.