CS 430/536 Computer Graphics I: Thick Primitives, Halftone Approximation Anti-Aliasing
CS 430/536 Computer Graphics I: Thick Primitives, Halftone Approximation Anti-Aliasing
Computer Graphics I
Thick Primitives,
Halftone Approximation
Anti-aliasing
Week 6, Lecture 11
2
Drawing with Thick Primitives
• How do we thicken
the line stroke width?
• Ideas:
– Place the center of
the circular “brush” on
the pixel
– Place the upper
corner of the square
“marker” on the pixel
(issues of orientation)
– Then do scan
conversion algorithm 3
Three Basic Methods
1. Column Replication
– Use >1 pixel per col/row
2. Trace brush outline
across 1-pixel primitive
3. Trace two copies, t
apart, and fill in
4
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Column(Row) Replication
• Idea: duplicate pixels in
– Columns, when
-1 < slope < 1
– Rows, otherwise
• Thickness t is from
primitive’s boundaries
perpendicular to its tangent
• What happens for even t?
• Issues when lines meet at
angles, when octants
merge, brightness for
sloped lines, etc. 5
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Moving the Pen
• Example:
– a rectangular pen
– Center or corner follows
scan algorithm
• How to implement?
– Idea 1: fill the box at each
point
– Problem: pixels get colored
more than once
– Idea 2: fill by using a span of
the pen primitive at each
step
6
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Halftone Approximation
• Not all devices can display all colors
– e.g. GIF is only 256 colors
• Idea: With few available shades,
produce illusion of many colors/shades?
• Technique: Halftone Approximation
• Example: How do we do greyscale with
black-and-white monitors?
7
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation
• Technique: Dithering
• Idea: create meta-pixels, grouping base
pixels into 3x3s or 4x4s
• Example: a 2x2 dither matrix for grayscale
8
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation
• Issues with Dithering
– Image is now 4x in size
• How do we keep image the same size?
• Technique: Error Diffusion
• Idea: When approximating pixel
intensity, keep track of error and try to
make up for errors with later pixels
9
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation:
Error Diffusion Example #1
• Problem: draw 1D line with 1/3 gray tone
• Pixel #1: round to black, 0… error 1/3
• Pixel #2: value 1/3+1/3=2/3, color white
• Pixel #3: value 1/3-1/3=0, color black
• Pixel #4: value 1/3+0= 1/3, color black
• Color sequence: 01001001001…
10
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation:
Error Diffusion Example #1
Draw 1/3 gray line
12
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation:
Error Diffusion Example #2
• Let be the shade of pixel
• To draw we round pixel to nearest
shade and set
• Then, diffuse the errors throughout
surrounding pixels, e.g.
S[x + 1][y] += (7/16) err
S[x - 1][y - 1] += (3/16) err
S[x][y - 1] += (5/16) err
S[x + 1][y - 1] += (1/16) err 13
Pics/Math courtesy of Dave Mount @ UMD-CP
Halftone Approximation:
Error Diffusion Example #2
14
Pics courtesy of Dimitri Gusev @ Indiana
Antialiasing
• Converting an idealized line to a discrete grid
is an approximation
• “Jaggies” are the result
15
1994 Foley/VanDam/Finer/Huges/Phillips ICG
The Aliasing Problem
• General problem in
Analog-to-Digital
conversion
– When sampling, one
needs to sample at a
higher frequency
than the analog
signal
Example: Music CDs
– Aliasing shows up as Sampled: 44Khz
spurious low Max frequency: 22Khz
frequencies 16
1993 ACM SIGGRAPH Education Slide Set
The Aliasing Problem
• General problem in
Analog-to-Digital
conversion
– When sampling, one
needs to sample at a
higher frequency
than the analog
signal
Example: Music CDs
– Aliasing shows up as Sampled: 44Khz
spurious low Max frequency: 22Khz
frequencies 17
1993 ACM SIGGRAPH Education Slide Set
Zone plate
• Zone plate
– f(x,y) = x2 + y2
– Black if floor(f) odd, else
white
• Outer rings occur too often to
be sampled correctly
• Moiré patterns resemble the
zone plate
18
Compiled
from:
Lecture
notes
of
Dr.
John
C.
Hart
@
University
of
Illinois
Aliasing in Computer Graphics
• Mathematical model
of image: analog
• Screen: digital
• Result: visual
effects, jaggies, lost
textures and detail
19
1993 ACM SIGGRAPH Education Slide Set
Antialiasing in use…
20
Antialiasing
• How to create the
visual effect of Two major categories of
smoothing the line? anti-aliasing techniques:
(1) PreFiltering
• We need to find a (2) PostFiltering
way to simulate the
display of partial
pixels
21
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Antialiasing: PreFiltering
• Idea:
– each pixel has area
– compute color based
on overlap with the
object’s area
• Result: smoother
borders for
objects
22
1993 ACM SIGGRAPH Education Slide Set
Antialiasing: PostFiltering
(SuperSampling)
• Idea:
– take multiple samples for each pixel
– create weighted measure of color
– samples can be stochastic or regular
– stochastic makes for more pleasing results 23
1993 ACM SIGGRAPH Education Slide Set
Antialiasing: PostFiltering
• Filters: the weighted measure of color
– weighted or unweighted average of the pixels
24
1993 ACM SIGGRAPH Education Slide Set
Antialiasing of Lines & Curves
• Example: draw 1-pixel thick black line
2 different screen resolutions =>
2x jags, jags 1/2 size, but 4x memory!
25
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Antialiasing of Lines & Curves
29
Anti-aliasing of Circles and Curves
• Super-sampling can be applied to anti-aliasing of circles
and curves
• Double (triple,quadruple) the resolution of your buffer.
• Draw the circle of the curve with double
(triple,quadruple) width
• Compute the color of each pixel by counting the
number of colored sub-pixels
30
Antialiasing with Grayscales
31
From HW of Adrian Burka
Antialiasing with Grayscales
32
From HW of Adrian Burka
Anti-aliasing from CG II
Steven Thomas 33
Antialiasing Example
34
1993 ACM SIGGRAPH Education Slide Set