Linear quadtrees: A blocking technique for contour filling

Linear quadtrees: A blocking technique for contour filling

0031 3203/84 $3.0O+ .00 Pergamon Press Ltd. 1984 Pattern Recognition Society I',mcrn Rcc,,!lmti,m Vol. 17. N~*. 3. pp. 285 293. 1984. Prinled in Grea...

618KB Sizes 4 Downloads 51 Views

0031 3203/84 $3.0O+ .00 Pergamon Press Ltd. 1984 Pattern Recognition Society

I',mcrn Rcc,,!lmti,m Vol. 17. N~*. 3. pp. 285 293. 1984. Prinled in Great Britain.

LINEAR QUADTREES: A BLOCKING TECHNIQUE FOR CONTOUR FILLING* I. GARGANTINI'I"and H. H. ATKINSON Department of Computer Science, The University of Western Ontario, London, Ontario N6A 5B7, Canada

(Received 31 January 1983; in revisedform 22 July 1983; receivedfor publication 17 August 1983) Abstract~Given a linear quadtree forming a region's contour, an algorithm is presented to determine all the pixels 4-connected to the border's elements. The procedure, based on a connectivity technique, associates a two-valued state ("blocked" or "unblocked") with each node and fills increasingly larger quadrants with black nodes whose state is known to be unblocked. Advantages of the proposed procedure over existing ones are : (i) multiply connected regions can be reconstructed; (ii) the border can be given as a set of either 4- or 8connected pixels. Linear quadtrees Contour filling Pixel-based algorithms

I. I N T R O D U C T I O N

Binary images

Connectivity filling

corresponding to "unblocked" sides with black pixels. The procedure, with minor modifications, can be repeated at all successive (higher) quadrant-levels, with the last quadrant being the entire raster.

Linear quadtrees have been introduced recentlyt~-5~ as a memory-saving device for storing blocks of black pixels arising from the regular decomposition of twovalued images. Operations such as encoding and 2. D E F I N I T I O N S decoding (to and from a 2-dimensional array), A pixel is an element of the set 12, where I is the set of superposition, dynamic refinement, projection, rotation by 90 ° and detection of connectivity have been integers. Two pixels Q = (i,j) and Q' = (i',f) are said discussed in the above-referenced papers, while a to be p-adjacent for p = 0, 1, 2 if computer implementation of the corresponding 0 =< l i - i'l =< 1,0=< IJ-J'l =< 1, algorithms can be found in Tabakman/6~ The problem considered in this paper is the and reconstruction of a region given its boundary. li - r[ + IJ - J ' [ = P" Polygon-based algorithms,~7-1°~ pixel-based Q and Q' are O(p)-adjacent if they are k-adjacent for algorithms,lS.~O 141, or a combination of both t15~ can some integer k, 0 =< k =< p. The binary relation Rp on be used to tackle this problem. The solution envisaged 12, where QRpQ' iffQ and Q' are O(p)-adjacent, is called in this paper, "tailored" on linear quadtrees' an O(p)-adjacency. Clearly, Rp is reflective and properties, consists of reconstructing the region by symmetric, but not transitive. filling (increasingly) bigger quadrants with black An O(p)-path from Q to Q' is a sequence of pixels QO, nodes. The novel idea is not the use of linear quadtrees, QI . . . . . Q% m > 0, such that but the restructuring of the input data, even though the (i) QO = Q and Q" = Q' authors have been led to such a modification by the desire to avoid determining the neighbors' color: this (ii) Q~-I RpQS, 1 < s < m. operation, when performed on linear quadtrees, is, in Let now S be a subset o f l 2 and Sits set complement. fact, more complicated than it appears at first, as For Q, Q' e S, Q is said to be O(p)-connected to Q' in S if explained in Gargantini and Tabakman. ~t6~ there exists an O(p)-path from Q to Q' consisting of Roughly speaking, the proposed structure "blocks" pixels in S. An O(p)-connected region S is either a single those sides of the border's pixels which are associpixel or a set of pixels each pair of which is O(p)ated with a direction (or, alternatively, those sides connected in S. Set S = {a, e,f, c} shown in Fig. 1, for known to be shared by both the region and its instance, is O(2}-connected, but not O(l)-connected. complement), and fills the adjacent missing nodes An O(1)-connected region S is simply O(1)connected if S is O(2)-connected and an O(2)-connected region is simply 0 (2)-connected if S is O( 1)-connected. * The support of the Canadian Government under NSERC These definitions are, basically, those adopted in grant A7136 is gratefully acknowledged. Rosenfeld.~l 7~ t To whom correspondence should be addressed. 285

286

I. GARGANTINIand H. H. ATKINSON

I I

I I

t I

I I

BORDER = {QI(QeS ^ QR~Q) v ( Q e S ^ QR~hn)

[ I

for some Q e S or some I m • Imag}

I I I ]--

,,,c'//-// "/~d~ "/; /ell'l/l" -

"///~

(2)

for k = 1 and as

~ t

BORDER = {QI(QeS ^ QR2Q ) v ( Q e S ^ QRllm ) for some Q • S or some Ime Imag~

I

I

I I i

I I

i I

I I

I I

Fig. 1. A 22 x 22 pixel-array.

Finally, the O(k)-border of S, 1 < k < p, is the subset

B~(S) = {QHQeS ^ QRkQ for some (~•S--}. (1) For theset S = {a,b,c,d,e,f} shownin Fig. l , t h e O ( l ) border is {a, b, e,f, c}, while the O(2)-border is {a, b, e, d,

f,c}. 3. THE DATA Pixels are, quite often, arranged in a 2" x 2" array form, where n > 1 is known as the resolution parameter. A region S is, in general, given as a set of black pixels and its contour often selected to characterize the region itself and stored instead of the latter, in order to save memory. This technique, used, for instance, in phototypesetting, is useful if we are able to reconstruct the region, once we retrieve the contour. The border's pixels are, in general, determined by traversing the boundaries in such a way that the region either always lies to the right (i.e. clockwise for external contours) or always to the left (i.e. counterclockwise for external contours). To start the traversal, a given pixei, usually the most north-west, is selected together with a direction : the traversal then proceeds by associating, to each border pixel, one or more directions chosen from {E, S, W, N}. The border pixels, together with their corresponding directions, or an initial pixel and a sequence of {E, S, W, N}, called the chain code, are then stored. I t is quite clear that the two forms are equivalent, since one can be obtained from the other, once it is known which adjacency criterion has been adopted. We assume that the input data is given as the border's pixels together with their direction(s), produced by traversing the boundaries in such a way that the region always lies to the right. Before proceeding any further, we have to analyze the different components of the border and establish a suitable representation for them. Let us consider the region given in Fig. 1 with n = 2. It is clear that we have to extend definition (1) to include pixels on the boundary of the 2" x 2" array (or screen). We ideally border each side with 2" "imaginary" pixels, as shown by the dotted lines of Fig. 1. Let Imay denote the set of these pixels and Im a member oflmag. The BORDER of a region S is then defined as

(3)

fork =2. We then associate with each Q e BORDER a 4-bit field, called BLOCK. If the Q-direction is E, Q cannot be adjacent to any pixel on the northern side or, equivalently, Q is "blocked" on the northern side : we, therefore, set the first bit of BLOCK equal to 1. If no other direction is associated with Q, we set the other three BLOCK-bits to 0. Clockwise rotations by 90 ° generate the association scheme given in Table 1. If Q has multiple directions, we OR the corresponding BLOCK-bits. For Q = f of Fig. 1 BLOCK is [0111]. Having associated each pixel with a "blocked" or "unblocked" state, we have to specify how BOR DER is represented. BORDER is a linear quadtree, of length L, with each node formed of two fields, one holding the Q-quaternary CODE, the other the Q-BLOCK. BORDER is, therefore, a two-field array, sorted in ascending order according to CODE. For the time being, we purposely leave unspecified which definition--(2) or (3)--we choose for BORDER. In the sequel the reader is assumed to be familiar with linear quadtrees and their properties."'2.sJ 4. FILLING BY QUADRANTS:DETERMINATION OF THE MISSING-PIXELS'COLOR The algorithm for mapping the given data--represented as explained in Section 3--into a set of O(1)-connected regions is a connectivity filling procedure. The basic idea behind the algorithm consists of using as "seeds", (~°'15~ at pass 0, all the border's pixels, and replacing them, at pass > 1, with quadrants. (Here nodes and quadrants are synonymous, with a node being a pixel or a group of pixels in quadtrees' sense). Roughly speaking the association of "blocked" or "unblocked" states with increasingly bigger quadrants has the effect of blocking the region from growing outwards ("spillover") and forcing its reconstruction inwards until only four quadrants remain to be grouped, each formed of 2"-

Table 1. Values of the BLOCK-bits Direction E S W N

I st

BLOCK-bits 2nd 3rd

4th

A blocking technique for contour filling

7///

(o)

(b)

(c)

l/l/ "////

287

7/7A V / l ; //1"/

(d)

(e)

Fig. 2. Illustration of cases (i)-(v). pixels. To achieve this, we have to determine the color of the missing nodes in each quadrant. At pass 0, when all nodes are pixels, various cases arise, according to the last digit of Q-CODE that identifies the pixel position (0 for NW, 1 for NE, 2 for SW and 3 for SE) in the last subdivision. We have: (i) One node ~ BORDER in the 0 position; (ii) Two nodes e BORDER in positions 0 and 1 ; (iii) Two nodes e BORDER in positions 0 and 3; (iv) Three nodes E BORDER in positions 0, 1 and 2 ; (v) Four nodes e BORDER in positions 0, 1, 2 and 3.

all four nodes are found to be black, they are condensed ;(t .2.5} if some are found to be black, they are

added to the list of black nodes while white missing nodes are completely discarded. The procedure explained for the transition from pass 0 to pass 1 is used, with minor modifications, at the successive passes: what remains to be explained, now, is the mechanism of traversing the black nodes by "large" quadrants while inserting new ones and grouping common blocks. Therefore we need to introduce the data structures supporting the algorithm.

Illustration of the above cases is given in Fig. 2. 5. DATAS'I'RUCTURI'k~ Clockwise rotations by 90 ° generate all other possible cases. We remark that case (iii) does not occur, at pass The input data, BORDER, is an array formed of two 0, if BORDER is defined according to (3). fields, CODE and BLOCK, as shown in Fig. 3. The basic criterion adopted to decide the color of a The output data consists of a linked list, LINQ. missing node within the new quadrant's grouping is with three fields, CODE. COUNTER and LINK lsee simple: ira neighbor is missing (i.e. does not belong to Fig. 4). BORDER) on a blocked side, that neighbor is white, At pass 0 LINQ-CODE equals BORDER-CODE, black otherwise. The next quadrant is given the L I N Q - C O U N T E R = 0, LINQ-LINK points at the BLOCK-value obtained by ORing the corresponding next node, as given by BORDER. At the end of pass ~) BLOCK-bits of its four components : in fact, if one or LINQ contains the linear quadtree relative to the two nodes on the same side are blocked, the new region{s) whose contour is BORDER, with LINK quadrant is also blocked on that side. pointing to the node whose quaternary code is its We have, corresponding to the cases (i)-(iv) listed logical successor in linear quadtrees' sense. Here pass is before, the following. a variable taking the values 0, 1, 2..... n, while FIRST Case (i). If the eastern and southern sides of the present and NEXT are two pointers governing the traversal of pixel are unblocked, the new quadrant is black, LINQ. otherwise the missing nodes are white (eastern side To facilitate the understanding of the algorith m, two blocked and southern unblocked or vice versa cannot auxiliary arrays are introduced, OLD and NEW, with occur due to the criterion used to generate the 3 fields each: CODE, BLOCK and COUNTER. BORDER pixels). Initially the CODE and BLOCK of OLD equal those Case (ii). If the southern sides of the present pixels are of BORDER, while COUNTER is set to 0. At pass 1 unblocked, the missing nodes are black, white N E W - C O D E contains the first In - 1) digits of OLDotherwise. CODE, NEW-COUNTER = O L D - C O U N T E R + 1 Case (iii). If the eastern side of the pixel in the 0 position if all four nodes within the new quadrant are found to and the northern side of that in the 3 positiion are be black, and NEW-BLOCK is determined by ORing unblocked, then 1 is black, white otherwise. If the the corresponding pixels' BLOCK-bits. As an southern side of 0 and the eastern side of 3 are example, the transition from pass 0 to pass 1 relative to unblocked, 2 is black, white otherwise. the region shown in Fig. 5 is given in the first five Case (iv). If the southern side of 1 and the eastern side columns of Table 2. BORDER, given according to (2), of 2 are unblocked, 3 is black, white otherwise. is {001,003,012,013,020,022, 100, 101,110, 111,113, In all five cases--(i)-(v)~the BLOCK-bits are ORed 131, 133, 201,203, 223, 230, 232, 233, 311,313, 321,322, to generate the BLOCK field of the next quadrant. If 331. 332, 333 I. CODE

BLOCK

CODE I QUATERNARY INTEGER

COUNTER LINK No.OF POINTER GROUPINGS

O's ORl's

Fig. 3. The structure of a BORDER node.

Fig. 4. The structure of a L1NQ node.

288

I. GARGANTINIand H. H. ATKINSON Table 2. Filling by quadrants the region of Fig. 5 CODE

Pass 0 BLOCK

CODE

NESW ~1 ~3 012 013 ~0 ~2

ll01 0001 1000 1000 1001 00ll

1~ I01 110 III 113 131 133

1001 1000 1000 1100 0100 0100 0100

Pass 1 BLOCK

COUNTER

Pass 2 BLOCK

CODE

NESW

COUNTER

NESW

~

ll01

0

01

1000

0

02

1011

1

10

1001

11

l 100

1

13

0100

1

l~ll 0

11o~

1

0 q

m

201

0001

203 223

0011 1011

20 22

0 0011 1011 0

230 232 233

0001 0010 0010

23

0011

1 ~

311 313 321 322

0100 0100 0010 0110

331 332 333

0 10 0 00 11 0 110

31

0100

32

0110 0

33

011~

2

00ll

1

3

0111

1

.

1

0

The linear scan of OLD and the traversal of LINQ proceed in parallel, with pointer FIRST pointing at the first node of LINQ having the same (n - 1) digits as OLD and NEXT pointing at the first node, encountered by the traversal, with an (n - 1)-digit code different for that of OLD. This feature allows the updating of LINQ pass by pass. If the four nodes in a quadrant are found to be black, the LINQCOUNTER of the node pointed to by FIRST is increased by 1 and the LINQ nodes between FIRST and NEXT are deleted ;ifa missing node is found to be black but condensation cannot occur, then that node is inserted into LINQ at its proper position (determined by means of FIRST and the node's location in the quadrant). In the example, only node 320 needs to be inserted into LINQ. 6. THE PROCEDURE AT pass > I As the reader has probably guessed, the algorithm at pass > 1 requires "to replace" OLD with NEW, (n - 1) by (n - pass), and repeat the steps described in

Sections 4 and 5. This is basically correct, except that three minor modifications must be introduced. (a) Condensation takes place only if the OLDCOUNTER of all four nodes equals pass. (b)Case (iii), which, at pass 0, can arise only if BORDER is defined according to (2), can now

[ i

'

,

I00 1 I01 1 II0 I I

I I 012 , 0 1 3 ]

,,,

loi 02

IO

[

Ill

I--I II3 L-1131

2 I

1133

"--

2o,

:3,,

ri 313 --__ --7

v

-7 I 3211

2301

_j ~. . . . 2 2 3 ~ 23212331 I

I

I I-

--I 322

i I---t

iII 331

--

332 1 3 3 3

Fig. 5. An O(1)-connected region.

A blocking technique for contour filling

289

- - b l o c k e d southern side of 0 and blocked northern side of 2 or blocked southern side of 1 and blocked northern side of 3. The unblocking operation must be done before ORing the BLOCK-bits for the next quadrant. In the example of Table 2 there are two occurrences of unblocking while going from pass 1 to pass 2: one when quadrant 20 (blocked on the southern side) and quadrant 22 (blocked on the northern side) are grouped together to form quadrant 2, and the other when node 32 (blocked on the eastern side) and node 33 (blocked on the western side) are condensed to form node 3. Another unblocking occurs in the transition from pass 2 to pass 3: eastern side of 0 and western side of 1 unblock one another (slashed l's replaced by 0's indicate this operation in Table 2). Let us now say a few words on the derivation of all other cases by rotating (i }-(iv) of Section 4 by 90 °, 180 ° and 270 °. If 2, for instance, was given in case (i), a clockwise rotation by 90 ° would take place on BLOCK, provoking a circular right shift of 2 BLOCK-bits : after determination of the BLOCK-bits of the new quadrant an inverse mapping (i.e. a circular left shift) brings back the proper values of BLOCK. The core part of the algorithm, implementing cases (i)-(v) of Section 3, is given in the Appendix 1. A more complicated case--consisting of 50(1)-connected subsets--is shown in Fig. 7. For the reader's

Fig. 6. Unblocked nodes. occur also when definition (3) is adopted. (c) A quadrant, blocked at a certain pass, can become unblocked on the very same side at some successive step. This modification is somewhat subtle. Consider, for instance, the region shown in Fig. 6. At pass 1 the B's 0-quadrant (circled) is blocked on the eastern side while 1 is blocked on the western side. The successive grouping, represented by the Bquadrant, is not blocked on either side. To implement this feature in our algorithm we must eliminate internal blocks which are mutually opposite, namely a simultaneous occurrence of - - b l o c k e d eastern side of 0 and blocked western side of 1 or blocked eastern side of 2 and blocked western side of 3

w

00O0 0O01 0010 O011 0100 0101 0110 0111 IOOG IO01 I010 DO02

0102 0103 0112 0113 1002 1003

0020

I011

1032

0200

0210 0211

t

I

I 11210

O3OI

,

0202 0203 0220 0221

,

;o I

~

1222 0223

:)323 0332 0333 1222 ,

IIII

1120

1131

1122

1133

13OO

1311 1313

1

0321

II10

1113

1012 1013

0031

I

IO0 I101

1331

1230

1320

1232

1322 1323 1332 1333,

3010

3111

i

ZOO0 2001

3000 i

2O02 .----;'{'~A~

3002 3003 3012

2020 2021

3020 3021

2022 2023

3022 3023: r / 2211 i2300 2301 2310

2200 2202

I

2212

'

2311

3OI3 3/O2 13103 I

3131 3033

3201~r

2213 2302 2303 2312 2313 3202 3203

t

3113

3123

3133

3300

331

3302

3313

3320 3321

3331

i

2220

Fig. 7. A multiply connected region.

290

I. GARGANTINIand H. H. ATKINSON Table 3. Filling by quadrants the region of Fig. 7. Pass 2 CODE

BLOCK

Pass 3

COUNTER

CODE

NESW 2

12

13

OllJ

2

02 03 10 11

COUNTER

NESW

1~Ol o o lOl~ o Ojll o o 111I 0 0 1~0 0 llOJ 0 O0 1Ioo

ot

BLOCK

1

1 0

0

0 1111

2

1

0 11~0

2

1

2 0

0

22

0 0111 0 1111

0

23

1010

1

20

30 31

1

0 1~1 0 0 lllJ

0 ~Ill 0

1

1 0 0

32 33

0 ~lo 0 0 I, 1 1 ~[ 0

1 0 0

convenience we have given the quadrants grouping for passes 2 and 3 in Table 3. 7. DATA STRUCTURES(REVISITED) Since, at all passes, O L D - C O D E and N E W - C O D E contains the first ( n - p a s s ) and (n - pass - 1) digits of the B O R D E R nodes, respectively, this information can be directly derived from L I N Q (see Fig. 8) by performing remainder operations. O L D and NEW, therefore, are not necessary and were introduced to facilitate the understanding of quadrants grouping. After completion of pass n, L I N Q - C O D E should be shifted to the right a n u m b e r of quaternary places as indicated by L I N Q - C O U N T E R : alternatively, this operation could be done at each pass while updating the L I N Q - C O U N T E R s .

0

8. ALGORITHM CAPABILITIES The algorithm uses an O(1)-adjacency criterion to determine all the pixels connected to the border while grouping them into the largest possible quadrants. Due to the introduction of blocked and unblocked sides, the contour can be given in either the (2) or (3) form: pixeis present in (3) while missing in (2)~like 0013, 0201, 1102, 3200 of Fig. 7 - - a r e assumed to be black. The sides they share with the neighbouring BORDER-pixels, in fact, cannot be blocked. Thus our algorithm, once we include case (iii) as given in Section 3, is invariant with respect to the definition of BORDER. The extension to three dimensions is fairly simple, once octal codes (`*) are used instead of quaternary integers and B L O C K is extended to 6 fields.

A blocking technique for contour filling ( n - poss- I ) - digit

LINK

FIRST

( n - p o s s ) - digit

291 LINK

NEXT

Fig. 8. Quaternary digits (from right to left) represent successive quadrants groupings. The algorithm fills a BORDER of length L in n steps. Let N P be the area, measured as the sum of black pixels forming the sought region, N the number of LINQ nodes after completion of the algorithm, k~ the execution time of a remainder operation, k2 that of an OR or shifting operation and k3 that of a comparison. Since once a black node is inserted into LINQ at some step it can never be condensed at a successive one, the total running time of the algorithm is, in the worst case, proportional to ( k l , p a s s + k2 + k3)* pass

= 1

= k n 2 (L + N), for some k > 0. Existing algorithms are either proportional to the area to be filled (i.e. to N P ) or to the area of the rectangle circumscribing the filled region (i.e. to an integer >_ N P ) ; in our case the algorithm works in time proportional to the number of black nodes plus the number of border pixels, and can be applied to any pixel-based region.

The remaining part of the filling algorithm depends on the data structure used: linear quadtrees. We fill the region quadrant by quadrant, with quadrants made up from 2 x 2 pixels up to 2"- ~ x 2"- ~ pixels, where n is the resolution of the image. The idea of "blocking" border pixels is shown to be successful in "blocking" increasingly larger quadrants--via a few modifications, of course. The algorithm does not present "spillovers", works also in the presence of regions with "holes", and can be executed in n steps. In writing this paper the authors have been faced with the problems of defining the border in a fashion suitable to actual computation, presenting the procedure informally enough to be clearly understood, giving significant examples and then presenting the formal algorithm. To keep the paper within a reasonable size we have limited the examples to two (one of Which only partially worked-out), and the formal algorithm to the core part of the filling procedure.

Acknowledgement--The authors wish to thank Drs. T. R. S. 9. SUMMARY

One of the most common problems in digital image processing consists of filling a region, given a set of border pixels and corresponding direction(s). Almost any algorithm works if the sought region is convex ; most work if the region is known to be simply connected; very few perform well in the presence of "holes". This paper presents a pixel-based procedure to solve the problem formulated for linear quadtrees. The novelty of the paper, however, does not lie with the use of linear quadtrees but in restructuring the input data in a form suitable for contour filling. Instead of associating a direction to each given border pixel, we associate a state : "blocked" or"unblocked". Ifa pixel, for instance, has only the eastern and southern directions associated with it, we know that the northern and eastern sides are "blocked", in the sense that no neighbors sharing that side can be black; the southern and western sides are "unblocked", in the sense that association with missing black nodes is possible. We define, therefore, for each border pixel, a 4-bit BLOCK-vector corresponding to the northern, eastern, southern and western sides: the bit is 1 if the pixel side is blocked, 0 otherwise.

Walsh and M. V. R. Ramanath for their criticism.

REFERENCES

1. I. Gargantini, An effective way to represent quadtrees, Commun. Ass. comput. Mach. 25, 905-910 (1982). 2. I. Gargantini and Z. Tabakman, Linear quad- and octtrees: their use in generating simple algorithms for image processing, Proc. Graphics Interface '82. NCGA, pp. 123-127 (1982). 3. I. Gargantini, Detection of connectivity for regions represented by linear quadtrees, Comp. Math. Applic. 8, 319-327 (1981). 4. I. Gargantini, Linear oct-trees for fast processing of threedimensional objects, Comput. Graphics Image Process. 20, 365-374 (1982). 5. I. Gargantini, Translation, rotation and superposition of linear quadtrees, Int. J. Man. Mach. Stud. 18, 253 263 (1983). 6. Z. Tabakman, A software package for linear quadtrees. CS 490Y Thesis, Computer Science Department, The University of Western Ontario (1982). 7. K.E. Brassel and R. Fegeas, An algorithm for shading of regions in vector display graphics, Proc. Association ~f Computing Machines SIGGRAPH 79, pp. 126 133 (1979). 8. M. L. Lieberman, How to color in a coloring book, Proc. Association of Computing Machines SIGGRAPH 78, pp. 111-116 (1978).

292

I. GAR(;AI'ZrlNIand H. H. A'rKINSON

9. W.M. Newman and R. F. Sproull, Principleoflnteractive Graphics. McGraw-Hill, New York (1979). 10. T. Pavlidis, Algorithms for Graphics and Image Processin.q. Computer Science Press, Rockill, MD (1982). 11. T. Pavlidis, Filling algorithms for raster graphics, Comput. Graphics Image Process. 10, 126-141 (1979). 12. H. Samet, Region representation: quadtree from boundary codes, Commun. Ass. comput. Mach. 23, 163-170 (1980). 13. U. Shani, Filling regions in binary raster images--a graph theoretical approach, Proc. Association of Computing Machines SIGGRAPH 80, pp. 321-327 (1980). 14. A. R. Smith, Tint fill, Proc. Association of Computing Machines SIGGRAPH 79, pp. 276-283 (1979). 15. T. Pavlidis, Contour filling in raster graphics, Ass. comput. Mach. Comput. Graphics 15, 29-36 (1981). 16. 1. Gargantini and Z. Tabakman, Separation of connected components using linear quad- and oct-trees, Proc.

Twelfth Conf. Numerical Mathematics and Computing University of Manitoba, 1982, pp. 257-267 (19821. 17. A. Rosenfeld, Connectivity in digital pictures, d. Ass. comput. Mach. 17, 146-160 (1970).

APPENDIX Procedure G R O U P (FIRST, NEXT, PRESENT, BLOCKPR, COUNT); (* This procedure groups all black nodes that belong to the same quadrant at the current PASS: these nodes lie, in LINQ, between the node pointed by FIRST (included) and the node pointed by NEXT; the (n - PASS - 1) digit ofeach of these LINQ-CODEs have been moved into PRESENT[I], 1 < 1 < 4, while the corresponding BLOCK-bits have been moved into BLOCK-PR; PRESENT[I] are sorted, i.e. if node 0 is present, it is in PRESENT[l], etc. ; BLOCK-PR[I, 1] contains the BLOCK-bit relative to the northern side of PRESENT[I], BLOCK-PR[1, 2] the bit relative to the eastern side of PRESENT[l], and so on. COUNT is the number of black nodes present in the current quadrant. Five procedures (not given) are called within GROUP. They are: (i) ROTATION, which performs a circular right shift on the BLOCK-PR bits; (ii) INV-ROT, which implements the inverse operation; (iii) OR-B, that ORs bits; (iv) CONDENSE-UPDATE, which condenses four black nodes, if possible, by updating the COUNTER of one of them and deleting the others, inserts black nodes if necessary and moves ahead the necessary pointers; (v) MOVE-POINTERS which moves pointers in LINQ to prepare for next quadrant *)

integer COUNT; integer array PRESENT[1:4], BLOCK-PR[1:4, 1:4]; pointer FIRST, NEXT; begin integer ROT-ANGLE ; integer array NEW-BLOCK[1:4, 1:4] ; case COUNT of 1 : begin (* only one node is present *) if PRESENT[I] = 0 then (* no rotation is necessary *) ROT-ANGLE ,---0 else if PRESENT[I] = I then (* rotate by 270 degrees *) ROT-ANGLE ,- 270 else if PRESENT[I] = 2 then (* rotate by 90 degrees *) ROT-ANGLE ,-- 90 else (* rotate by 180 degrees *) ROT-ANGLE ,-- 180; ROTATION (PRESENT, BLOCK-PR, ROT-ANGLE); NEW-BLOCK ,-- OR-B (BLOCK-PR); INV-ROT (NEW-BLOCK, ROT-ANGLE); (* perform test on rotated bits *) if BLOCK-PR[1, 2] = 0 and BLOCK-PR[1, 3] = 0 then (*missing nodes are black *) CONDENSE-UPDATE else (*missing nodes are white *) MOVE-POINTERS end ; 2: begin (*two nodes are present *) if (PRESENT[I] = 0 and PRESENT[2] = 1) or (PRESENT[l] = 0 and PRESENT[2] = 3) then ROT-ANGLE ~ 0 else if (PRESENT[l] = 1 and PRESENT[2] = 3) or (PRESENT[I] = 1 and PRESENT[2] = 2) then ROT-ANGLE ,- 270 else if PRESENT[I] = 2 and PRESENT[2] = 3 then ROT-ANGLE ~ 180 else ROT-ANGLE ,,-- 90; ROTATION (PRESENT, BLOCK-PR, ROT-ANGLE); (* test if present nodes share an edge *) if PRESENT[l] = 0 and PRESENT[2] = 1 then begin (* eliminate opposite internal directions if any *) if BLOCK-PR[1, 2] = 1 and BLOCK-PR[2, 4] = 1 then BLOCK-PR[I, 2] ,-- BLOCK-PR[2, 4] ,-- 0; NEW-BLOCK ,-- OR-B (BLOCK-PR); INV-ROT (NEW-BLOCK, ROT-ANGLE); (* perform test on rotated bits *) if BLOCK[I, 3] = 0 and BLOCK[2, 3] = 0 then (* missing nodes are black *) CONDENSE-UPDATE

A blocking technique for contour filling else (*missing nodes are white *) M O V E - P O I N T E R S end else (* present nodes share a corner *) begin NEW-BLOCK ~ OR-B (BLOCK-PR);

INV-ROT (NEW-BLOCK, ROT-ANGLEI; if BLOCK-PR[1, 2] = 0 and BLOCK-PR[2, 1] = 0 and BLOCK-PR[1, 3] = 0 and BLOCK-PR[2, 4] = 0 then (* missing nodes are black *) CON DEN SATE-U PDATE else if BLOCK-PR[I, 2] = 0 and BLOCK-PR[2, 1] = 0 then (* node in position 1 is black, node in position 2 is white *) CON DEN SE-U PDATE else if BLOCK-PR[1, 3] = 0 and BLOCK-PR[2, 4] = 0 then (* node 2 is black, node 1 is white *) CONDENSE-UPDATE else (* missing nodes are white *) M O V E - P O I N T E R S end end ; 3: begin (* three nodes are present *) if P R E S E N T [ l ] = 0 and PRESENT[2] = 1 and PRESENT[3] = 2 then R O T - A N G L E .-- 0 else if P R E S E N T [ I ] = 0 and PRESENT[2] = 2 and PRESENT[3] = 3 then R O T - A N G L E ,-- 90 else if P R E S E N T [ I ] = 1 and PRESENT[2] = 2 and PRESENT[3] = 3 then ROT-ANGLE *-- 180 else R O T - A N G L E *-- 270; (* eliminate opposite internal directions if any *) if BLOCK-PR[1, 2] = 1 and BLOCK-PR[2, 4] = 1 then BLOCK-PR[I, 2] ,-- BLOCK-PR[2, 4] ,-- 0; if BLOCK-PR[1, 3] = 1 and BLOCK-PR[3, 1] = I then BLOCK-PR[I, 3] *-- BLOCK-PR[3, 1] *- 0; NEW-BLOCK ,-- OR-B (BLOCK-PR); INV-ROT (NEW-BLOCK, ROT-ANGLE); (* performed test on rotated bits *) if BLOCK-PR[2, 3] and BLOCK-PR[3, 2] = 0 then (* missing node is black *) CONDENSE-UPDATE else (* missing node is white *) M O V E - P O I N T E R S end; 4: begin (* all four nodes are present *) (* eliminate opposite internal direction if any *) if BLOCK-PR[1, 2] = 1 and BLOCK-PR[2, 4] BLOCK-PR[I, 2] ,- BLOCK-PR[2, if BLOCK-PR[I, 3] = 1 and BLOCK-PR[3, 1] BLOCK-PR[I, 3] ,-- BLOCK-PR[3, if BLOCK-PR[2, 3] = 1 and BLOCK-PR[4, 1] BLOCK-PR[2, 3] ,-- BLOCK-PR[4, if BLOCK-PR[3, 2] = 1 and BLOCK-PR[4, 4] BLOCK-PR[3, 2] ,-- BLOCK-PR[4, NEW-BLOCK ,-- OR-B (BLOCK-PR); CONDENSE-UPDATE ; end ;

= 1 then 4] 4-- 0; = 1 then 1] ,-- 0; = 1 then 1] ,-- 0; = 1 then 4] ,--0;

About the Author--I RENFGARGANTINI received the degree of Oottore in Scienze Fisiche from the Universita degli Studi di Milano (Italy). Dr. Gargantini worked as an Assistant Professor at the University of Milano, and as a researcher at the European Automic Center in Brussels and at the IBM Research Center in Zikich. In 1968 she joined the Department of Computer Science at The University of Western Ontario where she is, at present, an Associate Professor. Most of her publications are in numerical analysis. About the Author--HARvl-v HAMILTON ATKINSON received the B.Sc. from Sir Wilfrid Laurier University (Waterloo, Ontario) in 1974 and the M.Sc. in Computer Science from The University of Western Ontario in 1982. At present, Mr. Atkinson is a research assistant in the Department of Computer Science at The University of Western Ontario.

293