Sei sulla pagina 1di 22

Anti-Aliasing

Aliasing
Aliasing definition: Distortion of information due to undersampling To avoid aliasing, sampling frequency has to be greater than twice the highest frequency occurring in the object. This minimum sampling frequency to avoid aliasing is also called the Nyquist Sampling Frequency. In other words, sample at least twice every period.
True Object period

Sampling below Nyquist Freq

Sampling above Nyquist Freq

period

Example of Aliasing
Suppose we have a pattern of alternating red and green stripes.

Suppose we have show this pattern with pixels matching the stripes. This is equal to the Nyquist Frequency. For each pixel, we sample the middle of the pixel and color the entire pixel that color. We get the correct image.

Suppose now we move the pattern further back, so that each pixel is now relatively bigger. Note: This is now below the Nyquist frequency. Once again, we sample the middle of the pixel

Example of Aliasing (continued)

And we color the entire pixel the sampled color. We would get this picture

This gives a severe misrepresentation of the underlying pattern.

Anti-Aliasing
Since were representing real-world objects with a finite number of pixels, aliasing occurs frequently. Therefore, we need to implement techniques to cancel the undesirable effects of aliasing. These techniques are called anti-aliasing techniques. One common anti-aliasing method is super-sampling

Antialiasing Examples

Super-Sampling
Split single pixel into sub-pixels. Pixels final color is a mixture of sub-pixels colors. Simple method: Sample at the middle of each sub-pixel. Then, pixels color is the average of the sub-pixels color.

Pixels

Sub-divide into sub-pixels

Super-Sampling a Zero-Width Line

Apply Bresenhams algorithm at subpixel level

Sub-divide each pixel into sub-pixels, for example 4x4 sub-pixels

Each pixel can have a maximum of 4 colored sub-pixels

0.0 0.5 0.5

0.0 1.0 0.0

0.0 1.0 0.0

1.0 0.0
Assign color

0 2 2

0 4 0

0 4 0

4 0 0

0.0

Fraction of pixels color to be lines color

How many sub-pixels are colored?

Super-Sampling a Line with Non-Zero Width

A line that is one-pixel wide. For every pixel: Maximum number of sub-pixels inside line = 16

0 10/16

0 15/16

5/16 13/16

9/16 7/16

A sub-pixel is considered in if its lower-left corner is inside the line

8/16

2/16

Fraction of sub-pixels are in = fraction of color of the pixel should be line color

Sub-pixel Weighting Masks


Instead of considering each sub-pixel to be of equal importance, assign a weight to each subpixel. Usually consider the center sub-pixel to be most important
1 2 2 1 2 3 3 2 2 3 3 2 1 2 2 1

Example weight for each sub-pixel Total weight = 32 Final color of pixel = Sum of each (sub-pixel colors x sub-pixel weight) / total weight

Common Filter Functions


Box Filter Cone Filter Gaussian Filter

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 2 3 2 1

2 4 5 4 2

3 5 6 5 3

2 4 5 4 2

1 2 3 2 1

1 2 3 2 1

2 5 6 5 2

3 6 8 6 3

2 5 6 5 2

1 2 3 2 1

( x m )2 1 Gaussian function = exp ( 2s2 ) s 2p where s is the standard deviation and m is the mean

Additional Benefit of AntiAliasing


Solve the line-intensity difference problem. The line-intensity difference occurs when were drawing a diagonal line. In the following example, 5 pixels are used to draw each line, but the diagonal line is actually longer. Therefore, the diagonal line appears less intense. Applying anti-aliasing technique automatically takes care of this problem (assume anti-alias non-zero width line).

Anti-Aliasing Area Boundaries


For each pixel, determine what fraction lines in one area, and what fraction lies in the other area. Then, take the weighted average of the two area colors. Pitteway-Watkinson method adapts Bresenhams method to quickly find the percentage.

Potrebbero piacerti anche