Академический Документы
Профессиональный Документы
Культура Документы
Processing
Sixteen lectures
Part IB
Part II(General)
Diploma
Scene
description
Computer
graphics
Image processing
Scene
description
Computer
graphics
printed output
monitor (CRT/LCD/whatever)
all visual computer output consists of real images
generated by the computer from some internal
digital image
Image
capture
Image
display
Image processing
2D computer graphics
Image processing
Course Structure
Background [3L]
3D CG
3D computer graphics
2D CG
IP
Background
Course books
10
What is an image?
IP
Background
the course was so different back then that they are not helpful
3D CG
2D CG
Background
11
12
Image capture
a variety of devices can be used
scanners
cameras
area CCD
13
14
Image display
a digital image is an array of integers, how do
you display it?
reconstruct a real image on some sort of
display device
A real image
A digital image
15
Displayed on a CRT
Nearest-neighbour
e.g. LCD
Gaussian
e.g. CRT
16
Half-toning
e.g. laser printer
17
18
Sampling
a digital image is a rectangular array of
intensity values
each value is called a pixel
Sampling resolution
256256
128128
6464
3232
22
44
88
1616
picture element
19
20
Quantisation
Quantisation levels
8 bits
(256 levels)
7 bits
(128 levels)
6 bits
(64 levels)
5 bits
(32 levels)
1 bit
(2 levels)
2 bits
(4 levels)
3 bits
(8 levels)
4 bits
(16 levels)
21
22
The retina
23
adaptation
24
Simultaneous contrast
as well as responding to changes in overall
light, the eye responds to local changes
persistence
25
26
Mach bands
Ghost squares
27
28
Foveal vision
two classes
rods
cones
high resolution
colour
lower resolution
principally monochromatic
29
30
objects
eyes
transmission
reflection
31
32
Classifying colours
33
34
Colour vision
three axes
MIN Fig 4
Colour plate 1
35
36
medium
long
medium
long
medium
short
short
luminance
red-green
yellow-blue
colour-blindness effects
why red, yellow, green and blue are perceptually important
why you can see e.g. a yellowish red but not a greenish red
Chromatic metamerism
37
38
green
green
blue
light
off
red
light
fully on
red
blue
XYZ colour space was defined in 1931 by the Commission Internationale de l clairage (CIE)
39
40
Y
y=
,
X +Y +Z
Z
z=
x + y + z =1
X +Y +Z
ignores luminance
can be plotted as a 2D function
41
42
Colour spaces
CIE XYZ, Yxy
Pragmatic
Munsell-like
used because they relate directly to the way that the hardware
works
FvDFH Fig 13.28
RGB, CMY, CMYK
Uniform
43
44
45
46
Colour images
base + 1 + 5 2
4
3
2
1
0
8 bits = 1 byte
an image of size W H can therefore be stored in
a block of W H bytes
one way to do this is to store pixel[x][y] at
memory location base + x + W y
5
base
0 1 2 3 4
47
48
Double buffering
frame
buffer
output
stage
(e.g. DAC)
display
B
U
S
output
stage
(e.g. DAC)
display
49
50
Image display
active displays
laser printers
ink jet printers
several other technologies
51
52
better
PAL 50Hz
768x576
NTSC 60Hz
640x480
80-90Hz
Flicker/resolution
trade-off
53
54
Printers
many types of printer
ink jet
dot matrix
laser printer
55
56
Printer resolution
laser printer
ink jet
phototypesetter
achieved by halftoning
up to about 3000dpi
57
58
direction of travel
JMF Fig 9b
inks are not perfect aborbers
mixing C + M + Y gives a muddy grey, not black
lots of text is printed in black: trying to align C, M
and Y perfectly for black text would be a nightmare
59
Standard angles
Magenta 45
Cyan
15
Yellow
90
Black
75
150 lpi 16 dots per cell
= 2400 dpi phototypesetter
(1616 dots per cell = 256
intensity levels)
60
3D CG
2D Computer Graphics
lines
2D CG
IP
Background
curves
clipping
filled areas
transformations
applications
10
61
62
y = mx + c
the slope of
the line
1
x
63
64
y+1
y+
y
y-
x-
x-1
x-1
x+
x+1
(x0,y0)
x+1
65
Iteration
assumes
integer end
points
d
yi
y
(x0,y0)
x
x+1
yi
d
y & y
yi
66
J. E. Bresenham, Algorithm for Computer Control of a Digital Plotter, IBM Systems Journal, 4(1), 1965
11
Speed up B:
67
dy = (y1 - y0)
dx = (x1 - x0)
x = x0
yf = 0
y = y0
DRAW(x,y)
WHILE x < x1 DO
x=x+1
yf = yf + 2dy
IF ( yf > dx ) THEN
y=y+1
yf = yf - 2dx
END IF
DRAW(x,y)
END WHILE
y
(x0,y0)
yi = y+yf
x+1
y+yf
y & y
y+yf
69
70
68
k = ax + by + c
2nd
1st
Exercise: work out what
changes need to be made
to the algorithm for it to
work in each of the other
three octants
4th
5th
6th
7th
k<0
k=0
k>0
8th
71
72
d = a( x + 1) + b( y + 12 ) + c
if < 0 then go E
= d +a
12
73
74
y
x
x+1
Iteration
a = (y1 - y0)
b = -(x1 - x0)
c = x1 y0 - x0 y1
x = ROUND(x0)
y = ROUND(y0-(x- x0)(a / b))
d = a * (x+1) + b * (y+) + c
DRAW(x,y)
(x0,y0)
Midpoint - comments
First decision
point
E case
just increment x
NE case
increment x & y
75
76
Curves
2
2
2
decision variable can be d = x + y r
Overhauser cubics
NURBS
77
78
= d + 2x + 3
13
79
80
Why cubics?
higher orders:
81
82
Hermite cubic
Bezier cubic
+ ( 2t 3 + 3t 2 ) P1
P( t ) = (1 t )3 P0
+ ( t 3 2t 2 + t )T0
P2
+ 3t (1 t ) 2 P1
+ ( t 3 t 2 )T1
P1
+ 3t 2 (1 t ) P2
+ t 3 P3
where:
Pi ( x i , y i )
P0
P3
Pierre Bzier worked for Citron in the 1960s
83
84
Bezier properties
Bezier is equivalent to Hermite
T0 = 3( P1 P0 ) T1 = 3( P3 P2 )
C0 continuous in position
discontinuous in position
b (t ) = 1
i
smooth join
corner
i= 0
14
85
(x0,y0) = Bezier(0)
FOR t = 0.05 TO 1 STEP 0.05 DO
(x1,y1) = Bezier(t)
DrawLine( (x0,y0), (x1,y1) )
(x0,y0) = (x1,y1)
END FOR
problems:
86
87
88
Q0 = P0
R0 = 18 P0 + 83 P1 + 83 P2 + 18 P3
Q1 = 12 P0 + 12 P1
R1 = 14 P1 + 12 P2 + 14 P3
Q2 = 14 P0 + 12 P1 + 14 P2
R2 = 12 P2 + 12 P3
Q3 = 18 P0 + 83 P1 + 83 P2 + 18 P3
R3 = P3
Exercise: prove that the Bezier cubic curves defined by Q0, Q1, Q2, Q3 and R0, R1, R2, R3
match the Bezier cubic curve defined by P0, P1, P2, P3 over the ranges t[0,] and
t[,1] respectively
how do we do this?
see the next slide
89
90
Overhausers cubic
method
(potential) problem
15
91
92
This can also be applied to chains of Bezier curves at high resolution: most of the curves
will each be approximated (by the previous algorithm) as a single line segment, Douglas
& Pckers algorithm can then be used to further simplify the line chain
93
94
Clipping
y = yT
x xL
y = yT
y = yB
x xR
y = yB
y yB
x = xL
y yT
x = xR
x = xL
x = xR
95
96
Cohen-Sutherland clipper 1
y = yT
1001
1000
y = yB
0001
0000
ABCD
Q1= Q2 =0
Q1 Q2 0
otherwise
0101
0100
1010
x = xL
ABCD
Cohen-Sutherland clipper 2
0010
0110
x = xR
Ivan Sutherland is one of the founders of Evans & Sutherland, manufacturers of flight simulator systems
Example
P1''
y = yB
P1
P1'
x1 ' = x L
0000
0010
1010
y1 '' = y B
y1 ' = y1 + ( y 2 y1 )
x L x1
x 2 x1
y B y1 '
y 2 y1 '
x = xL
16
97
98
Cohen-Sutherland clipper 3
Polygon filling
y = yT
y = yB
x = xL
x = xR
99
100
ntake all polygon edges and place in an edge list (EL) , sorted on
lowest y value
ostart with the first scanline that intersects the polygon, get all
edges which intersect that scan line and move them to an active
edge list (AEL)
pfor each edge in the AEL: find the intersection point with the
current scanline; sort these into ascending order on the x value
qfill between pairs of intersection points
rmove to the next scanline (increment y); remove edges from
the AEL if endpoint < y ; move new edges from EL to AEL if start
point y; if any edges remain in the AEL go back to step p
101
Clipping polygons
102
17
103
104
the algorithm progresses around the polygon checking if
each edge crosses the clipping line and outputting the
appropriate points
inside outside
inside outside
inside outside
i
nothing
output
i output
e output
inside outside
i and e output
Sutherland & Hodgman, Reentrant Polygon Clipping, Comm. ACM, 17(1), 1974
105
106
2D transformations
scale
Basic 2D transformations
why?
rotate
translate
(shear)
scale
it is extremely useful to
be able to transform
predefined objects to an
arbitrary location,
orientation, and size
any reasonable graphics
package will include
transforms
about origin
by angle
translate
2D Postscript
3D OpenGL
y ' = my
rotate
x ' = mx
about origin
by factor m
shear
x' = x + xo
y' = y + yo
x ' = x + ay
y' = y
parallel to x axis
by factor a
107
x' m 0 x
y ' = 0 m y
rotate
108
Homogeneous 2D co-ordinates
( x , y , w ) ( wx , wy )
do nothing
identity
x ' 1 0 x
y ' = 0 1 y
shear
x ' 1 a x
y ' = 0 1 y
( x , y ) ( x , y ,1)
18
109
110
x ' 1 0
y ' = 0 1
w' 0 0
x ' m 0 0 x
y ' = 0 m 0 y
w' 0 0 1 w
do nothing
rotate
In homogeneous coordinates
shear
identity
x ' = x + wx o
y ' = y + wy o
w' = w
x ' 1 a 0 x
y ' = 0 1 0 y
w' 0 0 1 w
x ' 1 0 0 x
y ' = 0 1 0 y
w' 0 0 1 w
xo x
y0 y
1 w
In conventional coordinates
x' x
= + x0
w' w
y' y
= + y0
w' w
111
112
Concatenating transformations
x ''
y '' =
w''
m
0
scale
0 0 x '
m 0 y '
0 1 w'
scale
x'
y' =
w'
shear
rotate by 45
shear
scale by 2
along x axis
1 a 0 x
0 1 0 y
0 0 1 w
both
x '' m 0 0 1 a 0 x m ma
y '' = 0 m 0 0 1 0 y = 0 m
0
w'' 0 0 1 0 0 1 w 0
0 x
0 y
1 w
rotate by 45
scale by 2
along x axis
2 2
1
2
0
2 2
2
2
0
0
1
2
2
0
0
1
0
0
scale
2 0 0
0 1 0
0 0 1
1 2 1 2 0
1
1
0
2
2
0 1
0
rotate
113
114
Bounding boxes
1 0 x o x
y ' = 0 1 y y
o
1 w
w' 0 0
n x'
x ''' 1 0
y ''' = 0 1
w''' 0 0
m 0 0 x '
y '' = 0 m 0 y '
w'' 0 0 1 w'
o x ''
x o m 0 0 1 0 x o x
y o 0 m 0 0 1 y o y
1 0 0 1 0 0
1 w
(xo,yo)
(0,0)
p x '''
1 0
y ''' = 0 1
w''' 0 0
x o x ''
y o y ''
1 w''
19
115
116
R
BBB
BBL
BBR
PL
BBT
yT
BBT
yB
xL
xR
REJECT
ACCEPT
COMPASS
productions
PR
PT
PB
BBB
BBL
BBR
117
118
XOR drawing
e.g. icons
e.g. games
119
120
Application 2: typography
straight lines
filled rectangles
pre-rendered bitmaps
z single resolution (dont scale well)
z use BitBlT to put into frame buffer
outline definitions
z multi-resolution (can scale)
z need to render (fill) to put into frame buffer
20
121
Application 3: Postscript
3D Computer Graphics
2D CG
3D 2D projection
3D versions of 2D operations
122
3D CG
IP
Background
3D scan conversion
sampling
lighting
ray tracing
123
124
3D 2D projection
Types of projection
to make a picture
parallel
e.g. ( x , y , z ) ( x , y )
useful in CAD, architecture, etc
looks unrealistic
radius (3.4)
centre (0,2,9)
e.g. box
size (2,4,3)
centre (7, 2, 9)
orientation (27, 156)
perspective
e.g. ( x , y , z ) ( xz , zy )
things get smaller as they get farther away
looks realistic
125
Viewing volume
126
viewing plane
(screen plane)
( 0,0,0 )
x' = x
d
z
y' = y
d
z
( x, y, z )
21
127
Perspective projection
with an arbitrary camera
3D transformations
128
3D homogeneous co-ordinates
( x , y , z , w ) ( wx , wy , wz )
3D transformation matrices
translation
1
0
0
0
mx
0
0
0
0
1
0
0
identity
0 tx
0 ty
1 tz
0 1
scale
0
my
0
0
0
0
mz
0
1
0
0
0
0
1
0
0
0
0
1
0
0 sin cos
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
0
0
1
sin
0
0 sin 0
1
0
0
0 cos 0
0
0
1
129
130
world
co-ordinates
90 rotation
about x-axis
Viewing transform 1
opposite
faces
viewing
co-ordinates
the problem:
viewing
transform
x
90 rotation
about x-axis
90 rotation
about z-axis
perpendicular
to el
131
132
Viewing transform 2
1
0
T=
0
0
Viewing transform 3
0 ex
0 ey
1 ez
0 1
d el
0
S=
0
0
0
d
el
0
0
0
0
d
el
0
0
0
1
= arccos
0 sin 0
0
0
cos 0
0
0
1
1
0
l '' z
2
l '' x + l '' z
22
133
134
Viewing transform 4
Viewing transform 5
l''' = R 1 l''
0
0
1
0 cos sin
R2 =
0 sin cos
0
0
0
l ''' z
= arccos
2
2
l ''' y + l ''' z
0
0
0
1
(0 , 0 ,
l''' y + l'''z
u'''' = R 2 R 1 u
cos
sin
R3 =
0
0
= ( 0,0, d )
= arccos
sin
cos
0
0
0 0
0 0
1 0
0 1
u'''' y
2
u'''' x + u'''' y
135
136
Viewing transform 6
world
co-ordinates
viewing
transform
viewing
co-ordinates
M = R 3 R 2 R1 S T
137
138
A variety of transformations
object in
object
co-ordinates
modelling
transform
object in
world
co-ordinates
viewing
transform
object in
viewing
co-ordinates
projection
Clipping in 3D
object in
2D screen
co-ordinates
2a
2b
x > z
a
d
x<z
a
d
y > z
b
d
y<z
b
d
y
z
x
23
139
oops!
z
x
a
d
x=z
a
d
y = z
b
d
y=z
b
d
z = zf
z = zb
140
which is
best?
y
z
x
zf
zb
x=a
y = b
y =b
z = zf
z = zb
141
142
Curves in 3D
sphere
where:
P0
P3
Pi ( x i , y i , z i )
143
a non-planar
polygon
144
this vertex is in
front of the other
three, which are all
in the same plane
which is preferable?
24
145
146
P( s, t ) = bi ( s )b j ( t )Pi , j
i=0 j =0
where: b0 ( t ) = (1 t )3
b1 ( t ) = 3t (1 t )2
b2 ( t ) = 3t 2 (1 t ) b3 ( t ) = t 3
P( t ) = bi ( t ) Pi
i=0
147
148
C0 continuous in position
149
150
Final quadrilateral
mesh
Nave
triangulation
More intelligent
triangulation
25
151
152
3D scan conversion
3D line drawing
lines
polygons
depth sort
Binary Space-Partitioning tree
z-buffer
A-buffer
ray tracing
153
154
3D polygon drawing
155
156
split
split
n
o
o
OK
q
n
26
157
158
tests get
more
expensive
if all 5 tests fail, repeat p and q with P and Q swapped (i.e. can I
draw Q before P?), if true swap P and Q
otherwise split either P or Q by the plane of the other, throw away
the original polygon and insert the two pieces into the list
159
160
8
8
the BSP tree trades off an initial time- and spaceintensive pre-processing step against a linear display
algorithm (O(N)) which is executed whenever a new
viewpoint is specified
the BSP tree allows you to easily determine the
correct order in which to draw polygons by traversing
the tree in a simple way
161
162
all polygons on the far side of it from the viewer are scanconverted first
then it is scan-converted
then all the polygons on the near side of it are scanconverted
27
163
164
Scan-line algorithms
draw the BSP tree for the back child of the root
draw the roots polygon
draw the BSP tree for the front child of the root
otherwise:
draw the BSP tree for the front child of the root
draw the roots polygon
draw the BSP tree for the back child of the root
there is thus one large active edge list and one (even larger) edge list
z enormous memory requirements
165
166
z-buffer basics
167
168
z-buffer algorithm
FOR every pixel (x,y)
Colour[x,y] = background colour ;
Depth[x,y] = infinity ;
END FOR ;
FOR each polygon
FOR every pixel (x,y) in the polygons projection
z = polygons z-value at pixel (x,y) ;
IF z < Depth[x,y] THEN
Depth[x,y] = z ;
Colour[x,y] = polygons colour at (x,y) ;
END IF ;
END FOR ;
END FOR ;
z-buffer example
4
5
6
7
8
9
4
5
6
7
8
9
6
7
8 8
9 9
4
5
6
6
8
9
4
5
6
6
6
9
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
4
5
6
6
8
9
4
5
5
4
3
2
6
6
5
4
3
6
6
6
5
4
6
6
6
6
6
5
6
6
6
6
6
6
28
169
170
[( x a ', y a ' ), z a ]
( x1 ' , y1 ', d )
xa ' = xa
project
( x2 ', y2 ', d )
( x2 , y2 , z2 )
d
za
d
ya ' = ya
za
1
1
1
= (1 t ) + ( t )
z
z1
z2
( x3 ' , y3 ' , d )
( x3 , y3 , z3 )
171
172
Comparison of methods
Algorithm
Depth sort
Scan line
BSP tree
z-buffer
Complexity
O(N log N)
O(N log N)
O(N)
O(N)
Notes
Need to resolve ambiguities
Memory intensive
O(N log N) pre-processing step
Easy to implement in hardware
other algorithms need to know about all the polygons before drawing a
single one, so that they can sort them into order
173
174
Sampling
Anti-aliasing
these artefacts (and others) are jointly known as
aliasing
methods of ameliorating the effects of aliasing are
known as anti-aliasing
29
175
176
177
178
The A-buffer
A-buffer: details
1 1 1 1 1 1 1 1
0 0 0 1 1 1 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0
L. Carpenter, The A-buffer: an antialiased hidden surface method, SIGGRAPH 84, 1038
179
180
A-buffer: example
A (frontmost)
C (backmost)
1 1 1 1 1 1 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1
0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1
0 0 0 0 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1
1 1 1 1 1 1 1 1
AB
=00000000 00000000 00001100 00011111
ABC =00000000 00000000 11110000 11100000
sub-pixel
colours
final pixel
colour
30
181
182
A-buffer: comments
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1
0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 1 1 1 1 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
why 48?
0 0 1 1 1 1 1 1
0 0 1 1 1 1 0 0
0 1 1 1 1 1 1 1
183
184
A-buffer: extensions
185
186
perfect reflection
(mirror)
specular reflection
diffuse reflection
(Lambertian reflection)
31
187
188
Comments on reflection
gross assumptions:
observation:
189
190
I = I l k d cos
= Il kd ( N L)
use this equation to set the colour of the whole polygon and draw
the polygon using a standard polygon scan-conversion routine
calculate the normal at the vertex, and use this to calculate the
diffuse illumination at that point
normal can be calculated directly if the polygonal model was
derived from a curved surface
[( x1 ' , y 1 ' ), z 1 , ( r1 , g 1 , b1 )]
[( x 2 ' , y 2 ' ), z 2 ,
( r2 , g 2 , b 2 )]
[( x 3 ' , y 3 ' ), z 3 , ( r3 , g 3 , b 3 )]
Henri Gouraud, Continuous Shading of Curved Surfaces, IEEE Trans Computers, 20(6), 1971
Specular reflection
192
one sided: only the side in the direction of the normal vector
can be illuminated
z if cos < 0 then both sides are black
two sided: the sign of cos determines which side of the
polygon is illuminated
z need to invert the sign of the intensity for the back side
191
Gouraud shading
I = I l k s cos n
= Il ks ( R V )n
Phong Bui-Tuong, Illumination for computer generated pictures, CACM, 18(6), 1975, 3117
32
193
194
Phong shading
no shadows
lights at infinity
[( x 2 ' , y 2 ' ), z 2 ,
( r2 , g 2 , b 2 ), N 2 ]
[( x 3 ' , y 3 ' ), z 3 , ( r3 , g 3 , b 3 ), N 3 ]
cheat!
z assume that all light reflected off all other surfaces onto a given
polygon can be amalgamated into a single constant term: ambient
illumination, add this onto the diffuse and specular illumination
195
196
I = I a k a + I i k d ( Li N ) + I i k s ( Ri V ) n
i
Li
Ri
the more lights there are in the scene, the longer this
calculation will take
197
Ray tracing
a powerful alternative to polygon scan-conversion
techniques
given a set of 3D objects, shoot a ray from the eye
through the centre of every pixel and see what it hits
198
33
199
200
plane
sphere
O
ray: P = O + sD , s 0
ray: P = O + sD , s 0
plane: P N + d = 0
s=
a = D D
b = 2D (O C )
c = (O C ) (O C ) r 2
circle: ( P C ) ( P C ) r = 0
2
d = b2 4ac
b + d
2a
b d
s2 =
2a
d + N O
N D
s1 =
d imaginary
d real
201
202
light 2
light 1
N
D
light 2
light 1
light 3
N
D
203
N2
light
N1
if a surface is totally
or partially reflective
then new rays can
be spawned to find
the contribution to
the pixels colour
given by the
reflection
this is perfect
(mirror) reflection
204
D2
D1
light
D0
D'1
D' 2
transparency + reflection
means that a ray can split
into two parts
34
205
206
regular grid
Types of super-sampling 1
single point
12
random
adaptive super-sampling
divide the pixel into a number of subpixels and shoot a ray through the centre
of each
problem: can still lead to noticable
aliasing unless a very high resolution subpixel grid is used
207
208
Types of super-sampling 2
Poisson disc
pure random
jittered
Poisson disc
Types of super-sampling 3
jittered
Poisson disc
pure random
210
35
light
211
previously we could only
calculate the effect of
perfect reflection
we can now distribute the
reflected rays over the
range of directions from
which specularly reflected
light could come
provides a method of
handling some of the interreflections between
objects in the scene
requires a very large
number of ray per pixel
212
diffuse reflection
light
specular reflection
213
214
diffuse to specular
light
handled by
distributed ray tracing
diffuse to diffuse
light
handled by radiosity
specular to diffuse
specular to specular
light
also handled by
distributed ray tracing
light
handled by no usable
algorithm
some research work
has been done on this
but uses enormous
amounts of CPU time
215
216
Multiple inter-reflection
light may reflect off many surfaces on
its way from the light to the camera
standard ray tracing and polygon
scan conversion can handle a single
diffuse or specular bounce
distributed ray tracing can handle
multiple specular bounces
radiosity can handle multiple diffuse
bounces
the general case cannot be handled
by any efficient algorithm
(diffuse | specular)*
diffuse | specular
Hybrid algorithms
polygon scan conversion and ray tracing are
the two principal 3D rendering mechanisms
(diffuse)*
(diffuse | specular )*
36
217
218
Surface detail
Texture mapping
multicoloured surfaces
bumpy surfaces
with
textured surfaces
without
219
220
Paramaterising a primitive
a texture is simply an
image, with a 2D coordinate
system (u,v)
each 3D object is
parameterised in (u,v) space
each pixel maps to some
part of the surface
that part of the surface
maps to part of the texture
221
222
(b)
(i+1,j+1)
(i,j+1)
(i,j)
s
(i+1,j)
(i,j)
t
u
Find (u,v) coordinate of the sample point on
the object and map this into texture space
as shown
37
223
224
nearest neighbour
bilinear
biquadratic
nearestneighbour
bilinear
225
Down-sampling
226
Multi-resolution texture
227
Solid textures
x m + y
Blue k , k
2 2
Red
m + x m + y
2 k , 2 k Green
228
2
2 2
1
1 1
38
229
230
Bump mapping
the surface normal is used in
calculating both diffuse and
specular reflection
bump mapping modifies the
direction of the surface
normal so that the surface
appears more or less bumpy
rather than using a texture
map, a 2D function can be
used which varies the
surface normal smoothly
across the plane
transparency
transparency mapping
reflectiveness
bump mapping
231
3D CG
Image Processing
filtering
2D CG
232
Filtering
IP
Background
convolution
nonlinear filtering
point processing
intensity/colour correction
compositing
halftoning & dithering
compression
233
h( i ) f ( x i )
where h(i) is the filter
in two dimensions:
f '( x , y ) =
9
9
9
1
1
1
9
9
9
1
1
1
9
9
1 1 1
1 1 1
1 1 1
i =
1
1
in one dimension:
f '( x ) =
234
h ( i, j ) f ( x i, y j )
i = j =
1 2 1
2 4 2
1 2 1
1 2 4 2 1
1
112
2 6 9 6 2
4 9 16 9 4
2 6 9 6 2
1 2 4 2 1
39
235
Vertical
1 1 1
1 0 -1
Diagonal
Horizontal edge
detection filter
1 1 0
0 0 0
1 0 -1
1 0 -1
-1 -1 -1
1 0 -1
0 -1 -1
Prewitt filters
1 2 1
1 0 -1
2 1 0
0 0 0
2 0 -2
1 0 -1
-1 -2 -1
1 0 -1
0 -1 -2
236
1 0
0 1
0 -1
-1 0
1 1 1
0 0 0
Roberts filters
-1 -1 -1
Image
Result
Sobel filters
237
238
Median filtering
not a convolution method
the new value of a pixel is the median of the
values of all the pixels in its neighbourhood
e.g. 33 median filter
10 15 17 21 24 27
12 16 20 25 99 37
15 22 23 25 38 42
18 37 36 39 40 44
original image
(16,20,22,23,
25,
25,36,37,39)
16 21 24 27
20 25 36 39
23 36 39 41
34 2 40 41 43 47
sort into order and take median
239
240
median
filter
add shot noise
median
filter
in this example,
median filter reduces
noise but doesnt
eliminate it
Gaussian
blur
Gaussian
blur
Gaussian filter
eliminates noise
at the expense of
excessive blurring
40
241
242
Point processing
inverting an image
Point processing
each pixels value is modified
the modification function only takes that
pixels value into account
f(p)
white
p '( i, j ) = f { p ( i, j )}
black
black
Point processing
improving an images contrast
243
white
Point processing
modifying the output of a filter
black = edge
white = no edge
grey = indeterminate
244
black = edge
white = no edge
f(p)
white
black
black
white
p
f(p)
f(p)
white
dark histogram
improved histogram
white
black
black
white
black
black
white
thresholding
245
i V
246
Image compositing
merging two or more images together
Vp
p' = p1/
i V p' p
41
247
248
Simple compositing
d = ma + (1 m )b
249
250
Arithmetic operations
Difference example
multiplication
used in masking
subtraction (difference)
d = 1| a b|
251
252
Halftoning
each greyscale pixel maps to a square of
binary pixels
52-102
103-153
154-204
205-255
42
253
254
255
256
Ordered dither
1 9
ordered 15 5
dither
4 12
14 8
halftone
16
12
7
15
8
1
4
9
3
13
2
16
11
2
3
6
11
7
10
6
14
5
10
13
e.g.
q i , j = p i , j div 15
14
bi , j = ( q i , j d i m od 4 , j mod 4 )
0 1 9 3
1 15 5 13
2 4 12 2
3 14 8 16
11
7
10
6
257
258
Error diffusion
error diffusion gives a more pleasing visual
result than ordered dither
method:
work left to right, top to bottom
map each pixel to the closest quantised value
pass the quantisation error on to the pixels to the
right and below, and add in the errors before
quantising these pixels
1-bit value
fi,j
bi,j
0-127
128-255
ei,j
f i, j
f i , j 255
f i , j = pi , j + 12 ei1, j + 12 ei, j 1
error
43
259
260
80
107
100
60
+30
80
0
+30
107
100
Error diffusion
+55
+55
107
100
7
16
+55
137
-59
-59
100
1
-59
96
3
16
+48
+48
current pixel
5
16
1
16
pixels still to
be processed
261
ordered dither
262
error diffused
original
ordered dither
error diffused
thresholding
halftoning
<128 black
128 white
thresholding
halftoning
(44 cells)
halftoning
(55 cells)
263
transform coding
264
44
265
266
Encoding - overview
image
Mapper
lossy
symbol encoder
lossless
fewer
bits than
original
quantiser
Symbol
encoder
Quantiser
mapper
all three
operations are
optional
267
268
3232 pixels
e.g.
P( p )
Code 1
Code 2
0
1
2
3
4
5
6
7
0.19
0.25
0.21
0.16
0.08
0.06
0.03
0.02
000
001
010
011
100
101
110
111
11
01
10
001
0001
00001
000001
000000
1024 bytes
269
270
Difference mapping
67
73
74
69
53
54
52
49
67
+6
+1
-5
-16
+1
-2
-3
+78
-2
+1
45
271
272
Percentage
of pixels
Difference
value
0
3.90%
-8..+7
42.74%
-16..+15
61.31%
-32..+31
77.58%
-64..+63
90.35%
-128..+127
98.08%
-255..+255 100.00%
-8..+7
-40..-9
+8..+39
-255..-41
+40..+255
Code
Code
length
Percentage
of pixels
0XXXX
42.74%
10XXXXXX
38.03%
11XXXXXXXXX
11
19.23%
7.29 bits/pixel
91% of the space of the original image
273
274
Predictive mapping
Run-length encoding
e.g. prediction
p i, j =
1
2
p i 1 , j +
1
2
method:
original pixels
p i , j 1
34 36 37 38 38 38 38 39 40 40 40 40 40 49 57 65 65 65 65
run-length encoding
d i, j = pi, j pi, j
3 34 36 37 4 38 1 39 5 40 2 49 57 4 65
275
276
19.37%
44.06%
compression ratios
99.76%
46
277
278
Transform coding
79 73 63 71 73 79 81 89
= 76
-4.5
+0
+4.5
-2
+1.5
+2
+1.5
279
280
Mathematical foundations
N 1
F ( u ) H ( u, x )
u= 0
e.g. H(u,x)
0
1
2
3
4
5
6
7
0
+1
+1
+1
+1
+1
+1
+1
+1
1
+1
+1
+1
+1
-1
-1
-1
-1
2
+1
+1
-1
-1
+1
+1
-1
-1
3
+1
+1
-1
-1
-1
-1
+1
+1
4
+1
-1
+1
-1
+1
-1
+1
-1
5
+1
-1
+1
-1
-1
+1
-1
+1
6
+1
-1
-1
+1
+1
-1
-1
+1
F (u) =
N 1
forward
transform
f ( x )h( x , u )
x=0
7
+1
-1
-1
+1
-1
+1
+1
-1
N 1
F ( u ) H ( u, x )
inverse
transform
u= 0
281
282
Walsh-Hadamard transform
square wave transform
h(x,u)= 1/N H(u,x)
0
2D transforms
10
11
12
13
14
15
two dimensions
forward transform
F (u) =
N 1
f ( x )h( x , u )
x=0
F ( u, v ) =
N 1 N 1
f ( x , y ) h ( x , y , u, v )
x=0 y=0
inverse transform
f (x) =
N 1
F ( u ) H ( u, x )
u= 0
f ( x, y ) =
N 1 N 1
F ( u, v ) H ( u, v , x , y )
u=0 v = 0
invented by Walsh (1923) and Hadamard (1893) - the two variants give the same results for N a power of 2
47
283
284
N 1
f (x)
x =0
e i 2 ux / N
N
inverse transform:
f (x) =
N 1
F ( u )e
i 2 xu / N
u=0
thus:
h( x , u ) =
1
N
e i 2 ux / N
H ( u, x ) = e i 2 xu / N
285
forward transform:
N
f ( x) =
N
2
286
x=0
A (u ) cos( 2 ux + (u ))
( 2 x + 1) u
f ( x ) cos
2N
inverse transform:
f (x) =
u =0
N 1
F ( u ) ( u ) cos
u= 0
( 2 x + 1) u
2N
where:
1
N
2
N
(u) =
u=0
u {1, 2, N 1}
287
288
0.5
0.25
0
0.4
0.6
0.8
-0.5
-1
-1
1
0.75
0.5
0.25
0.4
0.6
0.8
0.2
0.4
0.6
0.8
-0.25
-0.5
-0.5
-0.75
-0.75
-1
-1
-1
0.5
0
-0.25
1
0.75
0.5
0.25
0.4
0.6
0.8
0
-0.25
0.2
0.4
0.6
0.8
0.2
0.4
0.6
0.8
1
0.75
0.25
0.2
0.4
0.6
0.8
0
-0.25
-0.5
-0.5
-0.5
-0.75
-0.75
-0.75
-1
-1
-1
0.5
0.25
0.2
0.8
-0.25
-0.5
-0.75
0.75
0.6
0.5
0.25
0.2
0.4
0.75
0.5
0.2
-0.25
-0.75
0.25
0.2
-0.5
-0.75
0.25
-0.25
-0.25
1
0.75
1
0.75
48
289
290
10
11
12
13
14
15
first derived by Hotelling (1933) for discrete data; by Karhunen (1947) and Love (1948) for continuous data
291
292
compression standard
DCT
transform
Quantisation
JPEG
encoded
image
Variable
length
encoding
image
293
2D DCT
the most important
coefficients are in the
top left hand corner
294
Z ( u, v )
Z ( u, v )
16
11
10
16
24
40
51
61
12
12
14
19
26
58
60
55
14
13
16
24
40
57
69
56
14
17
22
29
51
87
80
62
18
22
37
56
68 109 103 77
24
35
55
64
81 104 113 92
49
64
78
72
92
95
49
295
50