SLIDE 1 Image warping/morphing
Digital Visual Effects, Spring 2006 Yung-Yu Chuang 2005/3/15
with slides by Richard Szeliski, Steve Seitz and Alexei Efros
SLIDE 2 Outline
- Images
- Image warping
- Image morphing
SLIDE 3
Image fundamentals
SLIDE 4
Image formation
A B
SLIDE 5
Sampling and quantization
SLIDE 6 What is an image
- We can think of an image as a function, f: R
2R:
– f(x, y) gives the intensity at position (x, y) – defined over a rectangle, with a finite range:
- f: [a,b]x[c,d] [0,1]
- A color image
( , ) ( , ) ( , ) ( , ) r x y f x y g x y b x y ⎡ ⎤ ⎢ ⎥ = ⎢ ⎥ ⎢ ⎥ ⎣ ⎦
x y f
SLIDE 7 A digital image
- We usually operate on digital (discrete) images:
– Sample the 2D space on a regular grid – Quantize each sample (round to nearest integer)
- If our samples are D apart, we can write this as:
f[i ,j ] = Quantize{ f(i D, j D) }
- The image can now be represented as a matrix
- f integer values
62 79 23 119 120 105 4 10 10 9 62 12 78 34 10 58 197 46 46 48 176 135 5 188 191 68 49 2 1 1 29 26 37 77 89 144 147 187 102 62 208 255 252 166 123 62 31 166 63 127 17 1 99 30
SLIDE 8
Image warping
SLIDE 9 Image warping
image filtering: change range of image
g(x) = h(f(x))
f x
h
g x f x
h
g x
image warping: change domain of image
g(x) = f(h(x))
SLIDE 10 Image warping
h h
f f g g
image filtering: change range of image
f(x) = h(g(x))
image warping: change domain of image
f(x) = g(h(x))
SLIDE 11 Parametric (global) warping
translation rotation aspect affine perspective cylindrical
Examples of parametric warps:
SLIDE 12 Parametric (global) warping
- Transformation T is a coordinate-changing
machine: p’ = T(p)
- What does it mean that T is global?
– Is the same for any point p – can be described by j ust a few numbers (parameters)
- Represent T as a matrix: p’ = M*p
T p = (x,y) p’ = (x’,y’)
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x M ' '
SLIDE 13 Scaling
caling a coordinate means multiplying each of
its components by a scalar
- Uniform scaling means this scalar is the same
for all components:
× 2
SLIDE 14
- Non-uniform scaling: different scalars per
component:
Scaling
X × 2, Y × 0.5
SLIDE 15 Scaling
caling operation:
by y ax x = = ' ' ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x b a y x ' '
scaling matrix S What’s inverse of S?
SLIDE 16 2-D Rotation
- This is easy to capture in matrix form:
- Even though sin(θ) and cos(θ) are nonlinear to θ,
– x’ is a linear combination of x and y – y’ is a linear combination of x and y
- What is the inverse transformation?
– Rotation by –θ – For rotation matrices, det(R) = 1 so
( ) ( ) ( ) ( )
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ − = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x θ θ θ θ cos sin sin cos ' '
T
R R =
−1
R
SLIDE 17 2x2 Matrices
- What types of transformations can be
represented with a 2x2 matrix?
2D Identity?
y y x x = = ' ' ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x 1 1 ' '
2D Scale around (0,0)?
y s y x s x
y
x
* ' * ' = = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x s s y x
y x
' '
SLIDE 18 2x2 Matrices
- What types of transformations can be
represented with a 2x2 matrix?
2D Rotate around (0,0)?
y x y y x x * cos * sin ' * sin * cos ' θ θ θ θ + = − =
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ − = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x θ θ θ θ cos sin sin cos ' '
2D Shear?
y x sh y y sh x x
y x
+ = + = * ' * '
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x sh sh y x
y x
1 1 ' '
SLIDE 19 2x2 Matrices
- What types of transformations can be
represented with a 2x2 matrix?
2D Mirror about Y axis?
y y x x = − = ' '
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡− = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x 1 1 ' '
2D Mirror over (0,0)?
y y x x − = − = ' '
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ − − = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x y x 1 1 ' '
SLIDE 20 All 2D Linear Transformations
- Linear transformations are combinations of …
– S
cale,
– Rotation, – S
hear, and
– Mirror
- Properties of linear transformations:
– Origin maps to origin – Lines map to lines – Parallel lines remain parallel – Ratios are preserved – Closed under composition
⎥ ⎦ ⎤ ⎢ ⎣ ⎡ ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡ y x d c b a y x ' '
SLIDE 21 2x2 Matrices
- What types of transformations can be
represented with a 2x2 matrix?
2D Translation?
y x
t y y t x x + = + = ' '
Only linear 2D transformations can be represented with a 2x2 matrix
NO!
SLIDE 22 Translation
⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ + + = ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ = ⎥ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎢ ⎣ ⎡ 1 1 1 1 1 1 ' '
y x y x
t y t x y x t t y x
tx = 2 ty = 1 Homogeneous Coordinates
SLIDE 23 Affine Transformations
- Affine transformations are combinations of …
– Linear transformations, and – 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 – Models change of basis
⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ = ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ w y x f e d c b a w y x 1 ' '
SLIDE 24 Projective Transformations
- Proj ective transformations …
– Affine transformations, and – Proj ective warps
- Properties of proj ective transformations:
– Origin does not necessarily map to origin – Lines map to lines – Parallel lines do not necessarily remain parallel – Ratios are not preserved – Closed under composition – Models change of basis
⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ = ⎥ ⎥ ⎦ ⎤ ⎢ ⎢ ⎣ ⎡ w y x i h g f e d c b a w y x ' ' '
SLIDE 25 2D coordinate transformations
x’ = x + t x = (x,y)
x’ = R x + t
x’ = s R x + t
x’ = A x + t
x’ ≅ H x x = (x,y,1)
(x is a homogeneous coordinate)
- These all form a nested group (closed under
composition w/ inv.)
SLIDE 26 Image warping
- Given a coordinate transform x’ = h(x) and a
source image f(x), how do we compute a transformed image g(x’) = f(h(x))?
f(x) g(x’) x x’ h(x)
SLIDE 27 Forward warping
end each pixel f(x) to its corresponding location x’ = h(x) in g(x’)
f(x) g(x’) x x’ h(x)
SLIDE 28 Forward warping
end each pixel f(x) to its corresponding location x’ = h(x) in g(x’)
f(x) g(x’) x x’ h(x)
- What if pixel lands “between” two pixels?
- Answer: add “contribution” to several pixels,
normalize later (splatting)
SLIDE 29 Inverse warping
- Get each pixel g(x’) from its corresponding
location x = h-1(x’) in f(x)
f(x) g(x’) x x’ h-1(x’)
SLIDE 30 Inverse warping
- Get each pixel g(x’) from its corresponding
location x = h-1(x’) in f(x)
- What if pixel comes from “between” two pixels?
- Answer: resample color value from
interpolated (prefiltered) source image
f(x) g(x’) x x’
SLIDE 31 Interpolation
- Possible interpolation filters:
– nearest neighbor – bilinear – bicubic – sinc / FIR
SLIDE 32 Bilinear interpolation
- A simple method for resampling images
SLIDE 33 Non-parametric image warping
pecify a more detailed warp function
plines, meshes, optical flow (per-pixel motion)
SLIDE 34 Demo
- http:/ / www.colonize.com/ warp/
- Warping is a useful operation for mosaics, video
matching, view interpolation and so on.
SLIDE 35
Image morphing
SLIDE 36 Image morphing
- The goal is to synthesize a fluid transformation
from one image to another. image #1 image #2 dissolving
- Cross dissolving is a common transition between
cuts, but it is not good for morphing because of the ghosting effects.
SLIDE 37
Artifacts of cross-dissolving
http:/ / www.salavon.com/
SLIDE 38 Image morphing
- Why ghosting?
- Morphing = warping + cross-dissolving
shape (geometric) color (photometric)
SLIDE 39
morphing cross-dissolving
Image morphing
image #1 image #2 warp warp
SLIDE 40
Morphing sequence
SLIDE 41
Face averaging by morphing
average faces
SLIDE 42 Image morphing
create a morphing sequence: for each time t
- 1. Create an intermediate warping field (by
interpolation)
- 2. Warp both images towards it
- 3. Cross-dissolve the colors in the newly warped
images
SLIDE 43
An ideal example
t=0 t=1 t=0.25 t=0.5 t=0.75 morphing
SLIDE 44
An ideal example
middle face (t=0.5) t=0 t=1
SLIDE 45 Warp specification (mesh warping)
- How can we specify the warp?
- 1. S
pecify corresponding spline cont rol point s
int erpolat e to a complete warping function
easy to implement, but less expressive
SLIDE 46 Warp specification (field warping)
- How can we specify the warp?
- 2. S
pecify corresponding vect ors
- int erpolat e to a complete warping function
- The Beier & Neely Algorithm
SLIDE 47 Beier&Neely (SIGGRAPH 1992)
ingle line-pair PQ to P’Q’:
SLIDE 48 Algorithm (single line-pair)
- For each X in the destination image:
- 1. Find the corresponding u,v
- 2. Find X’ in the source image for that u,v
- 3. destinationImage(X) = sourceImage(X’)
- Examples:
Affine transformation
SLIDE 49
Multiple Lines
length = length of the line segment, dist = distance to line segment
The influence of a, p, b. The same as the average of Xi’
SLIDE 50
Full Algorithm
SLIDE 51
Resulting warp
SLIDE 52 Comparison to mesh morphing
- Pros: more expressive
- Cons: speed and control
SLIDE 53 Warp interpolation
- How do we create an intermediate warp at
time t?
– linear interpolation for line end-points – But, a line rotating 180 degrees will become 0
length in the middle
– One solution is to interpolate line mid-point and
t=0 t=1
SLIDE 54 Animated sequences
pecify keyframes and interpolate the lines for the inbetween frames
- Require a lot of tweaking
SLIDE 55
Results
Michael Jackson’ s MTV “ Black or Whit e”
SLIDE 56 Warp specification
- How can we specify the warp
- 3. S
pecify corresponding point s
- int erpolat e to a complete warping function
SLIDE 57 Solution#1: convert to mesh warping
- 1. Define a triangular mesh over the points
– S
ame mesh in both images!
– Now we have triangle-to-triangle correspondences
- 2. Warp each triangle separately from source to destination
– How do we warp a triangle? – 3 points = affine warp! – Just like texture mapping
SLIDE 58
Multi-source morphing
SLIDE 59
Multi-source morphing
SLIDE 60 References
- George Wolberg, Image morphing: a survey,
The Visual Computer, 1998, pp360-372.
hawn Neely. Feature-Based Image Metamorphosis, S IGGRAPH 1992.
- Michael Jackson's "Black or White" MTV