Title: CSE 681 Aliasing and Antialiasing
1CSE 681Aliasing and Anti-aliasing
2Aliasing
- Functions are continuous, but the computer only
allows for a discrete representation - Signal processing is very concerned about
discrete representations of functions - Sampling a function is the process of determining
which function values to take and store for
discrete representation - Reconstruction is the process of determining the
function value at non-sampled locations
What is Aliasing? If you insufficiently sample
the signal, it may be mistaken for something
simpler during reconstruction
3Sampling And Reconstruction
- Assume samples are taken at a regular spacing
4An Image is a 2D Function
- An ideal image is a continuous function I(x, y)
of intensities - It can be plotted as a height field (see right)
- How do we determine the function values in a 2D
array table?
5Sampling an Image
- The result is a set of point samples, or pixels
6Sources of Aliasing
- Sampling The process of mapping a continuous
function to a discrete one - For example, take samples along the x-axis
- Quantization The process of mapping a continuous
variable to a discrete one - For example, take samples on the y-axis
- Convert color intensities to 8-bits per channel
(framebuffer). We do this a lot!
discretevalue
discrete position
7An Aliasing Example
Another source of aliasing
8Reconstruction Another Source of Aliasing
- The choice of a reconstruction filter affects
aliasing - For example, texture mapping
9Nearest Neighbor Reconstruction
- Acts like the round() function
- OK approximation, but not so great
10Nearest Neighbor Reconstruction
11Bilinear Interpolation
- Blend the four texel values surrounding the
sample by weighted distance
12Bilinear Interpolation
- Blending (or averaging) eliminates abrupt color
changes - ? Averaging (or smoothing) is a common way to
reduce aliasing artifacts - (i.e., anti-aliasing)
13Nearest Neighbor vs. Bilinear
14Nearest Neighbor vs. Bilinear
15Where Do We Find Aliasing?
- Aliasing occurs through out the rendering
pipeline - Point, normal, depth, and color quantization
- Full float precision is a recent advancement in
PC graphics hardware pipelines - Rasterization of geometric primitives
- Texture mapping
- Display hardware
16Line Rasterization
17Curve Rasterization
18Low Screen Resolution
19Pixels Display Hardware
- The value at a point sample is spread across a
pixel - A pixel is determined by the display device
- Shape and size?
20Aliasing in 2D Texture Mapping
- Texture sampling starts from a pixel in screen
space - Texture image resolution is usually greater than
the screen pixel resolution - Camera motion such as translation and zoom in/out
zoom out
21Aliasing in 2D Texture Mapping
- Texture sampling starts from a pixel in screen
space - Texture image resolution is usually greater than
the screen pixel resolution - Camera motion such as translation and zoom in/out
(called temporal aliasing)
zoom in
22The Classic Checkerboard Example
- A checkerboard texture is a 2D function with lots
of high frequencies (thus, difficult to sample
properly but great to check your anti-aliasing
method)
Aliasing increases when texels per pixel
increases
This texture has more checkers
23Texture Anti-aliasing
- Take a pixel center from screen space, map to
texture space, and filter the texture with the
neighboring texels - This produces the renderings on the previous
slide - How can we perform texture anti-aliasing?
- Map the four corners of the pixel to texture space
24Texture Anti-aliasing
- Map the four corners of the pixel to texture
space - Pixel maps to a quadrilateral (called its
pre-image)
image courtesy of D. Cohen-Or
25Magnification/Minification
- Magnification
- Pre-image covers the area of one texel or less
- Minification
- Pre-image covers the area of greater than one
texel
from Angel
Magnification
Minification
26How Do We Anti-alias?
- In minification, we can combine (average!) many
texel values to compute a pixel color
27Mipmaps
- Approximate the quadrilateral with just a
rectangle - I.e., just assume we have an axis-aligned
rectangle - Construct a hierarchy of textures
- Sample the texture at difference scales
(resolutions) - This is called a Level of Detail (LOD)
- Assume your texture has a power of two resolution
- Compute a new texture by averaging four
neighboring texel value together - Do step 2 again with the new texture
- Each new texture is a pre-filtered
(reconstructed?) version of the original texture
where a texel covers larger and larger areas
28Mipmaps
- Mipmap A hierarchy of pre-filtered textures
- Match your pre-image to a pre-computed average
- Compute the area of your pre-image
- Index to the level you need, i.e. which LOD
texture - Nearest or linear filtering in the LOD texture
29Mipmap Construction Storage
- Simple construction
- OpenGL will automatically generate this for you
- Easy storage
- Fits into a single 2D texture
30Anti-aliasing With Mipmaps
Aliased
Anti-aliased
31Common Approaches To Do Anti-Aliasing
- Quantization
- Use higher precision values
- Sampling
- Use a higher sampling rate
- Reconstruction
- Use higher order filters
- For example, mipmapping
32Higher Sampling Rate
- Raytracing
- One ray/pixel
- Pixel centers
- Computational Cost?
- 512 512 262,144 rays
- Well just primary rays
Poor ray sampling due to the view angle and
perspective projection
33Higher Sampling Rate
- Supersampling
- 16 rays/pixel
- Spread across a pixel
- Computational Cost?
- 512 512 16 4,194,304 rays
High frequencies are diminishing! Looks averaged
some what
34Higher Sampling Rate
- Supersampling
- 256 rays/pixel
- Spread across a pixel
- Computation time?
- 512 512 256 67,108,864 rays
High frequencies are diminishing! Looks more
averaged and the speckly artifacts are greatly
diminished.
35Signal Theory
- Signal Theory (an unpopular term) can help us
- Understand why an anti-aliasing method works or
does not work - Discover methods
36Sampling Theorem
- Questions you should ask yourself
- Why does supersampling work?
- How many samples are enough?
- Shannons Sampling Theorem
-
- Lets assume regularly (equally?) spaced samples
- Almost always done in practice
- When sampling a signal at discrete intervals,
the sampling frequency must be greater than twice
the highest frequency of the input signal in
order to be able to reconstruct the original
perfectly from the sampled version. This maximum
frequency is called the Nyquist limit.
37A Cosine Example
- Consider the function f (x) cos(2px) and a
regular sampling
- Given the samples, how do we reconstruct the
function?
38A Cosine Example
- Consider the function f (x)cos(12px) at a higher
frequency, but same sampling rate
- OK, we get aliasing. Sampling rate is too low.
39A Cosine Example
- Take our first function and reduce the sampling
frequency - Nyquist limit ½ sampling frequency
- Can we reconstruct the function exactly?
- The sampling theorem says yes, since our
sampling rate is sufficient compared with the
Nyquist limit - What reconstruction filter should we use?
40Sampling Grid
- We can generate the table values by multiplying
the continuous image function by a sampling grid
of Kronecker delta functions.
41Sampling Density
- How densely must we sample an image?
- If the scene is well understood then we have a
chance - If it has complex textures and such, then it is
difficult - If we under-sample the signal, we won't be able
to accurately reconstruct it
42More Theory Fourier Analysis
- So, what are the frequency characteristics of a
function? - Fourier Analysis defines a feature space (called
Fourier Space or the Frequency Domain) that can
show us the frequency characteristics of a
function - Lets define this space
43Fourier Analysis Harmonics
- This formulation is defined around periodic
signals - All periodic signals can be represented as a
summation of sinusoidal waves
44Fourier Transform
- The Fourier transform defines a conversion
between our function (spatial domain, i.e. f (x,
y)) into Fourier space (frequency domain, i.e.
F(u, v)) and vice versa
spatial domain
frequency domain
Fourier Transform
Inverse Fourier Transform
45Frequency Space
- Every periodic signal in the spatial domain has a
dual in the frequency domain - The u-axis tells us that a particular frequency
is present in the function and the v-axis tells
us how much - A bandlimited function
- A function which has no frequencies above some
threshold
frequency domain
spatial domain
46The Convolution Operator
- The convolution operator g f Ä h
- Combines two functions to produce a third
function by shifting and multiplying one function
with another
47Duality of Convolution And Multiplication
- Convolution in the spatial domain is the same as
multiplication in the frequency domain - Convolution in the frequency domain is the same
as multiplication in the spatial domain
48Sampling And Fourier Space
Fourier Transform
samplinggrid
(multiplication)
(convolution)
Fourier Transform
sampledsignal
49Aliasing Due To Insufficient Sampling
- Aliasing due to sampling is seen in the frequency
domain as overlapping of the function copies - Fourier Analysis tells us that as the sampling
rate is increased there is less overlap between
the copies
50Sampling Theorem Revisited
- In order to have any hope of accurately
reconstructing a function from a periodically
sampled version of it, two conditions must be
satisfied - The function must be bandlimited
- The sampling frequency, fs, must be at least
twice the maximum frequency, fmax, of the
function (Nyquist Limit)
51Reconstruction
- Given a sampled version of a function, how do we
evaluate (reconstruct?) the function at
non-sampled locations? - Filtering Combine the sample(s) to compute a
function value
52Reconstruction
- We have two possible scenarios
- Problem How do we best filter the samples to
reconstruct?
No aliasing
Aliasing
53Reconstruction
- Solution Extract a copy of the original signal
from the frequency domain of the sampled signal,
then we can reconstruct the original signal! - This just gets rid of the high frequencies wait
we did this before?
No aliasing
Aliasing
54Reconstruction Filters
- Reconstruction filter A method to combine one of
more samples to compute the function at any
location - Most filters usually use a neighborhood of
samples - A weight is applied to each neighborhood sample
and then added together ... sounds like averaging!
55Reconstruction Filters
- Goal Come up with a filter we can use in the
spatial domain that will only pass our original
function in the frequency domain - If we didnt sample high enough, we are out of
luck - but can at least get rid of as much of the
higher frequencies as we can
56Nearest Neigbhor Interpolation (Box Filter)
- Box filter Weight each sample with equal weight
- Nearest neighbor uses a neighborhood of one sample
spatial
Our Goal!
frequency
High frequencies are still present L
57The Box Filter is a Bad Filter To Use Why?
- Reconstruct a function in a pixel with a single
value a pixel is not a square
58The Box Filter is a Bad Filter To Use Why?
Original high-resolution image
ugly horizontal banding
59Bilinear Interpolation (Tent Filter)
- Tent filter Reduce the weight of each sample as
a linear ramp from the neighborhood center
spatial
frequency
High frequencies still present L But diminished!
Smoothing
60Filter Problems
- Visible artifacts are caused by poor
reconstruction filters - Two forces at play
- Pass-band attenuation cut off too narrow
- Cut out too many needed higher frequencies
results in blurry images - High-frequency leakage filter extends too much
- Let in unwanted higher frequencies results in
"ringing" and can accentuate the sampling grid
frequency
61Reconstruction Filter Terminology
- Low-pass filter Reduces high frequency leakage
- For example, averaging smoothing
- High-pass filter Increases high frequency
leakage - For example, nearest neighbor
- What is a good filter?
- Look at its frequency domain profile and see what
you get
62Better Filters?
- Gaussian filter Reduce the weight of each sample
as an exponential drop off from the neighborhood
center
spatial
frequency
What do you notice?
63Gaussian Filter
- We can change the width of the Gaussian
- A control for pass-band attenuation and
high-frequency leakage
spatial
frequency
64A Pixel Is Not A Square
- Not on your CRT display anyway each pixel is
reconstructed with a Gaussian filter
65Bi-Cubic Interpolation (Cubic Filter)
- Cubic filter The weights fit a cubic function
spatial
frequency
What do you make of this one?
66The Ideal Filter (The Sinc Function)
- OK is there a filter that will give us exactly
what we want??? - Answer Yes! ?
- Why didnt I just give you that?
- Its impractical to use L
spatial
frequency
67Reconstruction A Summary
- Order reconstruction filters according to ease of
computation - Box
- Tent
- Gaussian
- Cubic
- Sinc
- Infinite extent means need all samples in the
neighborhood - Expensive to almost impossible to compute!
- Reconstruction depends upon how you performed
sampling - You didnt sample enough means you have
overlapping copies means you will have
aliasing! - I.e., no reconstruction filter is going to come
to your rescue
68Temporal Aliasing
- Have you ever noticed when looking at a fast
rotating object that it reverses direction? - An electric fan or a car wheel on the highway
- We have an under-sampling problem in time