37
Introduction to Computer Graphics 12. Warping and Morphing National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor

Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Introduction to Computer

Graphics12. Warping and Morphing

National Chiao Tung Univ, Taiwan

By: I-Chen Lin, Assistant Professor

Page 2: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Outline

Image Warping

Image Morphing

Warping of 3D model

Reference:

• T. Beier, S. Neely, "Feature Based Image Metamorphosis," Proc. SIGGRAPH'92, pp. 35-42, 1992.

• A.W.F. Lee, D.Dobkin, W.Sweldens, P. Schroder, “Multiresolution Mesh Morphing, Proc. ACM SIGGRAPH’99. pp.343-350.

• Related articles in SIGGRAPH, Eurographics, ACM Trans. Graphics, IEEE Trans. Visualization and Computer Graphics, and other graphics related publications.

Page 3: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Image Warping

Rearranging pixels of a picture.

It’s useful for both image processing and for computer graphics (namely, for texture mapping).

Finding corresponding points in the source and destination images.

This function is called the “mapping” or “transformation”.

Page 4: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Image Warping (cont.)

u

v source

x

y destination

Forward mapping : (x, y) = f (u, v)

Inverse mapping : (u, v) = f’ (x, y)

Page 5: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Mapping types

How to create the mapping systematically?

Simple mappings

affine mapping

projective mapping

bilinear mapping

………

Page 6: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Affine Mappings

u = ax+by+c

v = dx+ey+f

A combination of 2-D scale, rotation, and translation transformations.

Allows a square to be distorted into any parallelogram.

6 degrees of freedom.

Inverse is of same form (is also affine).

Page 7: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Projective Mappings

u = (ax+by+c)/(gx+hy+i)

v = (dx+ey+f)/(gx+hy+i)

Linear numerator and denominator.

If g=h=0 then you get affine as a special case.

Allows a square to be distorted into any quadrilateral.

8 degrees of freedom.

Inverse is of same form (is also projective)

u = uq/q , v = vq/q

Page 8: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Bilinear Mappings

u=axy+bx+cy+d

v=exy+fx+gy+h

If a=e=0 then you get affine as a special case.

Allows a square to be distorted into any quadrilateral.

8 degrees of freedom.

Not recommended for if you need the inverse.

Page 9: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Bilinear Interpolation

An inexpensive, continuous function that interpolates data on a square grid.

At (0,0), (1,0), (0,1), and (1,1), the corner values are p00, p10, p01, p11.

pxy = (1-x)*(1-y)*p00 + x*(1-y)*p10 + (1-x)*y*p01 + x*y*p11

Another form,

px0 = p00 + x*(p10-p00)

px1 = p01 + x*(p11-p01)

pxy = px0 + y*(px1-px0)

What’s the different between these two forms?

Page 10: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Performing an Image Warp Source scanning:

for v = vmin to vmax

for u = umin to umax

x = x(u,v)

y = y(u,v)

copy pixel at source[u,v] to dest[x,y]

Destination scanning:for y = ymin to ymax

for x = xmin to xmax

u = u(x,y)

v = v(x,y)

copy pixel at source[u,v] to dest[x,y]Is there any problem?

Page 11: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

More Complex Situations

How to warp an image with a more complex function?

If the source and destination is of structural similarity

piecewise affine over a triangulation.

piecewise projective over a quadrilaterization.

piecewise bilinear over a rectangular grid.

Page 12: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

More Complex Situations …

Arbitrary functions can be used.

Store u[x,y] and v[x,y] in large arrays

Learning techniques: e.g. neural network

………

Popular methods in computer graphics:

Beier-Neely warp (popular for image morphing)

Radial-basis-function (RBF) based data scattering.

………

Page 13: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Morphing

Short for “metamorphosis”.

Early films used cross-dissolving only, but that looks artificial, non-physical.

Morph = warp the shape + cross-dissolve the colors.

If the mappings are defined, cross-dissolving can simply be performed by interpolation.

Page 14: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Feature-Based Image

Metamorphosis

Proposed by Thaddeus Beier, Shawn Neely

Prof. ACM SIGGRAPH’92, pp. 35-42.

Page 15: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Motivation

To transform one image smoothly into another image

Page 16: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Overview

Image

warping

Image

warping

Color

Blending

Page 17: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Concepts (Beier-Neely warp )

How to find a controllable mapping function with little manual assistance?

What’s the problem of mesh-based warping tech.?

How about the concept of “field”?

Page 18: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

How to control the mapping? Features

Points

Lines

Curves

……

Fields

Linear

quadratic

……

Source destination

Using control lines

Page 19: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

With only one pair of lines

To map the pixel X from pixel X' by corresponding lines PQ and P'Q'.

Page 20: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

With only one pair of lines Scan every pixels on the destination image and compute

the corresponding pixels on the source image.

Page 21: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

An example (only one pair of lines)

Page 22: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

The properties of this approach

Transforms each pixel coordinate by a rotation, translation ,and/or scale.

The image is scaled along the direction of lines by the ratio of the length of the line.

Pure rotation and translation.

Affine transformations. (uniform scales and shear are not possible to specify.)

Page 23: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

With multiple pairs of lines Specifying more complex transformations.

The displacement Di = Xi’-X.

A weighted average of these displacements is calculated.

Page 24: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

With multiple pairs of lines (cont.)

Page 25: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

With multiple pairs of lines (cont.)For each pixel X in the destination

DSUM = (0,0)

weightsum = 0

For each line Pi Qi

calculate u,v based on Pi Qi

calculate X'i based on u,v and Pi'Qi'

calculate displacement Di = Xi' - Xi for this line

dist = shortest distance from X to Pi Qi

weight = (length^p / (a + dist))^b

DSUM += Di * weight

weightsum += weight

X' = X + DSUM / weightsum

destinationImage(X) = sourceImage(X')

Page 26: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

An example with two line pairs

Page 27: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Morphing between two images

1. Assign the control lines.

2. CL(t) = (1-t)CL(0)+t CL(1)

3. Generate I0(t), I1(t) according to CL(t)

4. I(t) = (1-t)I0(t) + t I1(t)

Source

CL(0)

I(0)

Destination

CL(1)

I(1)

CL(t)

I0(t)

CL(t)

I1(t)

Page 28: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Performance

Proportional to the number of lines times the number of pixel.

Design time of metamorphosis is the dominant time in interactive design.

Page 29: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Advantage and disadvantage Advantages

It’s much more expressive.

The animator simply has to describe how lines in a source image are mapped into lines in a destination image.

The mesh warping is much less intuitive.

Disadvantages This algorithm must compute the effect of every feature

line on the movement of that pixel. -> slow!

In contrast, mesh warping has only local control .

Sometimes unexpected interpolations are generated.

pixel may be far away from all lines.

Page 30: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Disadvantage (cont.) The algorithm might make a mistake in computing how

that pixel should move during morphing.

Page 31: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Animated sequences Need a set of line segments at key frames for each

sequence.

A sequence from Michael Jackson’s MTV “Black or White”

Page 32: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

View morphing Is this warping/morphing tech. applicable to all kinds of

image transitions?

2D image

morphing

What we want :

Out of the scope of an undergraduate CG course

Page 33: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Warping 3D model

For instance, head model adjustment…

Page 34: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Warping 3D model

You can drag all vertices (more than 6000) or drag

feature samples…

Drag by users

What are the

displacement ?

?

?

?

Page 35: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

Warping 3D model

There are hundreds of papers about mesh morphing.

You may extend the Beier-Neely warp/morphing from images to 3d models.

Besides control lines, you may also use control points or other control primitives.

Page 36: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

An mesh morphing algorithm

A.W.F. Lee, D.Dobkin, W.Sweldens, P. Schroder, “Multiresolution Mesh Morphing, Proc. ACM SIGGRAPH’99. pp.343-350.

Page 37: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG10/CG_12_Morphing_S10.pdf · Introduction to Computer Graphics 12. ... for x = xmin to xmax u = u(x,y) v =

An mesh morphing algorithm (cont.)

Assign feature points.

Finding the corresponding points.

Interpolation