Anti-Aliasing - PowerPoint PPT Presentation

About This Presentation
Title:

Anti-Aliasing

Description:

Recall, multiplication by the sampling function is equivalent to convolution in ... Summed Area Table (SAT) Use an axis aligned ... Summed Area Table (SAT) ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 105
Provided by: hua81
Learn more at: https://web.eecs.utk.edu
Category:

less

Transcript and Presenter's Notes

Title: Anti-Aliasing


1
Anti-Aliasing
  • Jian Huang, CS594, Fall 2003
  • This set of slides are revised from those used at
    Ohio State by Prof. Roger Crawfis.

2
Anti-aliasing?
3
Aliasing
  • Aliasing comes from in-adequate sampling rates of
    the continuous signal
  • The theoretical foundation of anti-aliasing has
    to do with frequency analysis
  • Its always easier to look at 1D cases, so lets
    first look at a few of those.

4
Example of Sampling
5
Examples of Inadequate Sampling
6
Cosine Integrations
  • Consider these formulas

7
Improper Cosine Integrals
  • Evaluating from (-?,?)

8
Fourier Transform
  • The Fourier Transform represents a periodic
    function as a continuous summation of sins and
    coss.

9
Fourier Transform
  • Note
  • This is also called the direct current or DC
    component.

10
Inverse Fourier Transform
  • We can get back our original function f(x) from
    F(u) using the inverse transform

11
OK Why do this?
  • Fourier space is a very good space for analyzing
    and understanding our signals.
  • Rarely ever want to transform to Fourier space.
  • There are some great theories developed in terms
    of sampling and convolution.

12
Fourier Analysis
  • By looking at F(u), we get a feel for the
    frequencies of the signal.
  • We also call this frequency space.
  • Intuitively, you can envision, the sharper an
    edge, the higher the frequencies.
  • From a numerical analysis standpoint, the sharper
    the edge the greater the tangent magnitude, and
    hence the interpolation errors.

13
Fourier Analysis
  • Bandlimited
  • We say a function is bandlimited, if F(u)0 for
    all frequencies ugtc and ult-c.
  • Amplitude Spectrum
  • The magnitude, F(u), is called the amplitude
    spectrum or simply the spectrum.
  • Phase Spectrum or Phase

14
Fourier Properties
  • Linearity
  • Scaling

15
Convolution
  • Definition

16
Convolution
  • Pictorially

f(x)
h(x)
17
Convolution
h(t-x)
f(t)
18
Convolution
  • Consider the function (box filter)

19
Convolution
  • This function windows our function f(x).

f(t)
20
Convolution
  • This function windows our function f(x).

f(t)
21
Convolution
  • This function windows our function f(x).

f(t)
22
Convolution
  • This function windows our function f(x).

f(t)
23
Convolution
  • This function windows our function f(x).

f(t)
24
Convolution
  • This function windows our function f(x).

f(t)
25
Convolution
  • This function windows our function f(x).

f(t)
26
Convolution
  • This function windows our function f(x).

f(t)
27
Convolution
  • This function windows our function f(x).

f(t)
28
Convolution
  • This function windows our function f(x).

f(t)
29
Convolution
  • This function windows our function f(x).

f(t)
30
Convolution
  • This function windows our function f(x).

f(t)
31
Convolution
  • This function windows our function f(x).

f(t)
32
Convolution
  • This function windows our function f(x).

f(t)
33
Convolution
  • This function windows our function f(x).

f(t)
34
Convolution
  • This function windows our function f(x).

f(t)
35
Convolution
  • This function windows our function f(x).

f(t)
36
Convolution
  • This function windows our function f(x).

f(t)
37
Convolution
  • This function windows our function f(x).

f(t)
38
Convolution
  • This function windows our function f(x).

f(t)
39
Convolution
  • This function windows our function f(x).

f(t)
40
Convolution
  • This function windows our function f(x).

f(t)
41
Convolution
  • This particular convolution smooths out some of
    the high frequencies in f(x).

f(x)?g(x)
42
Impulse Function
  • Consider the special function (called impulse)
  • such that,

43
Impulse and Convolution
  • Then, if we take the convolution of f(x) with
    d(x), we get
  • f(x)?d(x) f(x)

44
Sampling Function
  • A Sampling Function or Impulse Train is defined
    by
  • where T is the sample spacing.

T
45
Sampling Function
  • The Fourier Transform of the Sampling Function is
    itself a sampling function.
  • The sample spacing is the inverse.

46
Sampling
  • What we have in computer graphics is a point
    sampling of our scene, or
  • I(x) f(x)ST(x)
  • What we would like is more of an integration
    across the pixel (or larger area)
  • I(x) f(x)? h(x)
  • What should h(x) be?

47
Convolution Theorem
  • The convolution theorem states that convolution
    in the spatial domain is equivalent to
    multiplication in the frequency domain, and vica
    versa.

48
Convolution Theorem
  • This powerful theorem can illustrate the problems
    with our point sampling and provide guidance on
    avoiding aliasing.
  • Consider f(x) ST(x)

f(t)
T
49
Convolution Theorem
  • What does this look like in the Fourier domain?

F(u)
50
Convolution Theorem
  • In Fourier domain we would convolve

F(u)
51
Aliasing
  • What this says, is that any frequencies greater
    than a certain amount will appear intermixed with
    other frequencies.
  • In particular, the higher frequencies for the
    copy at 1/T intermix with the low frequencies
    centered at the origin.

52
Aliasing and Sampling
  • Note, that the sampling process introduces
    frequencies out to infinity.
  • We have also lost the function f(x), and now have
    only the discrete samples.
  • This brings us to our next powerful theory.

53
Sampling Theorem
  • The Shannon Sampling Theorem
  • A band-limited signal f(x), with a cutoff
    frequency of l, that is sampled with a sampling
    spacing of T may be perfectly reconstructed from
    the discrete values fnT by convolution with the
    sinc(x) function, provided
  • l is called the Nyquist limit.

54
Sampling Theory
  • Why is this?
  • The Nyquist limit will ensure that the copies of
    F(u) do not overlap in the frequency domain.
  • I can completely reconstruct or determine f(x)
    from F(u) using the Inverse Fourier Transform.

55
Sampling Theory
  • In order to do this, I need to remove all of the
    shifted copies of F(u) first.
  • This is done by simply multiplying F(u) by a box
    function of width 2l.

S(u)
F(u)
l
-l
56
Sampling Theory
  • In order to do this, I need to remove all of the
    shifted copies of F(u) first.
  • This is done by simply multiplying F(u) by a box
    function of width 2l.

S(u)
F(u)
l
-l
57
General Process
58
How? - Convolution
Spatial Domain
Frequency Domain
Mathematicallyf(x)h(x)
  • Multiplication
  • Convolution

Evaluated at discrete points (sum)
59
Reconstruction
Mathematically f(x)h(x) (Sfi)h(x)
Sfi
h(x)
60
General Process - Frequency Domain
61
Pre-Filtering
62
Ideal Reconstruction with Sinc function
  • Spatial Domain
  • convolution is exact
  • Frequency Domain
  • cut off freq. replica

63
Reconstructing Derivatives
  • Spatial Domain
  • convolution is exact
  • Frequency Domain
  • cut off freq. replica

64
Possible Errors
  • Post-aliasing
  • reconstruction filter passes frequencies beyond
    the Nyquist frequency (of duplicated frequency
    spectrum) gt frequency components of the original
    signal appear in the reconstructed signal at
    different frequencies
  • Smoothing
  • frequencies below the Nyquist frequency are
    attenuated
  • Ringing (overshoot)
  • occurs when trying to sample/reconstruct
    discontinuity
  • Anisotropy
  • caused by not spherically symmetric filters

65
How Good? Error
  • Spatial Domain
  • local error
  • asymptotic error
  • numerical error
  • Frequency Domain
  • global error
  • visual appearance
  • blurring
  • aliasing
  • smoothing

Approximation Theory/Analysis
Signal Processing
66
Sources of Aliasing
  • Non-bandlimited signal
  • Low sampling rate (below Nyquist)
  • Non perfect reconstruction

67
Reconstruction Kernels
stop band
pass band
The spatial extent of reconstruction kernels, or
interpolation basis functions, depend on the
cut-off frequency as well.
filter
68
Reconstruction Kernels
  • Nearest Neighbor (Box)
  • Triangular func
  • Sinc
  • Gaussian

many others
Spatial d.
Frequency d.
69
Higher Dimensions
  • An-isotropic Filters
  • (radially symmetric)
  • separable filters

70
Interpolation (an example)
  • Very important regardless of algorithm
  • expensive gt done very often for one image
  • Requirements for good reconstruction
  • performance
  • stability of the numerical algorithm
  • accuracy

Linear
Nearest neighbor
71
Put Things in Perspective
  • In graphics, need to use continuous space
    functions. But can only work with discrete data.
    So, lets reconstruct from discrete data to
    continuous space (convolution) and resample
  • Interpolation is doing the same thing. Computing
    one data point in the resulting function, say, at
    x1.
  • So, which reconstruction kernel (basis function)
    does linear/bilinear/tri-linear interpolations
    use?

72
A Cosine Example
  • Consider the function f(x)cos(2px).

f(x)
x
F(u)
u
73
Sampling Theory
  • So, given fnT and an assumption that f(x) does
    not have frequencies greater than 1/2T, we can
    write the formula
  • fnT f(x) ST(x) ? F(u)? ST(u)
  • F(u) (F(u)? ST(u)) Box1/2T(u)
  • therefore,
  • f(x) fnT ? sinc(x)

74
A Cosine Example
  • Now sample it at T½

f(x)
x
F(u)
u
1
75
A Cosine Example
  • Problem
  • The amplitude is now wrong or undefined.
  • Note however, that there is one and only one
    cosine with a frequency less than or equal to 1
    that goes through the sample pts.

F(u)
u
1
76
A Cosine Example
  • What if we sample at T¾?

f(x)
x
F(u)
u
1
77
Supersampling
  • Supersampling increases the sampling rate, and
    then integrates or convolves with a box filter,
    which is finally followed by the output sampling
    function.

f(x)
x
78
Sampling and Anti-aliasing
  • If you can not get rid of it, convert it to noise.

Basic checkerboard
Checkerboard with noise
79
Sampling and Anti-aliasing
  • The images were calculated as follows
  • A 2Kx2K image was constructed and smoothly
    rotated into 3D.
  • For Uniform Sampling, it was downsampled toa
    512x512 image.
  • Noise was added to the image, sharpened and
    thendownsampled for the other one.
  • Both were converted to BW.

80
Sampling and Anti-aliasing
  • The problem
  • The signal is not band-limited.
  • Uniform sampling can pick-up higher frequency
    patterns and represent them as low-frequency
    patterns.

F(u)
81
Sampling and Anti-aliasing
  • Turning the high-frequencies into noise.
  • Recall, multiplication by the sampling function
    is equivalent to convolution in the Fourier
    domain.
  • Fourier transform of noise.

82
Non-uniform Sampling
83
Quality considerations
  • So far we just mapped one point
  • results in bad aliasing (resampling problems)
  • we really need to integrate over polygon
  • super-sampling is not a very good solution
    (slow!)
  • most popular (easiest) - mipmaps

84
Quality considerations
  • Pixel area maps to weird (warped) shape in
    texture space

v
ys
pixel
u
xs
85
Quality considerations
  • We need to
  • Calculate (or approximate) the integral of the
    texture function under this area
  • Approximate
  • Convolve with a wide filter around the center of
    this area
  • Calculate the integral for a similar (but
    simpler) area.

86
Quality considerations
  • the area is typically approxiated by a
    rectangular region (found to be good enough for
    most applications)
  • filter is typically a box/averaging filter -
    other possibilities
  • how can we pre-compute this?

87
Mip-maps
  • An image-pyramid is built.

256 pixels 128 64 32 16 8 4 2 1
88
Mip-maps
  • Find level of the mip-map where the area of each
    mip-map pixel is closest to the area of the
    mapped pixel.

2x2 pixels level selected
89
Mip-maps
  • Pros
  • Easy to calculate
  • Calculate pixels area in texture space
  • Determine mip-map level
  • Sample or interpolate to get color
  • Cons
  • Area not very close restricted to square shapes
    (64x64 is far away from 128x128).
  • Location of area is not very tight.

90
Summed Area Table (SAT)
  • Use an axis aligned rectangle, rather than a
    square
  • Precompute the sum of all texels to the left and
    below for each texel location
  • For texel (u,v), replace it with sum
    (texels(i0u,j0v))

91
Summed Area Table (SAT)
  • Determining the rectangle
  • Find bounding box and calculate its aspect ratio

92
Summed Area Table (SAT)
  • Determine the rectangle with the same aspect
    ratio as the bounding box and the same area as
    the pixel mapping.

93
Summed Area Table (SAT)
  • Center this rectangle around the bounding box
    center.
  • Formula
  • Area aspect_ratioxx
  • Solve for x the width of the rectangle
  • Other derivations are also possible using the
    aspects of the diagonals,

94
Summed Area Table (SAT)
  • Calculating the color
  • We want the average of the texel colors within
    this rectangle

(u4,v4)
(u3,v3)

-

-
(u2,v2)
(u1,v1)

-

-
95
Summed Area Table (SAT)
  • To get the average, we need to divide by the
    number of texels falling in the rectangle.
  • Color SAT(u3,v3)-SAT(u4,v4)-SAT(u2,v2)SAT(u1,v1
    )
  • Color Color / ( (u3-u1)(v3-v1) )
  • This implies that the values for each texel may
    be very large
  • For 8-bit colors, we could have a maximum SAT
    value of 255nxny
  • 32-bit pixels would handle a 4kx4k texture with
    8-bit values.
  • RGB images imply 12-bytes per pixel.

96
Summed Area Table (SAT)
  • Pros
  • Still relatively simple
  • Calculate four corners of rectangle
  • 4 look-ups, 5 additions, 1 mult and 1 divide.
  • Better fit to area shape
  • Better overlap
  • Cons
  • Large texel SAT values needed
  • Still not a perfect fit to the mapped pixel.

97
Elliptical Weighted Average (EWA) Filter
  • Treat each pixel as circular, rather than square.
  • Mapping of a circle is elliptical in texel space.

ys
v
pixel
xs
u
98
EWA Filter
  • Precompute?
  • Can use a better filter than a box filter.
  • Heckbert chooses a Gaussian filter.

99
EWA Filter
  • Calculating the Ellipse
  • Scan converting the Ellipse
  • Determining the final color (normalizing the
    value or dividing by the weighted area).

100
EWA Filter
  • Calculating the ellipse
  • We have a circular function defined in (x,y).
  • Filtering that in texture space h(u,v).
  • (u,v) T(x,y)
  • Filter h(T(x,y))

101
EWA Filter
  • Ellipse
  • ?(u,v) Au2 Buv Cv2 F
  • (u,v) (0,0) at center of the ellipse
  • A vx2 vy2
  • B -2(uxvy uyvx)
  • C ux2 uy2
  • F uxvy uyvx

102
EWA Filter
  • Scan converting the ellipse
  • Determine the bounding box
  • Scan convert the pixels within it, calculating
    ?(u,v).
  • If ?(u,v) lt F, weight the underlying texture
    value by the filter kernel and add to the sum.
  • Also, sum up the filter kernel values within the
    ellipse.

103
EWA Filter
  • Determining the final color
  • Divide the weighted sum of texture values by the
    sum of the filter weights.

104
EWA Filter
  • What about large areas?
  • If m pixels fall within the bounding box of the
    ellipse, then we have O(n2m) algorithm for an nxn
    image.
  • m maybe rather large.
  • We can apply this on a mip-map pyramid,rather
    than the full detailed image.
  • Tighter-fit of the mapped pixel
  • Cross between a box filter and gaussian filter.
  • Constant complexity - O(n2)
Write a Comment
User Comments (0)
About PowerShow.com