Interpolation and Deformations A short...

30
Engineering Research Center for Computer Integrated Surgical Systems and Technology 1 600.445 Fall 2000; Updated: 10 October 2002 Copyright © R. H. Taylor Interpolation and Deformations A short cookbook

Transcript of Interpolation and Deformations A short...

Engineering Research Center for Computer Integrated Surgical Systems and Technology1 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Interpolation and DeformationsA short cookbook

Engineering Research Center for Computer Integrated Surgical Systems and Technology2 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Linear Interpolation

[ ]1

1

10 15 20

5

T

ρ

=

=

pr

[ ]2

2

40 30 20

20

T

ρ

=

=

pr

[ ]3

3

20 20 2

??

0

?

T

ρ

=

=

pr

10

Engineering Research Center for Computer Integrated Surgical Systems and Technology3 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Linear Interpolation

[ ]1

1

10 15 20 T=

=

p

q a

rr r

[ ]2

2

40 30 20 T=

=

p

q b

rrr

[ ]3

3

20 20 20

???

T=

=

p

q

rr ( )1

3+ −a b arr r

Engineering Research Center for Computer Integrated Surgical Systems and Technology4 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Linear Interpolation

2 2, Apr

1 1, Apr

( )3 1 2 1

3 ???A

λ= + −

=

p p p pr r r r

1

λ

( )1 2 1A A Aλ= + −

( ) 1 21 A Aλ λ= − +

( ) ( )( ) ( )

3 1 2 1

2 1 2 1

λ− −

=− −

p p p p

p p p p

r r r rir r r ri

Engineering Research Center for Computer Integrated Surgical Systems and Technology5 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bilinear Interpolation

, 1i j+ur 1, 1i j+ +u

r

1,i j+ur

( )1 λ−λ

( )1 λ−λ

( )1 µ−

µ

,i jur

Engineering Research Center for Computer Integrated Surgical Systems and Technology6 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bilinear Interpolation

,i jur

, 1i j+ur 1, 1i j+ +u

r

1,i j+ur

( )1 λ−λ

( )1 µ−

µ

( )1 µ−

µ

( )( ) ( ) ( )( )( ) ( ) ( )1, 1 1, , 1 ,

, 1, , , 1 , 1, 1 ,

( , ) 1 1 1i j i j i j i j

i j i j i j i j i j i j i j

λ µ λ µ µ λ µ µ

λ µ λµ

+ + + +

+ + + +

= + − + − + −

= + − + − + −

u u u u u

u u u u u u u

r r r r rr r r r r r r

Engineering Research Center for Computer Integrated Surgical Systems and Technology7 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bilinear Interpolation

, ,,i j i jAur

, 1 , 1,i j i jA+ +ur

1, 1 1, 1,i j i jA+ + + +ur

1, 1,;i j i jA+ +ur

( ) { } { }, 1, 1, 1 , 1, interpolate( , , , , , )i j i j i j i jλ µ λ µ + + + +=u u u u ur r r r r

( ) { } { }, 1, 1, 1 , 1, interpolate( , , , , , )i j i j i j i jA A A A Aλ µ λ µ + + + +=

Engineering Research Center for Computer Integrated Surgical Systems and Technology8 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

N-linear Interpolation

{ }

{ }

( )

1 2

, , 1

, ,

NlinearInterpolate( , )

1 Nli

1

Let

= , with 0

be a set of interpolation parameters, and let

be a set of constants. Then we define:

N

N N k

N

N

A A

Λ λ λ ≤ λ ≤

=

Λ =

− λ

A

A

{ }{ }

1

1

1 1 2

1 2 1 2

nearInterpolate( , , , )

NlinearInterpolate( , , , )

( ) ( , , )NlinearInterpolate( , )

1

NOTE: Sometimes in this situation we will use notation

N

N N

N

N N

N N

N

A A

A A

A A

− +

Λ

+ λ Λ

Λ = λ λ= Λ A

……

Engineering Research Center for Computer Integrated Surgical Systems and Technology9 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Barycentric Interpolation

1pr

2pr

2 1λ −p pr r

( ) 2 11− λ −p pr r

( ) ( ) 2 11λ = − λ + λp p pr r r( ) ( ) 2 1

1 2

1

1

λ = − λ + λ

= λ + µλ + µ =

p p p

p p

r r rr r

Engineering Research Center for Computer Integrated Surgical Systems and Technology10 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Barycentric Interpolation

1pr 2p

r

3pr

( ), ????λ µ =pr ( ) ( )3 1 3 2 3

1 2 3

, ( )

(1 )

λ µ = + λ − + µ −

= λ + µ + − λ − µ

p p p p p p

p p p

r r r r r rr r r

( ) ( )

( )

3 1 3 2 3

1 2 3

1 2 3

, ( )

(1 )

, , 1 where

λ µ = + λ − + µ −

= λ + µ + − λ − µ

λ µ ν = λ + µ + ν λ + µ + ν =

p p p p p p

p p p

p p p p

r r r r r rr r r

r r r r

( ) ( )

( )( )

3 1 3 2 3

1 2 3

1 2 3

1 2 3

, ( )

(1 )

, , 1

, ,

where

A A A A

λ µ = + λ − + µ −

= λ + µ + − λ − µ

λ µ ν = λ + µ + ν λ + µ + ν =

λ µ ν = λ + µ + ν

p p p p p p

p p p

p p p p

r r r r r rr r r

r r r r

1A

2A

3A

Engineering Research Center for Computer Integrated Surgical Systems and Technology11 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Barycentric Interpolation

1pr 2p

r

3pr

31 2

1 1 1 1

λ = µ ν

pp pprr rr

1A

2A

3A

Engineering Research Center for Computer Integrated Surgical Systems and Technology12 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Barycentric Interpolation

{ }

{ }

1

1 2

, , 1 1

, ,

BarycentricInterpolate( , )

N

N

N k kk

A A

=

Λ λ λ ≤ λ ≤ λ =

=

Λ =

A

A

r …

r …

rr

1

Let

= , with 0 and

be a set of interpolation parameters, and let

be a set of constants. Then we define:

1

( ) ( , , ) BarycentricInterpolate( , )

N

k kk

N N N

A=

Λ = λ

Λ = λ λ = Λ

∑A

A A A

rri

…1

NOTE: Sometimes in this situation we will use notation

NOTE: This is a special case of barycentric Bezier

polynomial interpo stlations (here, 1 degree)

Engineering Research Center for Computer Integrated Surgical Systems and Technology13 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Interpolation of functions

v

( )y v

01

Engineering Research Center for Computer Integrated Surgical Systems and Technology14 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Fitting of interpolation curves

• The discussion below follows (in part)

G. Farin, Curves and surfaces for computer-aided geometric design, a practical guide, Academic Press, Boston, 1990, chapter 10 and pp 281-284.

Engineering Research Center for Computer Integrated Surgical Systems and Technology15 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

v

01

N,k

,

Note that many forms of polynomial may be usedfor the P ( ). One common (not very good) choice

is the power basis:

( )

Better choices are the Bernstein plynomials and the b-spline basis functi

= kN k

v

P v v

ons, which we will discuss ina moment

1-D Interpolation

{ }0 0

0

0 ,0

Given set of known values ( ),..., ( ) ,

find an approximating polynomial ( ,..., ; )

( ,..., ; ) ( )=

= ∑

m m

N

N

N k N kk

y v y v

y P c c v

P c c v c P v

Engineering Research Center for Computer Integrated Surgical Systems and Technology16 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

1-D Interpolation

{ }0 0

0

0 ,0

,0 0 , 0 0

,0 ,

Given set of known values ( ),..., ( ) ,

find an approximating polynomial ( ,..., ; )

( ,..., ; ) ( )

To do this, solve:

( ) ( )

( ) ( )

=

=

LM O M M

L

m m

N

N

N k N kk

N N N

N m N N m m

y v y v

y P c c v

P c c v c P v

P v P v c

P v P v c

0 ≅

Mm

y

y

Engineering Research Center for Computer Integrated Surgical Systems and Technology17 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bezier and Bernstein Polynomials

• Excellent numerical stability for 0<v<1• There exist good ways to convert to more

conventional power basis

( ) ( )

( )

=

=

= −

=

= −

…00

,0

,

, , ; 1

( )

( ) 1

NN k N

N kk

N

k N kk

N k kN k

NP c c v c v v

k

c B v

Nwhere B v v v

k

Engineering Research Center for Computer Integrated Surgical Systems and Technology18 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Barycentric Bezier Polynomials

• Excellent numerical stability for c<0<1• There exist good ways to convert to more

conventional power basis

( )00

,0

,

, , ; ,

( , )

( , ) u+v=1

=

=

=

=

=

…N

N k NN k

k

N

k N kk

N k kN k

NP c c u v c u v

k

c B u v

Nwhere B u v u v

k

Engineering Research Center for Computer Integrated Surgical Systems and Technology19 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bezier Curves

( )0 ,0

Suppose that the coefficients are multi-dimensional

vectors (e.g., 2D or 3D points). Then the polynomial

, , ; ( )

computed over the range 0 1 generates a Bezier

curve w

j

N

N k N kk

c

P c c v c B v

v=

=

≤ ≤

uur

uur uur uur…

ith control vertices .jcuur

0c

1c

3c

2c

Engineering Research Center for Computer Integrated Surgical Systems and Technology20 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Bezier Curves: de Casteljau Algorithm

( )0 0

0

1 11

Given coefficients , Bezier curves can be generated

recursively by repeated linear interpolation:

, , ;

(1 )

j

NN

j jk k kj j j

c

P c c v b

where

b c

b v b vb− −+

=

== − +

uur

uur uur…

uur

0

rc

1

rc

3

rc

2

rc

( )1 v−v

v

v

( )1 v−( )1 v−

Engineering Research Center for Computer Integrated Surgical Systems and Technology21 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Iterative Form of deCasteljau Algorithm

1

0

Step 1: for 0

Step 2 : for 1 step 1 until do

for 0 step 1 until do(1 )

Step 3: return

j j

j j j

b c j N

k k N

j j N kb v b vb

b+

← ≤ ≤

← =← = −← − +

Engineering Research Center for Computer Integrated Surgical Systems and Technology22 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Advantages of Bezier Curves

• Numerically very robust• Many nice mathematical properties• Smooth

• “Global” (may be viewed as a disadvantage)

Engineering Research Center for Computer Integrated Surgical Systems and Technology23 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

B-splines

0 1

0 2 2 1

1 1

Given

coefficient values { , , }

"knot points" { , , } with

D = "degree" of desired B-spline

Can define an interpolated curve ( , ; ) on

Then

(

+ −

+ − +

− + −

=

= ≤

≤ <

r rLL

L D

L D i i

D L D

c c

u u u u

P u u u u

P

C

u

C u

1

0

; ) ( )

where ( ) are B-spline basis polynomials (discussed

later)

+ −

=

= ∑ rL DD

j jj

Dj

u c N u

N u

C

Engineering Research Center for Computer Integrated Surgical Systems and Technology24 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

deBoor Algorithm

1

1

0

Given , , as before, can evaluate ( , ; )recursively as follows: Step 1: Determine index such that

Step 2: Determine multplicity r such that

Step 3: Det for 1

i i

i r i r i

j j

D P u

i u u u

u u u

d c i D j

+

− − +

≤ <

= = =

= − + ≤

u c c u

L

1

11 1j 1

1 1

1

Step 4: Compute ( , ; ) recursively, where

d

D ri

j D k jk k kj j

j D k j j D k j

i

P u du u u u

d du u u u

−+

+ − −− −−

+ − − + − −

≤ +

=− −

= +− −

c u

Engineering Research Center for Computer Integrated Surgical Systems and Technology25 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

B-spline basis functions

1

0

10

1 1 11

1 1

Given , , D as before

( , ; ) ( )

where

1( )

0 Otherwise

( ) ( ) ( ) for 0

+ −

=

− +− −+

+ − − +

=

≤ ≤=

− −

= + >− −

∑ rL DD

j jj

j jj

j j kk k kj j j

j k j j k j

P u c N u

u u uN u

u u u uN u N u N u k

u u u u

C u

C u

Engineering Research Center for Computer Integrated Surgical Systems and Technology26 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

Some advantages of B-splines

• Efficient• Numerically stable • Smooth• Local

Engineering Research Center for Computer Integrated Surgical Systems and Technology27 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

2D Interpolation

0 0

00 0 0

0

0

Consider the 2D polynomial

( , ) ( ) ( )

( )[ ( ), , ( )]

( )

where ( ) and ( ) can be arbitrary

functions (good choices Bernstein polynom

m n

ij i ji j

n

m

m mn n

i j

P u v c A u B v

c c B vA u A u

c c B v

A u B v

= =

=

=

∑∑L

L M O M ML

ials or B-Spline basis functions. Suppose that we have samples

( , ) for 0,...,

We want to find an approximating polynomial P. s s su v s N= =sy y

Engineering Research Center for Computer Integrated Surgical Systems and Technology28 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

2D Interpolation: Finding the best fit

[ ][ ]

0

0

Given a set of sample values ( , ) corresponding to 2D coordinates

( , ), left hand side basis functions ( ), , ( ) and right hand side

basis functions ( ), , ( ) , the goal is to find the

s s s

s s m

n

u v

u v A u A u

B v B v

y

LL

00

01

0 0 0 1

matrix of

coefficients .

To do this, solve the least squares problem

( , ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

ij

s s s s s s s i s j s m s n sij

mn

u v A u B v A u B v A u B v A u B v

≈ •

C

c

cc

yc

c

M ML LM M

Engineering Research Center for Computer Integrated Surgical Systems and Technology29 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

2D Interpolation: Finding the best fit

{ } { }{ }

0 0

0

A common special case arises when the ( , ) form a regular grid. In this

case we have , , and , , . For each value

, , solve the row least squares problem

( , )

u v

v

s s

s N s N

j N s

s s j

u v

u u u v v v

v v v N

u v

∈ ∈

y

L LLM

M

0

0

00 01 0 0 0

10 11 1

0 1

( ) ( )

for the unknown m-vector . Then solve m n-variable least squares problems

( )

v v v

j

s m s

jm

m

m

N N N m

A u A u

B v

≈ •

j

X

X

X

X X XX X X

X X X

M L ML M

M L M

LL

M M MM M O MM M M

L

1 0 0 00 10 0

0 1 1 1 1 01 11 1

0 1

0 1

0

( ) ( )( ) ( ) ( )

( ) ( ) ( )

for the vectors , , . Note that this latter step requires ov v v

n m

n m

n n mn

N N n N

j jn

B v B vB v B v B v

B v B v B v

c c cc c c

c c c

c c

L LL L

M M M M M O MM M O M LM M M

LL nly 1 SVD or

similar matrix computation.

Engineering Research Center for Computer Integrated Surgical Systems and Technology30 600.445 Fall 2000; Updated: 10 October 2002

Copyright © R. H. Taylor

2D Interpolation: Finding the best fit

• There are a number of caveats to the “grid” method on the previous slide. (E.g., you need enough data for each of the least squares problems). But where applicable the method can save computation time since it replaces a number of m and n variable least squares problems for one big m x n problem

• Note that there is a similar trick that you can play by grouping all the common ui elements together.

• Note that the y’s and the c’s do not have to be scalar numbers. They can be Vectors, Matrices, or other objects that have appropriate algebraic properties