Antialiasing: A technique for smoothing jagged lines on a computer graphics image—an implementation on the Amiga

Behavior Research Methods, Jan 1989

Images displayed on computer graphics displays often suffer from the presence of aliasing artifacts that give a jagged appearance to lines or polygon edges displayed on the screen. This paper details the problems associated with these artifacts and presents a method for drawingantialiased lines—ones in which the artifacts have been considerably reduced. The line-drawing routine is further developed to incorporategamma correction, to take into account the nonlinear relationship between the intensity of the light emission from the phosphor of the monitor and the grayscale values used to control the intensity on the screen.

A PDF file should load here. If you do not see its contents the file may be temporarily unavailable at the journal website or you do not have a PDF plug-in installed and enabled in your browser.

Alternatively, you can download the file locally and open with any standalone PDF reader:

https://link.springer.com/content/pdf/10.3758%2FBF03203871.pdf

Antialiasing: A technique for smoothing jagged lines on a computer graphics image—an implementation on the Amiga

PETER P. TANNER 0 1 2 PIERRE JOLICOEUR 0 1 2 WILLIAM B. COWAN 0 1 2 KELLOGG BOOTH 0 1 2 FLYNN D. FISHMAN 0 1 2 0 maybe addressed to PierreJolicoeur, Psychology Department, University of Waterloo , Waterloo, Ontario N2L 3Gl , Canada 1 University of Waterloo , Waterloo, Ontario , Canada 2 TANNER , JOLICOEUR, COWAN, BOOTH, AND FISHMAN Images displayed on computer graphics displays often suffer from the presence of aliasing artifacts that give a jagged appearance to lines or polygonedges displayed on the screen. This paper details the problemsassociatedwith these artifacts and presents a method for drawing antialiased lines-ones in which the artifacts have been considerably reduced. The line-drawing routine is further developed to incorporate gamma correction, to take into account the nonlinear relationship between the intensity of the light emission from the phosphor of the monitor and the grayscale values used to control the intensity on the screen. - Aliasing Raster display systemsthat use cathode-ray tube (CRT) displays, ink jet, electrostatic, or laser printers create im ages with arrangements of colored dots. The resulting im ages, therefore, are only approximate, apart from the rare case in which it is actually desired to create an image that really appears to be made up of dots. The quality of the approximation depends on the resolution of the screen, the resolution of the color informationthat can be stored for each dot, and the care taken to eliminate the effects caused by using this approximation of the desired image. Figure I showsa collection of "straight lines" as drawn on the screen of a personal computer using Bresenham's algorithm, an algorithmtypical of thoseused to draw lines on computer displays (Bresenham, 1965). The jaggies (i.e., the staircase effect) visible on these lines are the result of drawing the line into a matrix of pixels with no attention given to line smoothing or antialiasing. The presence of jaggies has a number of consequences. First, it may give a viewer strong cues as to whether a line is perfectly horizontal or vertical or not. While this cue may be helpful in certain computer graphics applications, it is an artificial information aid whose presence is normally not intended by the experimenter. Second, it may reduce the subject's capacity to understand the image on the dis play. For example, Booth, Bryden, Cowan, Morgan, and Plante (1987) showed that, under certain conditions, there was a significant improvement in a subject's ability to count the number of local elements in an image when that image was processed to reduce the aliasing artifacts. Third, the location and number of jaggies change substan tially when a line moves or changes orientation. A sub ject who views a rotating line receives significant cues that indicate the onset and speed of the rotation from the movement of the jaggies along the line. A subject com paring images A and B, where B is a rotated version of A, may well conclude that they are different images, be cause of the different positions of the steps on the lines within the image. Fourth, for objects that are small in re lation to the pixel grid, the staircase artifacts can cause different parts of an image to change their spatial rela tionships. An example of this occurred in an air traffic simulation system in which distant airplanes, covering only a few pixels, would change shape as they moved. Their wings would drop from one row of pixels to the next at a different time than would the rest of the plane, leading to confusion as to whether it was a midwing plane or an upperwing plane (for another example, see Lind holm, 1988). Finally (although this list is not exhaustive), jaggies result in Moire patterns (Crow, 1977) if there are several near-parallel lines drawn close together. Antialiasing techniques make the aliasing artifacts in rendered images less noticeable. One such technique is to defocus the picture tube on which the image is dis played. Although this approach does work to some ex tent, it does so at the cost of a considerable reduction in the viewable resolution of the image. A second approach is to use a higher-resolution display. For example, changing from 512 x 512 to 1,024 x 1,024 resolution will improve the image. However, such an ap proach is very expensive, it only reduces the aliasing er ror by a factor of two, and it still leaves the aliasing ar tifacts quite visible. Supersarnpling is a third antialiasing technique, in which the display is treated as if it has a higher resolution than is actually the case. Each pixel on the display is composed of several higher-resolution pixels or subpixels. The values of the subpixels for this virtual higher-resolution display are computed in the manner described above, each sub pixel being assigned a value of full on or full off. Then the values of the set of subpixels that constitute each pixel of the actual display are averaged according to some rule, the result being a display pixel that may be set to a gray level between full on and full off. Thus the use of this technique requires the ability to set the intensity of in dividual pixels to intermediate values between full on and full off. This technique increases the time required to draw a line. Increasing the virtual resolution of the display by a factor of n requires n2 subpixels per pixel, with a com putational load also increasing by a factor of n", which is unacceptably high. The fourth and final technique consists of prefiltering the data before sampling. As is described in the next sec tion, this method takes into account the reasons for the aliasing artifacts and takes steps to remove them. Most antialiasing methods in common use employ prefiltering. In particular, the common implementation of the anti aliased paintbrush is filtered to smooth its edges. As with the supersampling technique, prefiltering tech niques require the ability to set the intensity level of any pixel to intermediate values between full on and full off. A consequence of this requirement is that the framebuffer must have more than one bit to represent the gray level or color of each pixel. A further discussion of the aliasing problem and of ap proaches to antialiasing can be found in Rogers (1985) and Foley and Van Dam (1981). Antialiased Lines The term aliasing is used to describe the result of a sig nal being sampled at a rate lower than twice its frequency, as illustrated in Figure 2. The signal at the top of Figure 2 is sampled at a frequency indicated by the dots on the waveform. The result of this sampling (Figure 2, bottom) is a signal that is an alias of the original and bears little obvious relation to the original. The line-drawing al gorithm used to draw the lines in Figure 1 can be thought of as taking a sample at the center point of each pixel. If the line (modeled as a polygon or band with a width of one pixel) crosses this center point, the pixel is turned on, if the line does not cross the point, the pixel is off. Prefilter antialiasingalgorithms operate by setting pixel values according to a blending function pixel(i,j) = al + (l-a)hack> where I is the color of the object being drawn, hack is the previous color of the pixel, and a is the result of a low pass filter applied to the object at (i ,j). In general There are many methods to calculate a, which differ in how they trade off computational accuracy against time required for the calculations. Many implementations use an unweighted filter, one that is constant throughout the convolution mask. This results in a being equal to that #deftne INTENSITY 15 #derIDe abs(x) x < 0 ) '1 (-(x : x ) #derIDeBETWEEN(xl,mid,x2) \ (xl>=rnid && x2<=rnid 11 xl<=rnid && x2>=rnid '1 1 : 0) Draw_Antialiased_Line(xl. yl, x2. y2) int xl, y 1, x2. y2; ( int x, y. dx, abs_th, dy, abs_dy. dx2, dy2. A, Aerr, Tri; int INTENSITYlessTri. Sq. Sqerr, over. under, r, q, L. iner; if( xl==x2 && yl=y2) return(O); abs_dx = (abs( dx = x2 - xl) ); abs_dy = (abs( dy = y2 - yl) ); pixel( x, y. intensity) int x, y. intensity; ( extern struet RastPort .tp; SetAPen( rp.intensity); WritePixel( rp. x, y ); fraction of the area around the pixel that is covered by the line (Crow, 1978). Others model the pixel using a Gaussian function, so that the area of a line closer to the center of the pixel contributes more to the value of a than does an equal area further from the center (Feibush, Le voy, & Cook, 1980). Although this more closely models the actual physics of the monitor, it is much more time consuming than the use of constant filters, In experiments conducted with graphics on a personal computer, the tradeoff between image fidelity on one hand and speed of calculation and ease of implementation of the other normally favors the more practical and simpler antialiasing techniques. To the authors' knowledge, there have been no studies comparing the differences between the results of various antialiasing techniques in terms of the viewer's perception of quality or the viewer's ability to comprehend the image. These differences are appar ently much less than the differences between images with or without antialiasing. Siding with ease of implementation and speed of cal culation, we describe a very rapid antialiased-line drawing technique based on an algorithm by Field (1984). Field actually presents two algorithms for drawing an tialiased lines, both of which compute al directly without lookup tables or floating-point operations. Inner loop mul tiplications are avoided completely. The first algorithm, the one we use, employs approximation techniques to compute the filter response values. Figure 3 shows this algorithm coded as a C program (Kernighan & Ritchie, 1978) for the Commodore Amiga. The Appendix shows a sample program that calls the routine shown in Figure 3. Figure 4 presents an image of the same lines as those in Figure 1, but rendered with the use of this algorithm. This algorithm affects pixels in a parallelogram, with a major axis parallel to the line being drawn and a vertical minor axis if ILlx I < ILly I; otherwise the minor axis is horizontal. The pixels about the point where adjoining line segments meet are normally handled in a consistent and continuous manner. Indeed, drawing a line from (x,y) to (x+n,y+m) would give the same result as drawing two line segments, one from (x,y) to [x+(nlk),y+(mlk)] and the second from [x+(nlk),y+(mlk)] to (x+n,y+m), as suming that both nand m are integers divisible by k. However, if ILlx I < IllyI for one line segment, and not for the abutting segment, the pixels on the exterior angle will not be properly shaded. Extending the algorithm to handle this case would both increase its complexity and decrease its speed considerably. The algorithm assumes that the color of the background is black. White lines drawn on a black screen present a problem only when the lines cross each other, in which case a small portion of the line that has been drawn first will be made darker. Again, extending the algorithm to correct for this situation, while very simple, would sig nificantly decrease its speed. Gamma Correction Lines produced on a graphics display may suffer from a problem in addition to aliasing. Even after antialiasing has been applied, lines that are not perfectly horizontal or vertical may have a striped look, often called the barber pole effect. Furthermore, the stripes move along the line when it is rotated. The lines in Figure 4 suffer from this problem. The barber pole effect can be reduced by the use of gamma correction. Gamma correction takes into account the nonlinear function relating the numbers in the gray scale used to specify an intensity on the screen and the resulting amount of light emitted from the screen phosphor. Usually, the gray-scale values are linearly related to the voltage sent to the control circuitry of the CRT. However, there is a nonlinear relationship between this voltage and the resulting light emission, which is shown in the following expression: L = kV Y where V is the voltage, k is a constant, L is the emitted lightand 'Y is a constant that depends on the monitor used, as well as on the brightness and contrast settings of the monitor. Because the values that are placed in each framebuffer pixel are used to control the output voltage, notthe light, if one has 16gray levels represented by pixel values between 0 and 15 inclusive, it is quite likely that half intensity may be represented by a pixel value some distance from 7 or 8.1 Fortunately, discovering the value of 'Y and then per forming gamma correction is notdifficult. Note, however, that the valueof 'Y will vary from monitor to monitor and, on any singlemonitor, from one day to the next (because of inconsistencies in voltage and temperature). In prac tice, the amountof acceptable variability will dependon the nature of the experimentation. Careful psychophysi cal work may requirethat the valueof 'Y be estimated fre quently. To discover 'Y for a particular monitor at a particular time, one may place two rectangles on the screen beside each other. One rectangle should havea pattern of pixels with half of them at full intensity and the other half at zero intensity. Allthe pixels of the second rectangle should be at the same intensity, approximately in the middle of the lightness range as illustrated in Figure 5. The viewer is then givencontrol over the intensity valueof the pixels of the second rectangle and is asked to set its intensity such that its brightness matches that of the first rectangle. This is easily done by modifying the hardware color lookup table." The pixelvaluerequired in the second rectangle to make this brightness match is recorded, and con sidered to be half intensity. At this stage, the value of'Y can be computed directly. Alternatively, to ensure the accuracy of the computation of 'Y, the process can be repeated after changing the zero intensity pixels in the first rectangle to the newly found half-intensity values so that the three-quarter intensity value can be found. This procedure can be repeated several times until enough points are available to produce a graph that relates pixel values and screen intensities. A lookup table relating the pixel values with the screen intensities can be filled from interpolated points on the graph. Alternatively, the gamma can be computed, and the table entries then calculated. Table 1 was filled by means of the second technique (thecomputed gamma was 2.0; gammas for most monitors range from 1.8 to 2.8), but a table derived directly from a hand-drawn graph differedonly a little from the computed graph. Note that in the table, the range of computed gray-scale values has been increased to 64. If it had been left at 16 values (the number of possible intensities on the display), certain in tensities could never be displayed, because of the non linearity of the mapping. This would result in a slight reduction in the accuracy of the intensities of the darker pixels. With a software lookup table loaded so that pixel values correspond directly withthe pixel brightness (seethe code in Figure 6) the lines previously displayed in Figures 1 and 4 have been replotted in Figure 7. When displayed on a monitor, the gamma-corrected images appeardiffer ent in two ways. First, the barber pole effect is reduced in Figure 7, an effect particularly apparent when linesare in motion. Second, the intensity of the lines varies less if they are rotated. In general they appear to be darker than the uncorrected version. These differences may not be noticeable on the printed page, but they are certainly apparent on the monitor, particularly for lines that are in LUT Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 LUT Value 0 2 2 3 4 4 4 5 5 6 6 6 6 7 7 7 int Gamma[64] = ~ Gamma correction look up table' (0.2, 2, 3,4.4.4.5.5.6,6,6,6.7. 7, 7. 8,8,8,8,9.9.9,9,9,10,10.10.10,10. 11. II, I~ II, 11, II, 12. 12.12.12. 12.12, 13. 13, 13. 13, 13, I~ 13. 14. 14. 14, 14. 14. 14,14, 15. 15, IS, IS, IS, IS, 15. 151; Hdefme INTENSITY 63 Hdefme abs(x) x < 0) ? (-(x : x) Hdefme BETWEEN(xI.mid,x2) \ (xl>=mid && x2<=mid IIxl<=mid && x2>=mid 'l 1 : 0) Draw_Gamma_Comcted_Line(xl, yI, x2. y2) int xl, yl, x2, y2; ( int x, y, dx, abs_dx. dy, abs_dy, dx2. dy2. A, Aerr, Tri; int INTENSITYlessTri, Sq, Sqerr, over. under. r. q, L. incr; if( xl==x2 && yl=y2) retum(O); abs_dx = ( abs( dx = x2 - xl) ); abs_dy = ( abs( dy = y2 - yl) ); motion. The technique suggested here for gamma correc tion requires only a single setup operation. Once derived, the use of gamma-corrected values does not require any additional computation during the rendering of the im age on the screen. Extensions The antialiasing algorithm discussed in this paper is limited to the drawing of lines on a black background. Many techniques exist that perform the anti aliasing of polygon edges (Feibush, Levoy, & Cook, 1980), antipixel( x, y. intensity) int x, y. intensity; ( extern struet RastPort .Ip; SetAPen( Ip. intensity ); WritePixel( rp, x, y ); aliasing between arbitrary colors (as opposed to assum ing a black background as in this paper (Turkowski, 1986), and antialiasing for the very realistic images created by ray tracing (Mitchell, 1987). Just as this paper shows how to find the gamma of a monitor, Cowan (1983) describes a technique to find the functions required for mapping monitor gun voltages into cm coordinates (XYZ color space). In addition, Catmull (1979) discusses the use oflookup tables for film record ing, taking into account both the gamma correction re quired on the monitor, and the nonlinearities in the response of the film. Hardware and Software Considerations The computer routines displayed in this article were written in C for the Commodore Arniga. The display was in high-resolution mode, which results in four bits being available for each pixel, and hence 16 possible gray levels. The programs compile and run using either Lattice C or Manx C. Even with the relatively efficient antialiasing technique outlined above, the time needed to render a given length of line is considerably longer than the time needed to draw a line that has not been antialiased. The difference in draw ing time is especially large in computer systems that have hardware-based line-drawing capabilities (such as the Amiga), because the computations required for the anti aliased line are all performed in software. Nonetheless, we have found that relatively complex stimuli (consist ing of up to 300 short line segments) can be rendered on the Arniga in less than 5 sec. Thus, these stimuli can be "painted" on an invisible screen during the intertrial in terval. Of course, the feasibility of the antialiasing tech nique will depend on a number of factors, such as the speed of the computer, the complexity of the images to be rendered, and the amount of time available for the ren dering process. We know of no other research that has addressed the question of how many different levels of gray, or, alter natively, how many bits per pixel, are required to produce "reasonable" antialiased lines. From our experience with the Amiga, however, it is clear that four bits are suffi cient to render jaggies (that are quite apparent when lines are rendered without antialiasing) virtually imperceptible at normal viewing distances. Nor has any research as signed comparative measures to the quality of lines produced by different antialiasing techniques. Ultimately, it would be useful to carry out a series of experiments similar to those of Booth et al. (1987), in order to map out how performance (and/or appearance) trades off with the number of bits per pixel used to render the antialiased lines. A sample program that calls the routine shown in Figure 3 to draw antialiased lines. This program could also be used to call the routine shown in Figure 6 by changing , 'Draw.Antlaliased.Line' to "Draw _Gamma;Corrected_Line.' , ##include <stdio.h> ##include <clib/macros.h> #include <intuition/intuition.h>


This is a preview of a remote PDF: https://link.springer.com/content/pdf/10.3758%2FBF03203871.pdf

Peter P. Tanner, Pierre Jolicoeur, William B. Cowan, Kellogg Booth, Flynn D. Fishman. Antialiasing: A technique for smoothing jagged lines on a computer graphics image—an implementation on the Amiga, Behavior Research Methods, 1989, 59-66, DOI: 10.3758/BF03203871