You are on page 1of 4

Efficient Anti-Aliasing Algorithm for Computer Generated Images

Tsuyoshi Isshiki and Hiroaki Kunieda

Dept. Electrical and Electronics Engineering


Tokyo Institute of Technology
2-12-1 Ookayama, Meguro-ku, Tokyo 152-8552, JAPAN
isshiki@ss.titech.ac.jp, kunieda@ss.titech.ac.jp

Abstract detection and calculation of pixel blending ratio is sig-


nificantly simpler and more effective than that of the
Anti-aliasing is one of the most important process for previous post-filtering approaches. It is also well-tuned
generating high quality 3D graphics images. There have for efficient hardware implementation for real time com-
been many approaches for anti-aliasing but few consider puter graphics.
the real-time processing constraints which is critical for
various interactive graphics applications. In this paper,
we propose a very powerful but simple method for anti- 2 Pixel Connectivity
aliasing called double line scanning method which is suit-
able for low cost hardware implementation. We define the color intensity difference of two pixels Pa
and Pb as follows:

d(Pa,Pb)= lP," - IP," - PSI -k lp," - PFl (1)


1 Introduction where P,", P,", P," are the RGB values of pixel P,, re-
spectively. We say that the pixels Pa and Pb are con-
Although the computational power of current micropro- nected if d(P,,Pb) is below a predefined threshold T,
cessors and 3D graphics hardwares enable fast graphics otherwise we say they are disconnected. Also, a con-
image generation, there are strong demands for next gen- nected region is a group of orthogonally adjacent pixels
eration graphics platform which supports high quality where the color intensity difference between any two ad-
real time graphics rendering. Anti-aliasing, especially, jacent pixels is below the threshold T . A jaggy is thus
is one of the crucial task for such high quality graph- defined as the boundary of such connected region which
ics rendering which deals with the 'saggy edge" effect of has staircase pattern.
computer generated images. Several methods on anti- From a 2D image, horizontal and vertical pixel con-
aliasing are present t o date [l] [2] [3] [4]. A popular nectivities are first extracted and stored in two arrays of
supersampling approach generates the image at subpixel Boolean value:
resolution and averages the color intensity on each pixel
region. The drawback of this approach is the high com- c h ( i , j ) = d(p,,J,P*,J-l)< T,
c v ( i , j ) = d(P,,J,p,-l,J)< T (2)
putational cost t o generate the image at subpixel resolu-
tion. Another approach is by post-filtering the generated where P,,J is the pixel color value at ( i , j ) , c h ( i , j )is the
graphics image [3] [4]. It estimates the shape of the ob- horizontal pixel connectivity, and cv(i,j ) is the vertical
jects on the generated image, and calculates the pixel
pixel connectivity.
blending ratio on the edge pixels. The advantage of this
approach is that the computational cost is significantly
less than other anti-aliasing approaches, and it can be 3 Jaggy Extraction Algorithm
totally isolated from other graphics rendering tasks.
In this paper, we propose a new anti-aliasing method Jaggies are extracted by two phases: jaggies whose slope
called double-line scanning method. It is based on post- is between -45" and 45" angle are extracted by horizon-
filtering approach which detects object edges on two line tally scanning two adjacent rows of pixels, and jaggies
buffers, estimates the edge slope and calculates the pixel whose slope is between 45" and 135' angle are extracted
blending ratio for the edge pixels. Our method of edge by vertically scanning two adjacent columns.

0-7803-5471-0/99/$10.0001999IEEE

IV-532
j-1 j j-1 j j-1 j

i i i

i-1 i-1 i-1


if cv(i, j-1 j=1 if cv(i, j-1) = 1
andch I J) 1 and ch(i-1, j) = 1
and ch[;-; =0,E and ch(i, j) E 0 otherwise
openingti) :I UP openingti) :I DOWN openingu) := NULL
j-1 j j-1 j j-1 j

i i i Figure 3: Simple line fitting.


i-1 i-1 i-1
if cvfi. i) = 1
and c@-1, j) = 1
if cv(i. i) = 1
and cwi, j)) = 1
El
and ch(i, j) = 0 and ch(i-1, j) = 0 otherwise
closingti) := UP closingti) := DOWN closing(j) := NULL

Figure 1: Shapes of connected region on the scanning (a) Simple line fitting (b) Our smooth line fitting
points.
Figure 4: Comparison of simple line fitting and our
jaggy-head jaggy-tail smooth line fitting.

case, assign jaggy-tail := closing(j). And also:


if (jaggy-head = UP and jaggy-tail f DOWN 0 If c v ( i , j ) = 1, there are no pending jaggy.
or jaggy-head # DOWN and jaggy-tail = UP)
jaggy-shape := "INC". 0 Else if c h ( i , j ) = 0 and c h ( i - 1 , j ) = 0, then a
new jaggy has started at j . In this case, assign
jaggy-head := opening(j).
else if (jaggy-head = DOWN and jaggy-tail # UP 0 Else another jaggy is pending.
or jaggy-head # UP and jaggy-tail = DOWN)
jaggy-shape := "DEC". The shape of the jaggy is then determined by jaggy-head
and jaggy-tail as shown in Fig.2.

else if (jaggy-head = UP and jaggy-tail = DOWN)


jaggy-shape := "MAX". 4 Smooth Line Fitting Algorithm
After the jaggy has been extracted and its length and
shape evaluated, we need to calculate the jaggy slope
else jaggy-shape := "MIN" and the pixel blending ratio at each pixel on the jaggy.
Bloomenthal[3] and Overveld[4] use a simple line fit-
Figure 2: Jaggy shape evaluation. ting method which is illustrated in Fig.3. In the case
of Fig.3(a), the jaggy slope is determined solely by the
jaggy length (1 / j a g g y - l e n g t h ) , and the line is posi-
When scanning the two pixel rows i and i - 1 hori-
tioned so that it crosses the jaggy boundaries at half
zontally from left to right, we first detect the starting
way point which makes the fitted lines on the adjacent
point of the jaggy, and then detect its termination. De-
jaggies to be continuous at the jaggy boundaries. In the
tection of the starting point and termination point of a
case of Fig.3(b), it is considered as horizontal edge and
jaggy as well as its shape are determined by the shapes of
thus a horizontal line is fitted. The problem of this sim-
the connected region at each scanning point j as shown
ple line-fitting algorithm is that the slope of the fitted
in Fig.1 (denoted as o p e n i n g ( j ) and c l o s i n g ( j ) ) . Here,
line can only be the inverse of integers (1,1/2,1/3,. . .),
the conditions for detecting the start of jaggy and the
therefore the accuracy of the fitted line is quite limited.
termination of jaggy are:
Especially when the actual edge slope is close to 45",
1. If jaggy is not pending, and o p e n i n g ( j ) # N U L L , then jaggy cannot be effectively removed. Also, fitting a hor-
jaggy starts at j . In this case, assign jaggy-head := izontal line in the case of Fig.3(b) can cause unnatural
opening(j). appearance since the original edge may actually be con-
2. If jaggy is pending, and c v ( i , j ) = 1 or (jaggy-head = tinuing from the left jaggy.
U P and c h ( i , j ) = 0) or (jaggy-head = D O W N and In order to deal with these problems, we use the length
c h ( i - 1,j)= 0), then jaggy has terminated at j. In this information of three adjacent jaggies t o determine the

IV-533
line slope of the middle jaggy. Let IO and 11 be the 5 Pixel Blending Ratio Calcula-
starting point and the termination point of a jaggy at
rows i and i - 1, and let L be the jaggy length ( L :=
t ion
21 - 20 + 1). If the jaggy shape is “INC”,then After the fitted lines are calculated, we need to com-
1. If there is an adjacent jaggy terminating at 20 - 1 whose pute the blending ratio of the pixels on the jaggy. When
shape is “INC” with a length of Lo, then the fitted line equation is given as in eq.(3), the blend-
ing ratio between the two vertically adjacent pixels on
1 (Lo > L ) +
rows i - 1 and a becomes b ( j ) := ( j - d0/3 1/2)/(L +
+
d o / 3 d1/3) where j = 0,1, ,L - 1 and 0 < b ( j ) < 1.
a . .

0 (Lo = L ) b ( j ) can be obtained by calculating the gradient db :=


+ +
1/(L d 0 / 3 d1/3) and b(O), and then simply accu-
else do := 0. +
mulate db: i.e. b ( j + 1) := b ( j ) db. Here, we have
2. If there is a adjacent jaggy starting at + 1 whose obtained that 6 bits for representing the blending factor
shape is “INC” with a length of L1, then is enough without any noticeable difference compared
with floating-point representation. Let n be the num-
1 (L1 > L ) ber of bits to represent the blending factor. Following
describes the blending ratio calculation which adopts in-
0 (L1 = L ) cremental linear interpolation algorithm [5].
Blending Calculation(L, do, d l ) :
else d l := 0. + +
W := 3L do dl.
3. Set the line equation as N := 3 . 2 ” .
q := LN/Wj.
r := N mod W .
a := 0.
+
c := q/2 do . 12”/Wj.
For j = 0 to L - 1
Similar calculation is done for the case when the jaggy b ( j ) := c .
shape is “DEC”.Important point here is that we modify c:=c+q.
the length of the jaggy by f 2 / 3 , f 1 / 3 or 0, depending a := a + r .
on the length of the adjacent jaggies. In this way, we If a 1 W, then
can increase the accuracy of the fitted line (line slope a :=a - W .
can now have the values 1,3/4,3/5,3/6,3/7,. . .), and c := c + 1.
further reduce the aliasing effect especially on edges near Here, q and T are the quotient and the remainder of N
. 4 5 O angle. +
divided by W . The term c := q / 2 do . L2”/W] calcu-
Next, if the shape is “ M A X ” , lates the initial value of the blending factor b ( 0 ) . Then
at each iteration, q and r are accumulated in c and a,
1. If there is a jaggy terminating at 20 - 1 with length LO, respectively, and when a becomes larger than W , c is
then let f o ( z ) := (z - 20 + 1/2)/Lo + i - 1. Otherwise incremented by 1. These operations avoid the exact di-
LO:= 0 and fo(z) := i - 1. vision of N / W by evaluating the accumulated remainder
2. If there is a jaggy terminating at 2 1 + 1 with length L1, a. Values LN/WJ,N mod W , and L2n/WJ can be pre-
then let f l ( z ) := -(z - 2 1 - 1/2)/L1 + i - 1. Otherwise computed and stored in a lookup table. When n = 6,
L1 := 0 and fl(z) := i - 1. +
only 3 . 26 2 = 194 entries are needed in the lookup
table.
3. If Lo > 1 or L1 > 1, then set the line equation as

6 Results
else
y =i - 1/2. Here, we show the results of our anti-aliasing method
on a 3D graphics image. The original image is shown in
Similar calculation is done for case when the jaggy shape Fig.5, where the image size is 400 x 400. In Fig.6, the re-
is “ M I N ” . Here we simply extend the fitted lines on the sult of anti-aliasing using our method is shown, where all
left and right of the jaggy to the middle jaggy region. the visible jaggies have effectively been smoothed with-
Fig.4 shows the comparison of simple line fitting and out causing any blurring of the details. Here, the blend-
our modified smooth line fitting. ing factor is represented using 6 bits.

IV-534
Figure 5: Original graphics image without anti-aliasing. Figure 6: Graphics image processed with our anti-
aliasing method.
7 Summary
ACM, ~01.20,pp.799-805, 1977.
In this paper, we have presented an efficient yet very ef-
fective method for anti-aliasing computer generated im- L. Carpenter, “The A-Buffer, an Anti-Aliased Hid-
ages. Its features are: den Surface Method”, ACM Proc. SIGGRAPH 18,
pp.103-108, 1984.
1. We first convert the pixel color information into
pixel connectivity matrix which are represented by a J. Bloomenthal, “Edge Inference with Applica-
single bit, therefore reduced the memory bandwidth tions to Anti-Aliasing” , ACM Proc. SIGGRAPH .I 7,
requirement considerably. pp.157-162, 1983.

2. Jaggy extraction is done merely by scanning the C. van Overveld, “Application of Morphological Fil-
two pixel rows horizontally and vertically with a se- ters to Tackle Discretisation Artefacts”, Visual Com-
ries of simple logic operations which is well suited puter, vo1.8, pp.217-232, 1992.
for hardware implementation. Note that horizontal
D. Field, “Incremental Linear Interpolation”, ACM
scanning and vertical scanning can be done simul-
t aneously. Trans. Graphics, vo1.4, pp.1-11, 1985.

3. We developed an effective line fitting algorithm


which smoot hes the jaggies more effectively than the
conventional line fitting method.
4. We developed an efficient pixel blending ratio calcu-
lation method by adopting incremental linear inter-
polation algorithm which does not require division
and therefore ideal for hardware implementation.

References
[l] F.C. Crow, “The Aliasing Problem in Computer-
Generated Shaded Images”, Communication of the

IV-535

You might also like