Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping...

52
Image Warping and Morphing Leow Wee Kheng CS4243 Computer Vision and Pattern Recognition CS4243 Image Warping and Morphing 1

Transcript of Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping...

Page 1: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping and Morphing

Leow Wee Kheng CS4243 Computer Vision and Pattern Recognition

CS4243 Image Warping and Morphing 1

Page 2: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Morphing is artistic

CS4243 Image Warping and Morphing 2

Page 3: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Morphing is captivating!

CS4243 Image Warping and Morphing 3

Page 4: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Morphing is dynamic!

CS4243 Image Warping and Morphing 4

Page 5: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Morphing is fun!

CS4243 Image Warping and Morphing 5

Page 6: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Morphing is fun!

CS4243 Image Warping and Morphing 6

OK, that was not really morphing.

But, you get the point.

Page 7: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Two kinds of morphing Image morphing

2D

Object morphing 2D: like image morphing 3D: more complex

CS4243 Image Warping and Morphing 7

our focus

Page 8: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping & Morphing Involves 3 things

Spatial transformation Colour transfer Continuous transition

CS4243 Image Warping and Morphing 8

image warping

Page 9: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping & Morphing Involves 3 things

Spatial transformation Colour change Continuous transition

CS4243 Image Warping and Morphing 9

Page 10: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Spatial Transformation Simplest form: affine transformation

CS4243 Image Warping and Morphing 10

Page 11: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Affine Transformation

CS4243 Image Warping and Morphing 11

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

1005.010

8.001

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

translation

Page 12: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Affine Transformation

CS4243 Image Warping and Morphing 12

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

10002.10008.0

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

scaling

Page 13: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Affine Transformation

CS4243 Image Warping and Morphing 13

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

100011.002.01

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

shearing

parallel lines remain parallel

Page 14: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Affine Transformation

CS4243 Image Warping and Morphing 14

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

1000cossin0sincos

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

rotation

parallel lines remain parallel

Page 15: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Affine Transformation To solve for affine matrix:

For i = 1,…, n, arrange into two matrix equations:

Then, solve each equation using linear least square.

CS4243 Image Warping and Morphing 15

Page 16: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Perspective Transformation Generalisation of affine transformation:

Looks like a linear equation. But, perspective transformation is nonlinear. Will discuss further later.

CS4243 Image Warping and Morphing 16

Page 17: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Polynomial Transformation Described by polynomial equations

Example: 2nd-order polynomial, e.g., quadratic

CS4243 Image Warping and Morphing 17

Page 18: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Quadratic Transformation In matrix form

Solving the parameters is easy! Just like for the affine case (exercise).

CS4243 Image Warping and Morphing 18

If these are zero, what is the matrix?

Page 19: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Quadratic Transformation

CS4243 Image Warping and Morphing 19

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

0100000011.000

tapering / perspective distortion

Page 20: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Quadratic Transformation

CS4243 Image Warping and Morphing 20

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

− 0101.000

001000

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

tapering / perspective distortion

Page 21: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Quadratic Transformation

CS4243 Image Warping and Morphing 21

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

− 01001.00

001001.0

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

expansion / compression

Page 22: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Quadratic Transformation

CS4243 Image Warping and Morphing 22

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

− 010001.0

00101.00

Source (x, y) Target (u, v)

-3

-2

-1

0

1

2

3

-3 -2 -1 0 1 2 3

warping

Page 23: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

General Transformation General form of u and v

Possible kernel functions: Affine Polynomial Splines: B-splines, cubic splines, etc. Thin-plate spline: model physical bending energy

CS4243 Image Warping and Morphing 23

),(1

yxhau k

K

kk∑

=

=

parameters kernel function

Page 24: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Which kernel to use? General guidelines

Sufficient to capture transformation Not overly complex

CS4243 Image Warping and Morphing 24

Page 25: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Example

Fit affine transformation. Correct transformation, small error.

CS4243 Image Warping and Morphing 25

source target mapped source

Page 26: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Example

Fit affine transformation. Incorrect transformation, large error.

CS4243 Image Warping and Morphing 26

source target mapped source

Page 27: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Example

Fit quadratic transformation. Looks correct, small error; but can over fit.

CS4243 Image Warping and Morphing 27

source target mapped source

Page 28: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Example

Fit quadratic transformation. Correct transformation, small error.

CS4243 Image Warping and Morphing 28

source target mapped source

Page 29: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping & Morphing Involves 3 things

Spatial transformation Colour transfer Continuous transition

CS4243 Image Warping and Morphing 29

Page 30: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Colour Transfer Determine colour in transformed image. Remember to use backward mapping plus

bilinear interpolation

CS4243 Image Warping and Morphing 30

Page 31: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Colour Transfer Forward mapping

Copy colour of p in I to q in I’. But q is at real-valued coordinates; problem.

CS4243 Image Warping and Morphing 31

source target

Page 32: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Colour Transfer Backward mapping

Map q in I’ to p in I. Use bilinear interpolation to determine colour of p. Copy colour of p to q.

CS4243 Image Warping and Morphing 32

source target

Page 33: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With affine mapping

CS4243 Image Warping and Morphing 33

Page 34: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With affine mapping

CS4243 Image Warping and Morphing 34

Page 35: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With affine mapping

CS4243 Image Warping and Morphing 35

Page 36: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With affine mapping

CS4243 Image Warping and Morphing 36

Page 37: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With quadratic mapping

CS4243 Image Warping and Morphing 37

Why so much distortion?

Page 38: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With quadratic mapping

CS4243 Image Warping and Morphing 38

Page 39: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With quadratic mapping

CS4243 Image Warping and Morphing 39

Page 40: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping Example With quadratic mapping

CS4243 Image Warping and Morphing 40

Page 41: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Local Transformation Divide image into regions. Warp each region by a different transform.

Ensure changes over boundaries are smooth.

Achieve finer control.

CS4243 Image Warping and Morphing 41

Page 42: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Summary Need to mark good corresponding points. Lower-order function may not warp enough. Higher-order function can lead to distortions. Local transformations give finer control.

CS4243 Image Warping and Morphing 42

Page 43: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Warping & Morphing Involves 3 things

Spatial transformation Colour transfer Continuous transition

CS4243 Image Warping and Morphing 43

Page 44: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Morphing Basic ideas:

Want positions to change smoothly. Want colours to change smoothly.

CS4243 Image Warping and Morphing 44

Page 45: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Morphing Simplest transition: linear

CS4243 Image Warping and Morphing 45

pi qi

ri

I J

morphing path

Page 46: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

CS4243 Image Warping and Morphing 46

Morphing path is actually like this:

Page 47: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Image Morphing Set time step ∆t = 1 / number of frames. Repeat for 0 ≤ t ≤ 1

Warp I to I(t) by mapping pi to ri(t). Warp J to J(t) by mapping qi to ri(t). Blend I(t) and J(t) into M(t)

Save M(t) into a video.

CS4243 Image Warping and Morphing 47

Page 48: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Example

CS4243 Image Warping and Morphing 48

Page 49: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Anything peculiar?

CS4243 Image Warping and Morphing 49

Sample frames

Page 50: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Summary For seamless morphing

Match all corresponding features. Need accurate transformation.

For smooth morphing Use smaller time step.

CS4243 Image Warping and Morphing 50

Page 51: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

Further Reading More sophisticated image warping: [Wolberg90]. More sophisticated image morphing: [Lee96]

CS4243 Image Warping and Morphing 51

Page 52: Leow Wee Kheng CS4243 Computer Vision and Pattern ...cs4243/lecture/imorph.pdfCS4243 Image Warping and Morphing 23 ( ,) 1 u a h k x y K k ∑ k = = parameters kernel function Which

References S.-Y. Lee and S. Y. Shin. Warp generation and transition control in

image morphing. In Interactive Computer Animation. Prentice Hall, 1996.

G. Wolberg. Digital Image Warping. IEEE Computer Society Press, 1990.

CS4243 Image Warping and Morphing 52