You are on page 1of 5

On the Conversion of Filled Polygonal Regions from Raster to Vector Representation

J.R.PARKER
Department of Computer Science, University of Calgary, 2500 University Drive NW, Calgary, Alberta, Canada T2N-IN4

The usual method for specifying a fill pattern is to give a small sample of the pattern in raster form. A plotting routine then repeats this pattern over an arbitrary region. It is difficult for devices such as pen plotters to accurately reproduce pictures specified in this manner. By converting the original fill pattern to vector form, it is possible to fill arbitrary polygonal regions with a good approximation of most raster patterns. Received November 1987, revised July 1988

1. INTRODUCTION A.fillpattern is an arrangement of pixels (raster form) or lines (vector form) that will be repeated over some area or areas of a picture. The purpose is to identify areas that have some characteristic in common; in the case of a map, regions of similar population, vegetation, climate or altitude may be filled with the same pattern. The use of fill patterns is quite common in mapping and data graphing applications, where this sort of characterisation simplifies the interpretation of the picture by the viewer. Fill patterns are most often specified as either a single pixel value,12 as in a simple coloured region, or as a small raster image that represents a sample of the pattern. In the latter case the sample must be large enough to be unique but small enough to eliminate redundancy. A template size of 16 by 16 pixels is not unusual. This small region is then plotted repeatedly over a selected picture area. The pattern should be arranged so that lines that meet the boundary of the small fill-pattern template will meet each other when plotted over a larger area.3 8 This creates the appearance that is expected by the viewer. An example offillingwith a small template appears in Fig. 1. Fig. 1 a shows a map as a simple line drawing. The
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o

patterns are given as bit maps, represented by a series of hexadecimal values (b). The map, in this case a map of the Province of Alberta, contains a number of polygonal regions each of which is filled with one of the bit-map patterns (1 c). This is not an unusual way of specifying a fill pattern, nor is it an unusual application. However, the resulting map must be in raster form, and this is difficult to reproduce on a pen plotter or other vector device. 2. CONVERSION TO VECTORS If a pen plotter is to be used as an output device, there are three alternatives. First, the entire picture can be converted into vector form. This is a time-consuming process, even if it can be done accurately. Secondly, the raster fill patterns can be assigned indices, and these would be used to indicate a predefined vector-fill pattern that would be used to fill the polygonal area. The problem here is matching the raster fill patterns with each other so that the same raster pattern in two different locations results in the same vector pattern being used in both cases. Another problem is that the raster version of

Downloaded from comjnl.oxfordjournals.org by guest on December 3, 2010

o o o o o o o o o o o o

o o o o o o o o o o o o

o o o o o o o o o o o o

o o o o o o o o o o o o

o o o o o o o o o o o o

o o o o o o o o o o o o

Pattern is encoded as (Hex): 1111,2222,4444,8888,1111...,8888

(a)

(b)

(c)

Figure 1. An example of region filling, (a) Map outline; (b) a fill-pattern template; (c) map with filled regions.

THE COMPUTER JOURNAL, VOL. 32, NO. 6, 1989 549

J.R.PARKER 1 ... 1... 1... 1 1 ... 1... 1... 1. . 1... 1... 1... 1 .. 1 ... 1 . . . 1 ... 1 . . . 1 . . . 1 . . . 1 .. . 1 ... 1... 1... 1. . . 1... 1... 1... 1 ... 1... 1... 1... 1 1 ... 1... 1... 1 ... . 1 . . . 1 . . . 1 . . . 1 .. .. 1 . . . 1 . . . 1 . . . 1. ... 1... 1... 1... 1 1 ... 1... 1... 1 ... 1 . . . 1 . . . 1 . . . 1 .. . 1... 1 ... 1 ... 1. .. 1 ... 1 . . . 1 ... 1

1 . 11 11 1

1 1 1 1

1. 1 1 1 1

11111 . . 1. . . . 1. . 11 1
1 1

1... 1 .1.1. . 1. 1.1

1 1 11

11111 . . 1. . . . 1. .

1 1 1 1 1 1 . 1. . . 1. ..111..

(a)

(c)

<fD

a a a a a a a a

g b b . h g . . . . m n n . . . c . h . g . . . m . o . . . c . h . . g . . m . o . . . c . . i . . f . m . o . . . c . . . i . f . m . o . . . c . . . j . f . m . o . . . c . . k . . e . m . o . . . c . k . . e . .m . o . .

. . . d . . . c . . . f c . . . d . . . e . . . . c . . . d . . . e . . . . c . . . d . . . e . . . . c . . . d . . . e b . . . c . . . d . . . i . b . . . c . . . d . . . . b . . . c . . , d . . . e . a . . . b . . . c . . . d . . . . a . . . b . . . c . . . d

. . d . . . . d . . bbdbb . .d , . . . d . .

. . f . .

. . f . .

h h h h h

. . f . .

. . f . .
1

j . . . i . . j . i . .

Downloaded from comjnl.oxfordjournals.org by guest on December 3, 2010

. . . . c . . a a c a a . c

. . bcc . . . . b . . . d . . a d . a e . h . . . f . ggf

adc . 1 e . . . . . . e . . .

mp o

g e e g e e g

a:21324 b: 4 13 2 13 c: 4 4 4 13 d: 3 4 4 4 e: 10 7 6 3 f: 6 14 10 10 g: 6 11 6 14

a;41 14 b: 8 1 1 8 c: 12 11 12 d: 16 11 16 e: 16 5 5 16 f: 16 9 9 16 g: 16 13 13 16

a: 7 4 3 4 b: 7 13 3 13 c: 5 6 6 2 d: 5 15 5 11 e: 15 4 114 f: 15 13 11 13 g: 13 6 13 2

a:2624 b: 4 8 2 6 c: 6 8 4 8 d: 8 6 6 8 e: 8 4 8 6 f: 6 2 8 4 g:4262

Figure 2. Sample fill patterns with extracted linear features.

the picture will use different patterns from the vector version, thus changing the appearance of the picture. The third possibility is to convert the small raster image into a vector form and use these vectors tofilla vector region. This should produce pictures with very similar appearances without the high cost of converting the entire image from raster to vector. This is the alternative that will be explored further. What is needed first is a method for extracting the linear features from the fill-pattern template.1-210 The raster-to-vector conversion method described in Ref. 11 works quite well for this application, and has been successfully used to generate all the results that follow. Also, because of the small size of the fill-pattern template, the cost of this conversion is not high, although it may be said that filling a polygonal region with vectors is computationally expensive enough to counterbalance this. Briefly, the method for extracting vectors is as follows.11 The boundary pixels for all white regions in the raster image are set, and all other pixels are cleared.49 For each set pixel in the image all linear features

containing that pixel are traced. A linear feature is defined as a set of pixels that satisfies the chord property.1* The longest linear feature in each case is retained; its endpoints are saved as the vector representation of that feature, and all pixels involved are cleared if they cannot be used in any other features. Pixels belonging to the other linear features are left alone to be used in other features. This process is repeated until no unused pixels remain. The resulting vectors have no overlap between them, and completely redundant vectors (those which consist completely of pixels belonging to other vectors) have been removed. The vectors are normally extracted in raster order. Fig. 2 shows the result of extracting the linear features from four sample fill-pattern templates of size 16 by 16 pixels. The first row of templates in Fig. 2 are the original bit maps; the second row shows the extracted linear features labelled with letters. The endpoints for the first seven vectors found in each template appear at the bottom of the figure. These coordinates are the row and column indices of the start and end pixels in each feature.

550 THE COMPUTER JOURNAL, VOL. 32, NO. 6, 1989

FROM RASTER TO VECTOR REPRESENTATION OF FILLED POLYGONAL REGIONS

The pattern 2a represents a template that contains filled regions within it, which is a special case: the resulting vector fill pattern will contain only the boundaries of the smaller filled regions. The remaining patterns (2b-d) represent line images and can be reproduced exactly.5 It should be noticed that many pixels that belong to more than one linear feature are re-used, thus keeping the number of extracted vectors to as small a number as possible. Zero length vectors must, however, be retained for later use in linking features into polygons. The result of applying this method to a raster fillpattern template is a set of integer coordinates representing the endpoints of the linear features found in the template. These cannot be used directly as a vector fill pattern for a number of reasons. First, the endpoints are given as pixel coordinates, whereas they should be expressed in plots units (inches, centimetres, nibs). There is also a problem of alignment; linear features that were connected to each other by virtue of the endpoints being adjacent pixels now have a gap separating them. Consider the following raster image of a rectangle:

However, when the corresponding vector patterns are used in the same way the result is different:

The gaps between adjacent instances of the pattern can be eliminated by extending the vectors that intersect the pattern boundary by the distance equivalent to one-half of a pixel width.
Downloaded from comjnl.oxfordjournals.org by guest on December 3, 2010

ooooooo o o ooooo o ooooo o ooooo o ooooo o ooooooo

oooooo o o oooo o oooo o oooo oooo o o oooooo

When converted into vectors, the result might be:

ooooooooooooo

ooooooooooooo
these vectors can be connected end-to-end to yield a closed polygon, but cannot reasonably be used as they are. There is a similar alignment problem involving features that connect to the boundaries of the raster template. In order that features connect between neighbouring template regions, the linear features must be extended by one-half of a pixel in both directions. Consider the template seen in Fig. 2b. When two instances of this pattern are copied side by side, they have the following appearance:

o o o o o o o o o * o o o * o o o o o o

o o o o o o o o o o * o o

o o o

o o o * o o o * o o o o o o o o o o o o o o o o o o o * o o o * o o o o o

* o o o * o o o * o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o * o o o * o o o o o o o o

3. LINKING AND RESCALING Linking of the vectors is performed principally to create polygons from formerly solidly shaded areas (Fig. 2a). Linking is done using the endpoints only. Starting at the first vector, distances between its endpoints and all other endpoints are computed. If a distance of 2**0.5 or less is found, then the two vectors involved are considered to be joined at the ends. Extension of the polygon continues from the unused end of the new vector, until no adjacent vectors are found. This process is repeated until all vectors have been examined. The result is a collection of poly-lines; each poly-line can be converted into a polygon if the start and end points are within 2**0.5 units of each other. These are then reprocessed into sequences of vectors that can be drawn individually. The coordinates of the vector endpoints at this stage are still the integer pixel coordinates from the original grid. The final step is to transform the vector endpoint coordinates on to a new grid, so that vectors will connect across unit fill-pattern boundaries. Fig. 3 illustrates this transformation. The raster image is considered to begin at the (1,1) pixel, with pixels occurring every unit along both axes. The system used by the vector image is 0.5 units larger in all directions, and begins at a (0,0) origin point. Therefore, every vector that intersects any of the four boundaries in the original system must be extended to meet the boundaries of the new system. Since we are only concerned with linear features this presents no difficulty. These vectors are now rescaled to fit a unit square, so that the pattern may be easily scaled by the filling algorithm. The fill-pattern template is at this point represented as a collection of vectors that lie within a unit square. To fill a polygonal region with a pattern, a square region is moved across the polygon in raster-scan fashion with no overlap between consecutive square regions. Within each square the template vectors are plotted, clipping against the polygon boundaries. The vectors are scaled to fit the dimensions of the square exactly by multiplying all vectors by the width of the square in plot units. The fill pattern may in this way be scaled independently of the remainder of the picture.

THE COMPUTER JOURNAL, VOL. 32, NO. 6, 1989 551

D. A. UMPHRESS, U. W. POOCH AND M. TAN1K

Vector coordinates Raster coordinates


1

3 2 1

o o o o o o o o o

o o o o

(c)

Figure 3. Raster-to-vector coordinate transformation, (a) Raster and vector coordinates; (A) a line in raster coordinates; (c) an extended line in vector coordinates. 4. R E S U L T S AND C O N C L U S I O N S Fig. 4 shows an example of a result from the complete fill conversion process. The polygonal areas being filled are simply the letters of the word 'FILL', and the fill patterns used are those of Fig. 2; the polygons are clearly not all convex, a common restriction on vector-clipping procedures. In all cases the fill patterns were originally specified as a 16 by 16 pixel image. The execution times needed to convert the fill patterns to vector form are shown in Table 1. The times shown in Table 1 are an average taken over ten trials on a loaded VAX-11/780. The column labelled 'number of vectors' in the above table gives the total number of linear features extracted from the fill pattern. Total connectivity is computed as the sum of the number of neighbours of each set pixel. The time needed to extract the vectors from a fill pattern appears to be more a function of total connectivity than of the number of features found. The time needed tofilla polygonal region is a function of the number of sides in the polygon, the scale factor applied to the fill pattern, and the number of vectors in the fill pattern. A comparison of times for filling would not be relevant. It was noted that if the fill pattern contains filled areas (Fig. 1 a) the boundary-enchancement procedure should use only the horizontal and vertical neighbours to determine which pixels form a boundary. This will result in the filled regions being outlined, thus preserving the overall structure, if not density, of the original pattern. Line-image fill patterns should have all eight neighbours considered. It was also found that allowing a pixel to be used in more than one vector, a characteristic of the feature-extraction process, caused redundant features to be extracted from non-line-image patterns. While this has no effect on the appearance of the filled regions, it does impact the execution time of the filling process. The methods described above were devised for the purpose of converting a large collection of pictures, actually digitised maps, from one device format to another. This enabled a change of computer system to be

Downloaded from comjnl.oxfordjournals.org by guest on December 3, 2010

Table 1. Fill pattern conversion times Pattern Fig. 2 (a) Fig. 2 (b) Fig. 2(c) Fig. 2(rf) Execution time (sec) 0.68 0.42 0.37 0.26 Number of vectors 33 7 8 19 Total connectivity 156 114

80 56

oxox oxox
X X

Figure 4. Example of vector fill. 552 THE COMPUTER JOURNAL, VOL. 32, NO. 6, 1989

o o oxox oxox oxox oxox oxox oxoxoxoxoxox oxoxoxoxoxox

FROM RASTER TO VECTOR REPRESENTATION OF FILLED POLYGONAL REGIONS

effected. For this purpose the method works very well. There are other potential applications that are currently being explored; for example, the removal of existing fill

patterns from raster images, the construction of orthophotomaps from digitised photos, and digital font scaling, to name a few.

REFERENCES
l . C . Arcelli and A. Massarotti, Regular arcs in digital contours. Computer Graphics and Image Processing, 4 339-360 (1975). 2. F. L. Bongiovanni and A. Zorat, The discrete equation of the straight line. IEEE Transactions on Computers, C-24, 310-313 (1976). 3. K. E. Brassel and R. Fegeas, An algorithm for shading of regions on vector display devices. Proc. SIGGRAPH 79, p. 126-133; Computer Graphics, 13 (2), 126-133 (1979). 4. I. Chakravarty, A single pass chain generating algorithm for region boundaries. Computer Graphics and Image Processing, 15, 182-193. (1981). 5. H. Freeman, Computer processing of line drawing images. Computing Surveys, 6 (1), 57-97 (1974). 6. S. H. Y. Hung, On the straightness of digital arcs. IEEE Transactions on Pattern Analysis and Machine Intelligence, PAM1-7 (2), 203-215 (1985). 7. C. E. Kim, On cellular straight line segments. Computer Graphics and Image Processing, 18, 369-381 (1982). 8. D. T. Lee, Shading of regions on vector display devices. Computer Graphics, 15, (3), 37-44 (1981). 9. W. H. H. J. Lunscher and M. P. Beddoes, Fast binary image boundary extraction. Computer Vision, Graphics, and Image Processing, 38, 229-257 (1987). 10. R. Navatia and K. R. Babu, Linear feature extraction and description. Computer Graphics and Image Processing, 13 (3) (1980). 11 J. R. Parker, Extracting vectors from raster images. Computers and Graphics 12 (1) (1988). 12. T. Pavlidis, Contour filling in raster graphics, Computer Graphics, 15 (3), 29-36 (1981). 13. S. Pham, Digital straight segments. Computer Vision, Graphics, and Image Processing, 36, 10-30 (1986). 14. A. Rosenfeld, Digital Straight Line Segments. IEEE Transactions on Computers C-23 (12) 1264-1269 (1974).

Downloaded from comjnl.oxfordjournals.org by guest on December 3, 2010

Announcement
24-26 SEPTEMBER 1990

IFIP WG8.4 Conference on Multi-User Interfaces and Applications, Heraklion, Crete,

Greece Organized by IFIP Working Group 8.4, in cooperation with ACM SIGOIS, Greek Computer Society
Call for papers

Computer-supported cooperative work (CSCW) and other multi-user applications are broadly concerned with the combined use of communications and computer technology by a group of people. The Conference on MultiUser Interfaces and Applications will focus on user interface and architectural issues for CSCW and 'groupware' systems. The conference welcomes papers describing the design, implementation and evaluation of systems that encourage collaboration or coordination among users. Descriptions are solicited of underlying technologies (e.g. shared-window systems, wide-area file systems, multimedia networks), example applications (e.g. co-

authoring systems, group decision support) and related research topics (e.g. multi-user interface design, novel concurrency control schemes). WG8.4 has previously organised a number of conferences and workshops: 'Office Systems' (Helsinki, 1985), 'Methods and Tools for Office Systems' (Pisa, 1986), 'Office Knowledge: Representation, management and utilization' (Toronto, 1987), 'Office Information Systems: The design process' (Linz, 1988) and 'Groupware Technology' (Palo Alto, 1989). The Conference on Multi-User Interfaces and Applications is the sixth event in this series. Suggested topics A partial list of topics includes: desktop conferencing co-authoring systems coordination systems electronic meeting rooms group decision support distributed group problem solving design principles for multi-user interfaces multi-user interface management

shared hypertext/multimedia shared-window systems wide-area file systems


Conference Committee

General Chair Alex Verrijn-Stuart, University of Leiden, Netherlands Programme Chair Simon Gibbs, University of Geneva, Switzerland Organising Chair Panos Constantopoulos, FORTH, Greece
Information for Authors

Submit five copies of a double-spaced paper (twenty pages maximum), or electronic submission of equivalent length to: Dr Simon Gibbs, Centre Universitaire d'Informatique, 12 rue du Lac, Geneva 1207, Switzerland. Tel.: 41 (22) 787.65.87. Internet: gibbs@cgeuge51.BITNET, uucp: mcvax! cernvax! cui! simon. Submission deadline: 20 February 1990; notification of authors: 20 April 1990; cameraready copy: 1 June 1990.

THE COMPUTER JOURNAL, VOL. 32, NO. 6, 1989 553

You might also like