Post on 25-Aug-2018
Aliasing10/4/2010
CGGC1
(Anti)Aliasing
and
Image Manipulation
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
Image[x][y] = 127 + 128 *
sin((SQR(x – Size2) +
SQR(y – Size2)) /
32.0);
}
} // Size2 = Size / 2; Aliasing - Center for Graphics and Geometric Computing, Technion 2
Aliasing
Can’t draw smooth lines on
discrete raster device – get
staircased lines (“jaggies”):
Images with too fine
details create artifacts
(Moire patterns)
Why? How to solve?
Aliasing - Center for Graphics and Geometric Computing, Technion 3
Antialiasing
Aliasing - Center for Graphics and Geometric Computing, Technion 4
Antialiasing
Aliasing - Center for Graphics and Geometric Computing, Technion 5
Sampling
2D raster image = discrete sampling of
continuous image (signal)
Consider 1D signal sampling
Aliasing - Center for Graphics and Geometric Computing, Technion 6
Sampling
2D raster image = discrete sampling of
continuous image (signal)
Consider 1D signal sampling
Aliasing10/4/2010
CGGC2
Aliasing - Center for Graphics and Geometric Computing, Technion 7
Sampling
2D raster image = discrete sampling of
continuous image (signal)
Consider 1D signal sampling
Aliasing - Center for Graphics and Geometric Computing, Technion 8
Sampling
2D raster image = discrete sampling of
continuous image (signal)
Consider 1D signal sampling
Aliasing - Center for Graphics and Geometric Computing, Technion 9
Sampling Theory in a Nutshell
Terminology
Cycle – a repeated sequence over infinite signal
Frequency – number of cycles in a unit length
Example – sine wave
Cycle = 2
Frequency = 1/ 2
Aliasing - Center for Graphics and Geometric Computing, Technion 10
Sampling Theory
Theorem: Any periodic signal can be represented as
(infinite) sum of sine waves, at different frequencies
Can represent signal using coefficients of the sine
waves - alternative basis used by Fourier Analysis
Fourier Transform- Tool to transform to/from sine
basis, to/from the frequency domain
Aliasing - Center for Graphics and Geometric Computing, Technion 11
Example A square wave is represented by infinite sum
First few components:
...5
)5sin(
3
)3sin()sin()(
ttttSqrWave
Aliasing - Center for Graphics and Geometric Computing, Technion 12
Shannon Sampling Theorem
Shannon Theorem: Any signal that is band-limited to
frequency fmax and sampled at equally spaced intervals
smaller than ts = 1/(2fmax) can be fully reconstructed
The minimal sampling frequency of ts = 1/(2fmax) is
called the Nyquist frequency of the signal
That this condition is necessary can be trivially shown:
Question: What is the result of this sampling? Aliasing!
Aliasing10/4/2010
CGGC3
Aliasing - Center for Graphics and Geometric Computing, Technion 13
More Aliasing Examples
Sampling high frequency wave below Nyquist frequency
yields results that “look” like a low frequency wave
The appearance of high frequencies as low frequencies,
due to sampling, is called Aliasing:
Aliasing - Center for Graphics and Geometric Computing, Technion 14
Even More Aliasing ExamplesConsider two sine waves: -sin(3t) and sin(5t):
-sin(3t) = sin(5t) is satisfied for t = n / 4
Sampling sin(5t) at ti = i / 4 looks like
sampling sin(3t)
Aliasing - Center for Graphics and Geometric Computing, Technion 15
Aliasing
Aliasing – the appearance of high frequencies
as low frequencies
To avoid
Sample at a higher frequency - only if band-limited
to begin with
A-priori remove high frequencies – Low pass
filtering before sampling
For images – the discrete image is a
sampling set of a continuous image (band
limits?)
Aliasing - Center for Graphics and Geometric Computing, Technion 16
The Fourier Transform
Takes us from the spatial domain to the
frequency domain:
The inverse Fourier transform equals
We will see some examples shortly
dxexftF itx
)()(
dxexFtf itx
)(
2
1)(
Aliasing - Center for Graphics and Geometric Computing, Technion 17
Convolution
The convolution, denoted by *, is defined as:
Question: What is the intuition behind the
convolution operation?
Theorem: Convolution in the spatial domain
is the same as a multiplication in the
frequency domain and vice-versa
dttxgtfxgf
)()())(*(
Aliasing - Center for Graphics and Geometric Computing, Technion 18
The Fourier Transform (cont’d)
Question: What is the Fourier transform of a hat?
Aliasing10/4/2010
CGGC4
Aliasing - Center for Graphics and Geometric Computing, Technion 19
Convolution
Consider an fmax band-limited signal.
Sampling is the same as multiplying the signal
with equally spaced impulse functions (x):
By the theorem, this operation is equivalent to a convolution in the frequency domain:
Aliasing - Center for Graphics and Geometric Computing, Technion 20
Convolution (cont’d)
During the reconstruction process, we apply a low pass
filter that removes all frequencies above fmax
This ideal filter is a box filter in the frequency domain:
Samples that are less dense in the spatial domain will
become more dense in the frequency domain
Question: What will happen if we sample below the
Nyquist limit
Aliasing - Center for Graphics and Geometric Computing, Technion 21
Convolution (cont’d)We will get aliasing:
The different convolved elements, in the
frequency domain, overlap.
We have high frequencies intermixed with low
frequencies and they are inseparable.
The only way to prevent aliasing is pre-filtering
Aliasing - Center for Graphics and Geometric Computing, Technion 22
Back to Computer Graphics
Question: how all this sampling theory relates
to computer graphics?
When a discrete image Id(x,y) is created, we
are effectively generating a sample set of a
(possibly imaginary) continuous image Ic(x,y)
Extending sampling theory to two dimensions:
Ic(x,y) should be band-limited for it to be
reconstructable
Sampling should be above the Nyquist limit for Ic(x,y)
to be reconstructable
The box filter in the frequency domain is the ideal
low-pass filter (what is it in the spatial domain?)
Aliasing - Center for Graphics and Geometric Computing, Technion 23
Back to Computer Graphics (cont’d)
Question: is Ic(x,y) band-limited?
Question: can we pre-filter Ic(x,y)?
One can reduce aliasing by super-sampling
Question: can we
post-filter the data using
convolution with a sinc
filter in the spatial domain?
22
22sin
yx
yx
Aliasing - Center for Graphics and Geometric Computing, Technion 24
Sinc/Truncated sinc
Box
Triangle (Hat)
Guassian
22
22 )sin(
yx
yx
otherwise,0
1and1,1 yx
otherwise,0
1,1 2222 yxyx
232
343
232
24
1
121
242
121
16
1
111
111
111
9
1
121
252
121
17
1
21012
14641
06960
14641
21012
33
1
12321
24642
36963
24642
12321
81
1
11111
12421
141041
12421
11111
50
1
Common Filters
2
22
2
1yx
e
Aliasing10/4/2010
CGGC5
Aliasing - Center for Graphics and Geometric Computing, Technion 25
Common Filters (cont’d)
All filters are normalized so they sum to one.
Why?
Due to obvious reasons we cannot apply the
infinite filters and must compromise on the
truncated versions
Note the sinc filter can assume negative values
which is a potential for minor problems. Why?
The difference between different filters are quite
minor and most filters of size 44 offers similar
improvements
Aliasing - Center for Graphics and Geometric Computing, Technion 26
Filter results
Gaussian
Box
Unfiltered
Aliasing - Center for Graphics and Geometric Computing, Technion 27
Supersampling Example
None 3x3 5x5
Aliasing - Center for Graphics and Geometric Computing, Technion 28
A Word on Temporal Aliasing
So far we dealt with Spatial Aliasing
In animation, aliasing could also occur between one frame and the
next
This aliasing is known as Temporal Aliasing
Recall that in a movie each
frame represents a finite
time range of 1/25 or 1/30
of a second.
Hence, it would serve better
to accumulate the influence
of moving objects over this time
Aliasing - Center for Graphics and Geometric Computing, Technion 29
Motion Blur
The technique of
Motion Blur
accumulates the affect
of each object over the
time step of the frame
The result will look like
the image on the right
Playing animation with
motion blur is more
natural to the eye
Aliasing - Center for Graphics and Geometric Computing, Technion 30
Image ManipulationImage operations
Scaling
Rotation
Composition
Scientific American,
Feb 1994
Aliasing10/4/2010
CGGC6
Aliasing - Center for Graphics and Geometric Computing, Technion 31
Consider Linear Transformation L of image I:
What is wrong with this algorithm?
Image Scaling & Rotation
);,()),((
to0 from For
to0 from For
color background toclear
),ans(ImageLinTr
yxIyxLI
YMax(I)y
XMax(I)x
I
LI
Aliasing - Center for Graphics and Geometric Computing, Technion 32
Guarantee coverage – iterate over target
What can be wrong with this algorithm? Any
reason to limit L to a linear transformations?
Correct Image Scaling & Rotation
));,((),(
to0 from For
to0 from For
color background toclear
),ans(ImageLinTr
1 yxLIyxI
YMax(I)y
XMax(I)x
I
LI
Aliasing - Center for Graphics and Geometric Computing, Technion 33
Image Transformations
Each pixel in the target image is computed from a single source pixel – prone to Aliasing
Solution in filtering
A pixel in target image is
some affine combination
of several source pixels
Coefficients based on area coverage
Aliasing - Center for Graphics and Geometric Computing, Technion 34
Rotation By ShearConvenient for images as it
involved only intra-row or
intra-column operations
Rotation can be performed
by two shears – can be lossy
for large angles
Image size might be reduced in intermediate stage
Rotation by three shears is lossless up to
integer precision.
y
x
y
x
cossin
sincos
12
tan
01
10
sin1
12
tan
01
cossin
sincos
Aliasing - Center for Graphics and Geometric Computing, Technion 35
Image Composition
+
=
Aliasing - Center for Graphics and Geometric Computing, Technion 36
CompositionBasic Method
Will work until portion of foreground has
background color
Unfortunately we are facing more problems
);,(),(
else
);,(),(
color background),( if
to0 from For
to0 from For
color background toclear
),ompose(ImageOverC
1
2
1
21
yxIyxI
yxIyxI
yxI
YMax(I)y
XMax(I)x
I
II
Aliasing10/4/2010
CGGC7
Aliasing - Center for Graphics and Geometric Computing, Technion 37
Composition (cont’d)Question: This is the result of applying the
basic algorithm to teapot-over-white-
background. What is going on?
Aliasing - Center for Graphics and Geometric Computing, Technion 38
Composition (cont’d)
The reason for this behavior could be found in
the filtering (anti-aliasing) conducted during
the rendering process
On the boundary there exist pixels that are
only partially covered by the teapot
Rendered with black background,
these boundary pixels are darker
Yet, as dark as they are, they are
not black and hence they are
being copied verbatim
Question: Any remedy?
Aliasing - Center for Graphics and Geometric Computing, Technion 39
Composition (cont’d)
A background pixel has zero coverage while a
pixel totally contained in the teapot’s projection
will have a coverage of one.
This coverage information is also known as
the Alpha channel that accompanies the RGB
Question: How can we compute
the Alpha channel?
Question: How can we use the
Alpha channel to resolve this
boundary problem?
Aliasing - Center for Graphics and Geometric Computing, Technion 40
Composition (cont’d)
T – Teapot, S - Sand
Out: S(1 - T)
In: ST
Over: TT + S(1 - T)
Aliasing - Center for Graphics and Geometric Computing, Technion 41
Composition
(cont’d)
Scientific American,
Feb 1994
Aliasing - Center for Graphics and Geometric Computing, Technion 42
Special Effects – “Chroma Key”