Professional Documents
Culture Documents
Lec05 Morphing
Lec05 Morphing
Lec05 Morphing
Digital
g Visual Effects
Yung-Yu Chuang
with slides by Richard Szeliski, Steve Seitz, Tom Funkhouser and Alexei Efros
Image warping
Image formation
A
Sampling and quantization
What is an image
• We can think of an image as a function, f: R2R:
– f(x,
f( y)) gives
i th
the intensity
i t it att position
iti ((x, y))
– defined over a rectangle, with a finite range:
• f:
f [a,b]x[c,d]
[ b] [ d] [0,1]
[0 1]
f
x
perspective
affine cylindrical
Parametric (global) warping
p = (x,y) p’ = (x
p (x’,y’)
,y )
• Transformation T is a coordinate-changing
machine: p
p’ = T(p)
• What does it mean that T is global?
– Is the same for any point p
– can be described by just a few numbers (parameters)
• Represent
R t T as a matrix:
t i p’’ = M*p
M*
x' x
y'' M y
Scaling
• Scaling a coordinate means multiplying each of
its components by a scalar
• Uniform scaling means this scalar is the same
for all components:
g
f x x' 2 x
y y ' 2 y
2
Scaling
• Non-uniform scaling: different scalars per
component:
x x'
f g
y y '
x' 2 x
y ' 0.5 y
x 2,
y 0.5
Scaling
R
• Even though sin() and cos() are nonlinear to ,
– x’’ is
i a linear
li combination
bi ti off x and dy
– y’ is a linear combination of x and y
• What
Wh iis the
h iinverse transformation?
f i ?
– Rotation by –
1
– For rotation matrices, det(R) = 1 so R R
1 T
2x2 Matrices
• What types of transformations can be
represented with a 2x2 matrix?
2D Identity?
x' x x ' 1 0 x
y' y y ' 0 1 y
2D Shear?
x ' x shx * y x ' 1 shx x
y ' shy * x y y ' sh
1 y
y
2x2 Matrices
• What types of transformations can be
represented with a 2x2 matrix?
2x2 Matrices
• What types of transformations can not be
represented with a 2x2 matrix?
2D Translation?
x' x t x
NO!
y' y t y
x ' 1 0 t x x x t x
y ' 0 1 t y y t
y y
1 0 0 1 1 1
tx = 2
ty = 1
Affine Transformations
• Affine transformations are combinations of …
– Linear
Li transformations,
f i and
d
– Translations
• Properties of affine transformations:
– Origin does not necessarily map to origin
– Lines map to lines
– Parallel lines remain parallel
– Ratios are preserved
– Closed under composition x ' a b c x
– Models change of basis y ' d e f y
w 0 0 1 w
Projective Transformations
• Projective transformations …
– Affine transformations,
transformations and
– Projective warps
• Properties
P ti off projective
j ti ttransformations:
f ti
– Origin does not necessarily map to origin
– Lines map to lines
l
– Parallel lines do not necessarily remain parallel
– Ratios are not preserved
– Closed under composition x' a b c x
– Models change of basis y ' d e f y
w' g h i w
Image warping
• Given a coordinate transform x’ = T(x) and a
source image I(x),
I(x) how do we compute a
transformed image I’(x’) = I(T(x))?
T(x)
(x)
x x’
I(x) II’(x’)
(x )
Forward warping
• Send each pixel I(x) to its corresponding
location x’ = T(x) in I’(x’)
T(x)
(x)
x x’
I(x) II’(x’)
(x )
Forward warping
fwarp(I, I’, T)
{
for (y=0; y<I.height; y++)
for (x=0; x<I
x<I.width;
width; x++) {
(x’,y’)=T(x,y);
I’(x’ y’) I(x y);
I’(x’,y’)=I(x,y);
}
}
I I’
T
x’
Forward warping
Some destination may
not be covered
h(x)
(x)
x x’
f(x) g(x’))
g(x
Forward warping
fwarp(I, I’, T)
{
for (y=0; y<I.height; y++)
for (x=0; x<I
x<I.width;
width; x++) {
(x’,y’)=T(x,y);
Splatting(I’ x’ y’ I(x y) kernel);
Splatting(I’,x’,y’,I(x,y),kernel);
}
}
I I’
T
x’
Inverse warping
• Get each pixel I’(x’) from its corresponding
location x = T-11(x’) in I(x)
T-1(x
(x’))
x x’
I(x) II’(x’)
(x )
Inverse warping
iwarp(I, I’, T)
{
for (y=0; y<I’.height; y++)
for (x=0; x<I’
x<I’.width;
width; x++) {
(x,y)=T-1(x’,y’);
I’(x’ y’) I(x y);
I’(x’,y’)=I(x,y);
}
} T-1
I I’
x
x’
Inverse warping
• Get each pixel I’(x’) from its corresponding
location x = T-11(x’) in I(x)
x x’
f(x) g(x’))
g(x
Inverse warping
iwarp(I, I’, T)
{
for (y=0; y<I’.height; y++)
for (x=0; x<I’
x<I’.width;
width; x++) {
(x,y)=T-1(x’,y’);
I’(x’ y’) Reconstruct(I x y kernel);
I’(x’,y’)=Reconstruct(I,x,y,kernel);
}
} T-1
I I’
x
x’
Inverse warping
• No hole, but must resample
• What
Wh valuel should
h ld you take
k ffor non-integer
i
coordinate? Closest one?
Inverse warping
• It could cause aliasing
Reconstruction
• Reconstruction generates an approximation to
the original function
function. Error is called aliasing
aliasing.
sampling reconstruction
sample
l value
l
sample
l position
i i
Reconstruction
• Computed weighted sum of pixel neighborhood;
output is weighted average of input,
input where
weights are normalized values of filter kernel k
p
k (q )q
i i i
k (q )
i i
color=0;
weights=0;
for all q
q’s dist < width
p width d = dist(p, q);
w = kernel(d);
d color += w*q.color;
q weights += w;
p Color = color/weights;
p.Color
Triangle filter
Gaussian filter
Sampling
band limited
Reconstruction
P’
?
Non-parametric image warping
P ' wA A' wB B' wC C '
P wA A wB B wC C
Barycentric coordinate
P P’
Barycentric coordinates
P t1 A1 t 2 A2 t3 A3
t1 t 2 t3 1
Non-parametric image warping
scatter
tt plot
l t ffor 234D vector
BTSM
all training faces
Beautification engine
Support vector regression (SVR)
• Similar concept to SVM, but for regression
• RBF kernels
k l
• fb(v)
Beautification process
• Given the normalized distance vector v,
generate a nearby vector vv’ so that
fb(v’) > fb(v)
• Two options
p
– KNN-based
– SVR-based
SVR based
KNN-based beautification
5.1
4.3
3.1
31
v' v
45
4.5
4.6
5.3
SVR-based beautification
• Directly use fb to seek v’
• LP is approximated
pp byy modelingg face space
p as a
multivariate Gaussian distribution ’s i-th
component
λ2
λ1
Embedding and warping
Distance embedding
• Convert modified distance vector v’ to a new
face landmark
1 if i and
djbbelong
l tto diff
differentt ffacial
i l ffeatures
t
10 otherwise
eyes
mouth
full
Different degrees
50% 100%
Facial collage
Image morphing
Image morphing
• The goal is to synthesize a fluid transformation
from one image to another.
another
• Cross dissolving is a common transition between
cuts, but it is not good for morphing because of
the ghosting effects.
i g #1
image di l i g
dissolving image #2
Artifacts of cross-dissolving
http://www.salavon.com/
Image morphing
• Why ghosting?
• Morphing
M hi = warpingi + cross-dissolving
di l i
shape color
(geometric) (photometric)
Image morphing
image #1 cross-dissolving image #2
average faces
Image morphing
create a morphing sequence: for each time t
1 C
1. Create
t an iintermediate
t di t warping
i fifield
ld (b
(by
interpolation)
2 Warp both images towards it
2.
3. Cross-dissolve the colors in the newly warped
images
t=0 morphing
t=0.25
t=0.5
t=0.75 t=1
An ideal example
easy to implement,
implement but less expressive
Warp specification
• How can we specify the warp
2 SSpecify
2. if corresponding
di points
i t
• interpolate to a complete warping function
Solution: convert to mesh warping
1 D
1. Define
fi a triangular
ti l mesh h over th
the points
i t
– Same mesh in both images!
– Now
N we hhave triangle-to-triangle
i l i l correspondences
d
2. Warp each triangle separately from source to destination
– How do we warp a triangle?
– 3 points = affine warp!
– Just like texture mapping
Warp specification (field warping)
• How can we specify the warp?
3 Specify
3. S if corresponding
di vectors
t
• interpolate to a complete warping function
• The Beier & Neely Algorithm
Beier&Neely (SIGGRAPH 1992)
• Single line-pair PQ to P’Q’:
Algorithm (single line-pair)
• For each X in the destination image:
1. Fi
1 Find
d the
th corresponding
di u,v
2. Find X’ in the source image for that u,v
3 d
3. ti ti I (X) = sourceImage(X’)
destinationImage(X) I (X’)
• Examples:
Affine transformation
Multiple Lines
Di X i' X i
t=1
Animation
Animated sequences
• Specify keyframes and interpolate the lines for
the inbetween frames
• Require a lot of tweaking
Results