27
Image warping/morphing Digital Visual Effects Yung-Yu Chuang with slides by Richard Szeliski, Steve Seitz, Tom Funkhouser and Alexei Efros Image warping Image warping Image formation B A Sampling and quantization

Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

  • Upload
    buimien

  • View
    240

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Image warping/morphing

Digital Visual EffectsgYung-Yu Chuang

with slides by Richard Szeliski, Steve Seitz, Tom Funkhouser and Alexei Efros

Image warpingImage warping

Image formation

B

A

Sampling and quantization

Page 2: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

What is an image

• We can think of an image as a function, f: R2R:f( ) i th i t it t iti ( ) – f(x, y) gives the intensity at position (x, y)

– defined over a rectangle, with a finite range:f [ b] [ d] [0 1]• f: [a,b]x[c,d] [0,1]

xf

y

• A color image ( , )( , ) ( , )

r x yf x y g x y

( , ) ( , )

( , )f y g y

b x y

A digital image

• We usually operate on digital (discrete) images:S l th 2D l id– Sample the 2D space on a regular grid

– Quantize each sample (round to nearest integer)

f l h• 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 of integer valueso tege values

Image warping

image filtering: change range of image( ) h(f( ))g(x) = h(f(x))

fh

gh(y)=0.5y+0.5

x

hx

image warping: change domain of image

f

g(x) = f(h(x))h(y)=2y

fh

g

x x

Image warping

image filtering: change range of image( ) h(f( ))

f g

g(x) = h(f(x))h(y)=0.5y+0.5

hf g

image warping: change domain of image

f

g(x) = f(h(x))h([x,y])=[x,y/2]

hf

g

Page 3: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Parametric (global) warping

Examples of parametric warps:Examples of parametric warps:

translation rotation aspect

affineperspective

cylindrical

Parametric (global) warping

TT

p = (x,y) p’ = (x’,y’)• Transformation T is a coordinate-changing

machine: p’ = T(p)

p (x,y) p (x ,y )

machine: p T(p)• What does it mean that T is global?

Is the same for any point p– Is the same for any point p– can be described by just a few numbers (parameters)

R t T t i ’ M*• Represent T as a matrix: p’ = M*p

xxM

''

yy'

Scaling

• Scaling a coordinate means multiplying each of its components by a scalarits components by a scalar

• Uniform scaling means this scalar is the same for all components:for all components:

f g xx 2'x

yy 2'

y

2

Scaling

• Non-uniform scaling: different scalars per component: 'component:

''

yx

gyx

f

xx 2' yy

yy 5.0'

x 2,y 0.5

Page 4: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Scaling

• Scaling operation: axx 'byy '

• Or, in matrix form:

yx

ba

yx

00

''

yby 0

scaling matrix Sscaling matrix SWhat’s inverse of S?

2-D Rotation

• This is easy to capture in matrix form:

yx

yx

cossinsincos

''

yy cossin

R

• Even though sin() and cos() are nonlinear to ,’ i li bi ti f d

R

– x’ is a linear combination of x and y– y’ is a linear combination of x and y

Wh i h i f i ?• What is the inverse transformation?– Rotation by –

T1– For rotation matrices, det(R) = 1 so TRR 1

2x2 Matrices

• What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Identity?' xx 01'

yyxx

''

yx

yx

1001

''

2D Scale around (0,0)?xsx *' s 0'ysyxsx

y

x

*'

yx

ss

yx

y

x

00

''

y y

2x2 Matrices

• What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Rotate around (0,0)?*i*' i

yxyyxx

*cos*sin'*sin*cos'

yx

yx

cossinsincos

''

2D Shear?

yxshyyshxx

y

x

*'*'

yx

shsh

yx x

11

''

yxshy y yshy y 1

Page 5: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

2x2 Matrices

• What types of transformations can be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Mirror about Y axis?' xx 01'

yyxx

''

yx

yx

1001

''

2D Mirror over (0,0)?

yyxx

''

yx

yx

1001

''

yy yy

All 2D Linear Transformations

• Linear transformations are combinations of …Scale– Scale,

– Rotation,– Shear andShear, and– Mirror

• Properties of linear transformations:• Properties of linear transformations:– Origin maps to origin– Lines map to linesLines map to lines– Parallel lines remain parallel– Ratios are preserved xbax'p– Closed under composition

yx

dcba

yx

''

ydcy

2x2 Matrices

• What types of transformations can not be represented with a 2x2 matrix?represented with a 2x2 matrix?

2D Translation?t'

y

x

tyytxx

''

NO!

Only linear 2D transformations b t d ith 2 2 t ican be represented with a 2x2 matrix

Translation

• Example of translationHomogeneous Coordinates

111001001

1''

y

x

y

x

tytx

yx

tt

yx

111001

tx = 2ty = 1y

Page 6: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Affine Transformations

• Affine transformations are combinations of …Li f i d– 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

x

fdcbax

''

– Models change of basis

w

yfedwy

100'

Projective Transformations• Projective transformations …

Affine transformations and– Affine transformations, and– Projective warps

P ti f j ti t f ti• Properties of projective transformations:– Origin does not necessarily map to origin

l– Lines map to lines– Parallel lines do not necessarily remain parallel– Ratios are not preserved– Closed under composition

xcbax'

– Models change of basis

w

yihgfed

wy

''

wihgw

Image warping

• Given a coordinate transform x’ = T(x) and a source image I(x) how do we compute a source image I(x), how do we compute a transformed image I’(x’) = I(T(x))?

T(x)

I(x) I’(x’)x x’

(x)

I(x) I (x )

Forward warping

• Send each pixel I(x) to its corresponding location x’ T(x) in I’(x’)location x’ = T(x) in I’(x’)

T(x)

I(x) I’(x’)x x’

(x)

I(x) I (x )

Page 7: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Forward warpingfwarp(I, I’, T){{for (y=0; y<I.height; y++)for (x=0; x<I width; x++) {for (x=0; x<I.width; x++) {(x’,y’)=T(x,y);I’(x’ y’) I(x y);I’(x’,y’)=I(x,y);

}}} I I’

T

x

x’

Forward warping

Some destination may not be coverednot be covered

Many source pixels could mapMany source pixels could mapto the same destination

Forward warping

• Send each pixel I(x) to its corresponding location x’ T(x) in I’(x’)location x’ = T(x) in I’(x’)

• What if pixel lands “between” two pixels?p p• Will be there holes?• Answer: add “contribution” to several pixels• Answer: add contribution to several pixels,

normalize later (splatting)

h(x)

f(x) g(x’)x x’

(x)

f(x) g(x )

Forward warpingfwarp(I, I’, T){{for (y=0; y<I.height; y++)for (x=0; x<I width; x++) {for (x=0; x<I.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

x’

Page 8: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Inverse warping

• Get each pixel I’(x’) from its corresponding location x T-1(x’) in I(x)location x = T 1(x’) in I(x)

T-1(x’)

I(x) I’(x’)x x’

(x )

I(x) I (x )

Inverse warpingiwarp(I, I’, T){{for (y=0; y<I’.height; y++)for (x=0; x<I’ width; x++) {for (x=0; x<I’.width; x++) {(x,y)=T-1(x’,y’);I’(x’ y’) I(x y);I’(x’,y’)=I(x,y);

}}} I I’T-1

xx’

Inverse warping

• Get each pixel I’(x’) from its corresponding location x T-1(x’) in I(x)location x = T 1(x’) in I(x)

• What if pixel comes from “between” two pixels?• Answer: resample color value from• Answer: resample color value from

interpolated (prefiltered) source image

f(x) g(x’)x x’f(x) g(x )

Inverse warpingiwarp(I, I’, T){{for (y=0; y<I’.height; y++)for (x=0; x<I’ width; x++) {for (x=0; x<I’.width; x++) {(x,y)=T-1(x’,y’);I’(x’ y’) Reconstruct(I x y kernel);I’(x’,y’)=Reconstruct(I,x,y,kernel);

}}} I I’T-1

xx’

Page 9: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Inverse warping

• No hole, but must resampleWh l h ld k f i • What value should you take for non-integer coordinate? Closest one?

Inverse warping

• It could cause aliasing

Reconstruction

• Reconstruction generates an approximation to the original function Error is called aliasingthe original function. Error is called aliasing.

l lsampling reconstruction

sample value

l i isample position

Reconstruction

• Computed weighted sum of pixel neighborhood; output is weighted average of input where output is weighted average of input, where weights are normalized values of filter kernel k

qqk )(

color=0;

i i

i ii

qkqqk

p)(

)(

color=0;weights=0;for all q’s dist < width

width

d

qd = dist(p, q);w = kernel(d);

p

d color += w*q.color;weights += w;

p Color = color/weights;q p.Color = color/weights;

Page 10: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Triangle filter Gaussian filter

Samplingband limited

Reconstruction

The reconstructed function is obtained by interpolating The reconstructed function is obtained by interpolating among the samples in some manner

Page 11: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Reconstruction (interpolation)

• Possible reconstruction filters (kernels):t i hb– nearest neighbor

– bilinearbi bi – bicubic

– sinc (optimal reconstruction)

Bilinear interpolation (triangle filter)

• A simple method for resampling images

Non-parametric image warping

• Specify a more detailed warp functionS li h i l fl ( i l i )• Splines, meshes, optical flow (per-pixel motion)

Non-parametric image warping

• Mappings implied by correspondencesI i• Inverse warping

P’?

Page 12: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Non-parametric image warping

'''' CwBwAwP CBA CwBwAwP

Barycentric coordinateCwBwAwP CBA

P’P

Barycentric coordinates

1321

332211

tttAtAtAtP

1321 ttt

Non-parametric image warping

'''' CwBwAwP CBA CwBwAwP Barycentric coordinate

CwBwAwP CBA

Non-parametric image warping2

)( rer Gaussian iX XPkK

Pi

)'(1

radial basis function)log()( 2 rrr thin plate

splineiK

Page 13: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Image warping

• Warping is a useful operation for mosaics, video matching view interpolation and so onmatching, view interpolation and so on.

An application of image warping: face beautification

Data-driven facial beautification Facial beautification

Page 14: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Facial beautification Facial beautification

Training set

• Face images92 C i f l– 92 young Caucasian female

– 33 young Caucasian male

Feature extraction

Page 15: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Feature extraction

• Extract 84 feature points by BTSMD l i l i 234D di • Delaunay triangulation -> 234D distance vector (normalized by the square root of face area)

tt l t fBTSM scatter plot forall training faces

234D vector

Beautification engine

Support vector regression (SVR)

• Similar concept to SVM, but for regressionRBF k l• RBF kernels

• fb(v)

Beautification process

• Given the normalized distance vector v, generate a nearby vector v’ so that generate a nearby vector v so that

fb(v’) > fb(v)

• Two optionsp– KNN-based– SVR-basedSVR based

Page 16: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

KNN-based beautification

5.15.1

4.34.3

3 13 1

44 55

3.13.1vv'

44..55

4.64.655..33

SVR-based beautification

• Directly use fb to seek v’

• Use standard no-derivative direction set method for minimization

• Features were reduced to 35D by PCA

SVR-based beautification

• Problems: it sometimes yields distance vectors corresponding to invalid human facecorresponding to invalid human face

• Solution: add log-likelihood term (LP)

• LP is approximated by modeling face space as a pp y g pmultivariate Gaussian distribution ’s i-th

component

u’s projectionin PCA space

i-th eigenvaluein PCA space

PCA

λ2

λ1

Page 17: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Embedding and warping Distance embedding

• Convert modified distance vector v’ to a new face landmarkface landmark

1 if i d j b l t diff t f i l f t1 if i and j belong to different facial features10 otherwise

• A graph drawing problem referred to as a stress i i i ti bl l d b LM l ith minimization problem, solved by LM algorithm

for non-linear minimization

Distance embedding

• Post processing to enforce similarity transform for features on eyes by minimizingfor features on eyes by minimizing

SVR K=5K=3Original

Page 18: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Results (in training set) User study

Results (not in training set) By parts

eyes

mouth

full

Page 19: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Different degrees

50% 100%

Facial collage

Results

• video

Image morphingImage morphing

Page 20: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Image morphing

• The goal is to synthesize a fluid transformation from one image to anotherfrom one image to 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 #2di l i gimage #1 image #2dissolving

Artifacts of cross-dissolving

http://www.salavon.com/

Image morphing

• Why ghosting?M hi i di l i• Morphing = warping + cross-dissolving

shape(geometric)

color(photometric)(geometric) (photometric)

Image morphing

cross-dissolvingimage #1 image #2

morphingwarp warp

Page 21: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Morphing sequence Face averaging by morphing

average faces

Image morphing

create a morphing sequence: for each time t1 C t i t di t i fi ld (b 1. Create an intermediate warping field (by

interpolation)2 Warp both images towards it2. Warp both images towards it3. Cross-dissolve the colors in the newly warped

imagesimages

t=0 t=1t=0.33

An ideal example (in 2004)

t=0 t=1t=0.25t=0.5t=0.75morphing

Page 22: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

An ideal example

middle face (t=0.5)t=0 t=1

Warp specification (mesh warping)

• How can we specify the warp?1 S if di li t l i t1. Specify corresponding spline control points

interpolate to a complete warping function

easy to implement but less expressiveeasy to implement, but less expressive

Warp specification

• How can we specify the warp2 S if di i t2. Specify corresponding points

• interpolate to a complete warping function

Solution: convert to mesh warping

1 D fi t i l h th i t1. Define a triangular mesh over the points– Same mesh in both images!

N h i l i l d– Now we have triangle-to-triangle correspondences2. Warp each triangle separately from source to destination

– How do we warp a triangle?– 3 points = affine warp!– Just like texture mapping

Page 23: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Warp specification (field warping)

• How can we specify the warp?3 S if di t3. Specify corresponding vectors

• interpolate to a complete warping function• The Beier & Neely Algorithm• 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 d th di 1. Find the corresponding u,v2. Find X’ in the source image for that u,v3 d ti ti I (X) I (X’)3. destinationImage(X) = sourceImage(X’)

• Examples:

Affine transformationAffine transformation

Multiple Lines

XXD 'iii XXD

length = length of the line segment, dist = distance to line segmentThe influence of a, p, b. The same as the average of Xi’

Page 24: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Full Algorithm Resulting warp

Comparison to mesh morphing

• Pros: more expressive C d d l• Cons: speed and control

Warp interpolation

• How do we create an intermediate warp at time t?time t?– linear interpolation for line end-points

B t li t ti 180 d ill b 0 – But, a line rotating 180 degrees will become 0 length in the middleOne solution is to interpolate line mid point and – One solution is to interpolate line mid-point and orientation angle

t=0

t=1t=1

Page 25: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Animation Animated sequences

• Specify keyframes and interpolate the lines for the inbetween framesthe inbetween frames

• Require a lot of tweaking

Results

Michael Jackson’s MTV “Black or White”

Multi-source morphing

Page 26: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Multi-source morphing References• Thaddeus Beier, Shawn Neely, Feature-Based Image Metamorphosis,

SIGGRAPH 1992, pp35-42. • Detlef Ruprecht, Heinrich Muller, Image Warping with Scattered

Data Interpolation, IEEE Computer Graphics and Applications, March 1995 pp37-43 March 1995, pp37 43.

• Seung-Yong Lee, Kyung-Yong Chwa, Sung Yong Shin, Image Metamorphosis Using Snakes and Free-Form Deformations, SIGGRAPH 1995 SIGGRAPH 1995.

• Seungyong Lee, Wolberg, G., Sung Yong Shin, Polymorph: morphing among multiple images, IEEE Computer Graphics and Applications, g p g , p p pp ,Vol. 18, No. 1, 1998, pp58-71.

• Peinsheng Gao, Thomas Sederberg, A work minimization approach to image morphing The Visual Computer 1998 pp390 400 to image morphing, The Visual Computer, 1998, pp390-400.

• George Wolberg, Image morphing: a survey, The Visual Computer, 1998, pp360-372.

• Data-Driven Enhancement of Facial Attractiveness, SIGGRAPH 2008

Project #1: image morphingProject #1: image morphing

Reference software

• Morphing software reviewI d 30 d l i i F t M h• I used 30-day evaluation version. You can use any one you like.

FantaMorph

Page 27: Image warping/morphing Image warpingImage warping · Image warping/morphing Digital Visual Effects ... Steve Seitz, Tom Funkhouser and Alexei Efros Image warpingImage warping Image

Morphing is not only for faces Morphing is not only for faces