10
A new antialiasing approach for image compositing Jean-Pierre Braquelaire, Anne Vialard Laboratoire Bordelais de Recherche en Informatique URA 1304, Universite´ Bordeaux I, 351, cours de la Libe´ration, F-33405 Talence, France e-mail: MJean-Pierre.BraquelaireD Anne.VialardN@ labri.u-bordeaux.fr In this paper we describe a new antialias- ing technique for discrete regions. We pro- pose the use of a new model of contours, called euclidean paths, which provides an approximation of the underlying real boundary of a discrete region. Euclidean paths are used to compute the blending coefficients of the frontier pixels. This method allows us to superimpose a dis- crete region on a background while avoid- ing the well-known staircase effect. Key words: Image compositing Anti- aliasing Discrete regions Discrete con- tours Euclidean paths Correspondence to: J.-P. Braquelaire 1 Introduction A discrete region is a connected set of pixels of a discrete 2D image. Typically, discrete regions result from image segmentation. It is well known that a paste operation of a discrete region on a background picture produces aliasing along the region boundary. Such aliasing effects can be partly corrected by applying postprocessing anti- aliasing techniques on the resulting image. Antialiasing as postprocessing has been con- sidered in two different ways. The first and most used approach consists of applying image pro- cessing techniques to the compound image. In this case, antialiasing of a discrete region is based on low-pass filtering [GW87] applied along the re- gion boundary [FvDFH90]. As the discrete region generally results from the sampling of a real region, a better approach to region antialiasing would consist of computing the blending coefficients of the frontier pixels, which are the pixels crossed by the underlying real boundary. For each boundary pixel, a commonly used blending coefficient is the ratio between the pixel area inside the real region and the area outside (box filtering) [Bli94, FvDFH90, PD84]. Unfortunately, the real boundary is unknown in most cases. The second approach to antialiasing as postprocessing is based on the reconstruction of the underlying real boundary, which implies an analysis of the discrete contours. In 1983, Bloomenthal proposed a method of anti- aliasing based on the recognition of straight lines in the image [Blo83]. More recently, van Overveld [vO92] described a method based on the detection of jaggies in the image. These two techniques only antialias linear frontiers efficiently. Moreover, they are not adapted to the specific problem of pasting a discrete region on a given background insofar as they are designed to postprocess an image globally. In this paper, we propose the use of a new contour model that provides a convenient reconstruction of the underlying real boundary. In Sect. 2, we describe our contour model called euclidean paths. We briefly explain a construction method of euclidean paths based on the recogni- tion of discrete lines along the discrete contour. In Sect. 3, we show how to use euclidean paths to compute the blending coefficient of each frontier pixel. Finally, in Sect. 4, we provide some significant results obtained with this method that we com- pare with the usual frontier filtering technique. The Visual Computer (1997) 13 : 218227 ( Springer-Verlag 1997 218

A new antialiasing approach for image compositing

Embed Size (px)

Citation preview

Page 1: A new antialiasing approach for image compositing

A new antialiasingapproach for imagecompositing

Jean-Pierre Braquelaire,Anne Vialard

Laboratoire Bordelais de Recherche en Informatique —URA 1304, Universite Bordeaux I, 351, cours de laLiberation, F-33405 Talence, Francee-mail: [email protected]

In this paper we describe a new antialias-ing technique for discrete regions. We pro-pose the use of a new model of contours,called euclidean paths, which provides anapproximation of the underlying realboundary of a discrete region. Euclideanpaths are used to compute the blendingcoefficients of the frontier pixels. Thismethod allows us to superimpose a dis-crete region on a background while avoid-ing the well-known staircase effect.

Key words: Image compositing — Anti-aliasing — Discrete regions — Discrete con-tours — Euclidean paths

Correspondence to: J.-P. Braquelaire

1 Introduction

A discrete region is a connected set of pixels ofa discrete 2D image. Typically, discrete regionsresult from image segmentation. It is well knownthat a paste operation of a discrete region ona background picture produces aliasing along theregion boundary. Such aliasing effects can bepartly corrected by applying postprocessing anti-aliasing techniques on the resulting image.Antialiasing as postprocessing has been con-sidered in two different ways. The first and mostused approach consists of applying image pro-cessing techniques to the compound image. In thiscase, antialiasing of a discrete region is based onlow-pass filtering [GW87] applied along the re-gion boundary [FvDFH90].As the discrete region generally results from thesampling of a real region, a better approach toregion antialiasing would consist of computingthe blending coefficients of the frontier pixels,which are the pixels crossed by the underlying realboundary. For each boundary pixel, a commonlyused blending coefficient is the ratio between thepixel area inside the real region and the areaoutside (box filtering) [Bli94, FvDFH90, PD84].Unfortunately, the real boundary is unknown inmost cases. The second approach to antialiasingas postprocessing is based on the reconstructionof the underlying real boundary, which implies ananalysis of the discrete contours.In 1983, Bloomenthal proposed a method of anti-aliasing based on the recognition of straight lines inthe image [Blo83]. More recently, van Overveld[vO92] described a method based on the detectionof jaggies in the image. These two techniques onlyantialias linear frontiers efficiently. Moreover, theyare not adapted to the specific problem of pastinga discrete region on a given background insofar asthey are designed to postprocess an image globally.In this paper, we propose the use of a new contourmodel that provides a convenient reconstruction ofthe underlying real boundary.In Sect. 2, we describe our contour model calledeuclidean paths. We briefly explain a constructionmethod of euclidean paths based on the recogni-tion of discrete lines along the discrete contour.In Sect. 3, we show how to use euclidean paths tocompute the blending coefficient of each frontierpixel.Finally, in Sect. 4, we provide some significantresults obtained with this method that we com-pare with the usual frontier filtering technique.

The Visual Computer (1997) 13 :218—227( Springer-Verlag 1997218

Page 2: A new antialiasing approach for image compositing

2 Euclidean paths: definitionand construction

We call the set Z2 the discrete plane and any pointof Z2, a discrete point. We classically identify adiscrete point P and the pixel centered on P.Two discrete points P and Q are 8-adjacent ifmax( Dx

P!x

QD , Dy

P!y

QD)"1. An 8-connected

discrete path is then defined as a sequence(P

0,2 , P

n) of discrete points such that P

iis

8-adjacent to Pi`1

for all 04i(n. We definea discrete contour as any 8-connected path of thediscrete plane with no self-intersection. The cor-responding discrete region is the set of points ofZ2 located inside the discrete contour. See Fig. 1.The model of euclidean paths provides a newrepresentation of such 8-connected discrete con-tours. A similar representation for 4-connecteddiscrete paths representing interpixel contourshas been detailed in a previous work concerningcontour smoothing applied to contour visualiz-ation [Via96]. The general idea of our modelconsists of moving each contour point from itsoriginal position in order to smooth the contour.This approach is based on the fact that the under-lying real boundary is likely to be a smooth curve.Moreover, euclidean paths preserve all the in-formation contained in the original discrete paths.Let P"(X, ½) be a discrete point. We define thecell of P as the set of points of R2 satisfying thefollowing constraint:

DX!xD(12

and D½!y D(12

.

In other words, the cell of P is the pixel centeredon P without its borders. We define a euclideanpoint associated with P as a given point p of thecell of P (Fig. 2).Let C be a discrete contour. It can be defined asa sequence of discrete points C"(P

0, P

1,2 ,P

n).

The sequence of real points CM "(p0, p

1,2 , p

n)

where piis a euclidean point associated with P

iis

called a euclidean path associated with C. Thelocation constraint of each point of a euclideanpath is such that any discrete contour canimmediately be restored from an associated eu-clidean path. As a matter of fact, rounding offa euclidean point p

ito the nearest discrete point

gives the initial contour point Pi.

Let us now briefly describe a method of construc-tion that provides a smooth euclidean path froma discrete contour. As any discrete contour canlocally be considered as a discrete line segment,one can approximate the real tangent at eachpoint of the contour path. To obtain the asso-ciated euclidean point, we project the contourpoint on the local tangent. Repeating this opera-tion along the discrete contour provides an asso-ciated euclidean path that satisfies the smoothnessrequirement. The estimation of local tangents isbased on the following definition of an 8-connec-ted discrete line.

Definition 1. [Rev91] An 8-connected discrete lineD is the set of points (x, y) of Z2 that satisfies thedouble inequality k4Ax!By(k#max( DA D, DB D),where A, B, k3Z.

The rational AB

is the slope of D and the integerk describes its position in the discrete plane. Intu-itively, the discrete line is the set of integer pointsenclosed between the real lines of equationy"(Ax!k!max(DAD, DBD)#1)/B and y"(Ax!k)/B.Let us consider an 8-connected discrete line D anda given point P of D. Let (A, B, k) be the character-istics of D calculated in the local coordinate sys-tem of origin P. Without any loss of generality, wesuppose here that 04A4B (D is located in thefirst octant). The other cases can be inferred byusing symmetries. The equation of D is nowk4Ax!By(k#B.Let p be the real point of coordinates (x, y)"(0, a)with a"(1!2k!B)/2B. It can be shown thata verifies !1

2(a(1

2. In other words, p is a eu-

clidean point associated with P. One can considerp as a projection of P on the real line D ofequation y"(A/B)x#(1!2k!B)/2B. More-over the lineD is at equal distances from both thereal lines bounding D. This construction of a eu-clidean point associated with a point of a discreteline is illustrated in Fig. 3.Let us now consider a point P of a discrete con-tour C. We use a vectorization algorithm in orderto find the longest discrete line segment ofC around P. We apply the line recognition processsymmetrically around P to extract a segment cor-responding to the intuitive notion of the tangent

219

Page 3: A new antialiasing approach for image compositing

1

4

32

Fig. 1. Discrete region and its discrete contour

Fig. 2. The sequence of points (P0,2 , P

6) is an 8-connected path.

The cell of each discrete point P is defined as the open unit squarecentered on P. The gray square in the figure represents the cell of P

2.

A euclidean point associated with a discrete point can be any point ofthe cell. The point p

2is an example of a euclidean point associated

with P2

Fig. 3. Tangent driven construction of a euclidean point associatedwith a discrete point

Fig. 4. An 8-connected disk contour and its associated euclidean path

at P. We use an adapted version of the vectoriz-ation algorithm of Debled and Reveilles[DRR95] to obtain the characteristics of therecognized discrete line [Via96]. The real lineD associated with the recognized line D is anapproximation of the real tangent at P. The char-acteristics of the discrete tangent at P and theprojection described are used to compute the eu-

clidean point associated with P. Figure 4 gives anexample of a euclidean path built by this methodfrom a discrete circle.Note that, although the construction uses a vec-torization algorithm, euclidean paths are whollydifferent from vectorized discrete curves. In par-ticular, euclidean paths avoid the asymmetriesusually arising with vectorization.

220

Page 4: A new antialiasing approach for image compositing

3 Antialiasing of discrete regions

In this section, we present the principles of analgorithm for computing the blending coefficientof each frontier pixel of a discrete region. In theprevious section, we have seen how to constructa euclidean path associated with the contour ofa discrete region. We suppose here that the pointsof the euclidean path are linked by line segmentsand thus a polyline is defined. We call the set ofreal points surrounded by this polyline the euclid-ean domain. The principle of the algorithm is tocompute the area covered by the euclidean do-main for each pixel crossed by the polyline. Thearea computed between 0 and 1 directly gives theblending coefficient.Let C"(P

0, P

1,2 , P

n) be a discrete contour and

CM "(p0, p

1,2, p

n), its associated euclidean path.

Let us consider the cell ciof the contour point P

i.

According to the definition of euclidean paths,there is one and only one euclidean point in eachcell. Thus, the portion of the cell c

icovered by the

euclidean domain is defined by only three points(Fig. 5):

— The euclidean point pi.

— The real point I1

corresponding to the intersec-tion between the segment [p

i~1, p

i] and the

sides of ci.

— The real point I2

corresponding to the intersec-tion between the segment [p

i, p

i`1] and the

sides of ci.

One can remark that Freeman’s coding of thediscrete contour gives information about the sidesof the cell for which the intersections have to becomputed.In Fig. 5b, the gray area corresponds to the partof the cell covered by the euclidean domain. Itobviously depends on the convention of orienta-tion adopted to traverse the contour: here theprocessed region is at the left side of the path. It iseasy to compute the covered area of the currentpixel analytically from the intersection points. Inthe general case, this consists of computing thearea of a polygon that has from three to fivevertices. It would be tedious to enumerate all thepossible configurations here. In the example ofFig. 5, the covered area is equal to 1

2(yx

1#xy

2),

where the origin of the coordinates is the lowerleft corner of the pixel, (x, y) are the coordinates

of pi, x

1is the abscissa of I

1and y

2is the ordinate

of I2.

When a discrete diagonal move occurs, a pixelthat does not belong to the discrete contour maybe intersected by the euclidean domain. In thiscase, the covered area is limited to a triangle. Seepixel P in Fig. 6. In this example, the covered areaof pixel P is equal to 1

2x3(1!y

2) where the origin

of the coordinates system is the left lower cornerof pixel P, y

2is the ordinate of I

2, and x

3is the

abscissa of I3.

All the covered areas are computed duringa unique traverse of the euclidean path. Somepixels may be traversed many times by the euclid-ean path. See pixel P in Fig. 7. As the euclideanpath does not cut itself, the consecutive coveredareas can easily be accumulated.We have seen how to compute a blending coeffi-cient for each pixel crossed by the euclidean path.The final color of a pixel P of the discrete regioncrossed by the euclidean boundary is then easy tocompute. Let us denote by col

1the original color

of P in the discrete region and by col2, the color of

the corresponding pixel in the background pic-ture. Then the final color col of P is obtainedthrough the classic blending computation [Bli94]:

col"acol1#(1!a)col

2,

where a is the blending coefficient of P. As theeuclidean path is computed from an 8-connectedpath, the euclidean domain generally intersectssome background pixels. Let B be such a back-ground pixel. To compute the final color of B, weknow the original background color col

2and

the blending coefficient a. However, there is noinformation about the color of the discrete regionat B.A simple way to compute the missing color col

1consists of averaging the colors of those of the4-neighbors of B included in the discrete region.This technique is illustrated in Fig. 8.On the contour example given in Fig. 4, our algo-rithm provides the result shown in Fig. 9a. In thisexample, the pixels for which col

1is obtained by

interpolation are the 12 brightest ones that areenhanced in Fig. 9b.The disk example shows the reconstruction prop-erties of euclidean paths for smooth curves withno angular point. Let us now see the results ona polygonal example. Figure 10a shows a real

221

Page 5: A new antialiasing approach for image compositing

5

6

7

8

a

a

a

b

b

b

Fig. 5. Processing of a cell: a intersectioncomputation; b cover of the cell

Fig. 6. Computing the covered area of a pixeloutside the discrete contour; a intersectioncomputation; b cover of the cell

Fig. 7. Multiple covers of a pixel

Fig. 8. The pixel B being outside the discreteregion, its color col

1is averaged from its

neighborhood. In this example, the intersectionbetween the discrete region and the 4-neighbor-hood of background pixel B contains the pixels O

1and O2. The color assigned to B is the average

between the color of O1

and the color of O2

rectangle and its 8-connected digitization. Fig-ure 10b shows the antialiased rectangle where theblending coefficients have been computed fromthe real rectangle. Figure 10c is the result of lowpass filtering of the interior and exterior bound-aries of the discrete rectangle. Figure 10d shows

the euclidean path computed from the discretecontour and the antialiased picture derived fromit. In spite of a local computation, euclidean pathsallow us to recover a polygonal contour. Ourantialiasing method provides results as good asthose of real antialiasing in this case.

222

Page 6: A new antialiasing approach for image compositing

9

10

a b

a b

c d

Fig. 9a, b. Antialiasing a discrete disk

Fig. 10. Antialiasing of a discrete rectangle;a a rectangle and its digitization; b antialiasingfrom the real boundary; c filtering; d antialiasingfrom the euclidean path

4 Results

In this section we present two results of regionantialiasing obtained with our method. Both re-gions have been extracted from segmented digital

images. We compare these results with resultsobtained by the usual method of low-pass filteringof the region boundary.In the first example, the antialiased region isa polygonal region resulting from the segmenta-tion of a house image (Fig. 11). The top left image

223

Page 7: A new antialiasing approach for image compositing

Fig. 11. House image pasted on a black background; top no antialiasing; middle the boundary is involved with a 3]3 Gaussian filter;bottom antialiasing based on the euclidean path of the house boundary

224

Page 8: A new antialiasing approach for image compositing

Table 1. Computational times of blending coefficients

Number of Timecontour points in seconds

Disk 36 (0.01Rectangle 42 (0.01Zelda 576 0.05House 862 0.22Zelda 1150 0.14

shows the discrete region without any antialiasingpostprocessing. In order to emphasize the jaggingeffect, the house has been pasted on a blackbackground.For each image in the left column, the right col-umn displays an enlargement of an area located atthe intersection of the left part of the roof with thechimney. In the images of the middle row, theboundary has been convolved by a 3]3 Gaussianfilter. Thought the jagging effect is reduced, it isstill visible all around the house boundary. Con-sider, for instance, the left part of the chimney.The borders have been smoothed, but both theindentations remain perceptible. It is obvious,when considering the corresponding enlarged im-age, that the low-pass filtering cannot completelyremove such nonlocal indentations.The images of the lower row are obtained byantialiasing the boundary of the house with themethod already described. Here the borders of theroof look rectilinear and the jaggies have beenentirely removed. Moreover, this method suc-ceeds in removing the nonlocal indentations ap-pearing on the left borders of both the chimneyand the wall.The region of the second example is a segmentedhuman face (Fig. 12). This figure is organized likeFig. 11. Unlike the region of the first example, thisone has nonrectilinear boundaries. It is interestingto observe the effect of the low-pass filtering oncurvatures such as the left border of the neck orthe border of the right cheek. On these parts, thefiltering simply blurs the jaggies, but does notremove them. In this case also the antialiasingwith euclidean paths provides better results.Note that we do not take into account the factthat the color of some pixels of the processedregion may be influenced by the initial back-ground color. This is the case, for example, forpixels belonging to a prefiltered area in the orig-inal image from which the processed region hasbeen extracted. This occurs in real images at ob-ject junctions where the transition area is gener-ally two or three pixels wide. It depends on thesegmentation process whether such a pixel is con-sidered as belonging to the processed region. Inthe example of Fig. 11, the left border of thechimney contains some pixels whose color isa blending between the initial pale blue of the skyand the pink of the brick. A column of those pixelsis particularly visible on the top left image of

Fig. 11 and is still noticeable after the antialiasingprocess. More generally, any pixel of a transpar-ent object contains a part of the initial back-ground color. The specific problem of separatinga foreground object from a background of a con-stant color has been discussed in an article bySmith and Blinn [SB96]. This kind of treatmentis, however, not the aim of this paper.The complexity of the construction of euclideanpaths depends on the shape of the contour. Themore the contour has large rectilinear segments,the more the vectorization algorithm has to tra-verse contour points to estimate the local tangent.Computational times of the construction of eu-clidean paths and the computation of blendingcoefficients along the discrete contour are given inTable 1 for the examples provided in this paper.These experiments were done on an Iris Indigo2 (150 MHz processor). The proposed method isfast enough for interactive use.The method has been described for simplyconnected regions the boundary of which is an8-connected contour with no self-intersection. It isobvious how to extend it to a region with holes byprocessing each of its contours separately. How-ever, the method fails with self-intersecting con-tours. Consider, for instance, the region of whichthe pixels are (i, i), (i#1, i#1),2 , (i#k, i#k).The blending coefficients resulting from themethod are respectively 0, 1,2 , 1, 0. The methodcan be adapted in order to process these casescorrectly by considering the 4-connected inter-pixel boundary of the region. This boundary is theset of closed polylines drawn between the regionand the background pixels. In this case, it isnot easy to compute the blending coefficientsanalytically, and a supersampling process thatincreases the computational times is involved.However, this method has been implemented andis also fast enough to allow interactive use.

225

Page 9: A new antialiasing approach for image compositing

Fig. 12. Zelda’s face pasted on a dark blue background; top no antialiasing; middle the boundary is involved with a 3]3 Gaussianfilter; bottom antialiasing based on the euclidean path of the face boundary

226

Page 10: A new antialiasing approach for image compositing

5 Conclusion

In this paper, we have described a new method ofantialiasing discrete regions based on the analysisof the discrete contour of the region. The methodconsists of building a smoothed path (an euclid-ean path) and of computing analytically a blend-ing coefficient for each pixel traversed by theeuclidean path. This method gives better resultsthan the usual low-pass filtering of the boundaryand is suitable for image compositing. Moreover,the method is fast enough to allow interactive use.

References

1. Blinn JF (1994) Compositing, part 1: theory. IEEE ComputGraph Appl 14:83—87

2. Bloomenthal J (1983) Edge inference with application toantialiasing. ACM Comput Graph Proceedings of SIG-GRAPH ’83 17:157—162

3. Debled-Renesson I, Reveilles JP (1995) A linear algorithmfor segmentation of discrete curves. Int J Patt Recogn ArtifIntell 9:635—662

4. Foley J, Dam Avan, Feiner S, Huges J (1990) ComputerGraphics Principles and Practices. Addison Wesley, Read-ing, Massachusetts

5. Gonzalez RC, Wintz P (1987) Digital image processing, 2ndedn. Addison-Wesley, Reading, Massachusetts

6. Porter T, Duff T (1984) Compositing digital images.ACM Comput Graph (Proceedings of SIGGRAPH ’84)18:253—259

7. Reveilles JP (1991) Geometrie discrete, calcul en nombresentiers et algorithmique. These d’etat, Universite Louis Pas-teur, Strasbourg

8. Smith AR, Blinn JF (1996) Blue screen matting. ACM Com-put Graph (Proceedings of SIGGRAPH ’96) 30:259—268

9. Vialard A (1996) Chemins Euclidiens: un modele de repre-sentation des contours discrets. PhD Thesis, LaBRI Univer-site Bordeaux I, Bordeaux

10. Overveld C van (1992) Application of morphological filter totackle discretisation artefacts. Visual Comput 8:217—232

JEAN-PIERRE BRAQUELA-IRE received his PhD in 1983 inTheoretical Computer Science.He has been a professor at Bor-deaux I University since 1991and is responsible for a researchteam in image structuring andanalysis at the Research Labor-atory of Computer Science ofBordeaux (LaBRI). His presentinterests are in discrete ge-ometry, color, image analysis,and programming methodology.

ANNE VIALARD obtained aPhD in Computer Science atBordeaux I University in 1996.She is a member of the researchteam in image structuring andanalysis at the Research Labor-atory of Computer Science ofBordeaux (LaBRI). Her researchinterests are in image analysis,image processing, and discretegeometry.

.

227