Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... ·...

24
236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman c 2011 Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Transcript of Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... ·...

Page 1: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

236861 Numerical Geometry of Images

Tutorial 2

Calculus of variations II

Guy Rosman

c⃝2011

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 2: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

The Euler-Lagrange equation (reminder)

Given the functional

f (u) =

∫ x1

x0

F(x , u(x), u′(x)

)dx

with F ∈ C3 and all admissible u(x) having fixed boundary valuesu(x0) = u0 and u(x1) = u1.

An extremum of f (u) satisfies the differential equation

Fu −d

dxFu′ = 0

with the boundary conditions u(x0) = u0 and u(x1) = u1.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 3: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Special cases of the E-L equation

If the integrand does not depend on the independent variable x ,

f (u) =

∫ x1

x0

F(u(x), u′(x)

)dx ,

for a solution of the E-L equation, the first-order differentialequation

d

dx

(F − u′Fu′

)= 0,

or

F − u′Fu′ = const,

must hold (Beltrami identity).

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 4: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Proof of the Beltrami Identity

Using the full derivative of F by x we obtain

dF

dx=

∂F

∂uu′ +

∂F

∂u′u′′ +

∂F

∂x→

∂F

∂uu′ =

dF

dx− ∂F

∂u′u′′ − ∂F

∂x

Multiplying the E-L equation by u′ we obtain:

u′∂F

∂u− u′

d

dx

∂F

∂u′= 0,

or

u′∂F

∂u= u′

d

dx

∂F

∂u′

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 5: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Plugging the obtained identity into the E-L equation, we get:

dF

dx− ∂F

∂u′u′′ − ∂F

∂x− ∂F

∂uu′︸ ︷︷ ︸ = 0 →

dF

dx− ∂F

∂u′u′′ − ∂F

∂x− u′

d

dx

∂F

∂u′= 0 →

−∂F

∂x+

dF

dx− ∂F

∂u′u′′ − u′

d

dx

∂F

∂u′︸ ︷︷ ︸ = 0 →

−∂F

∂x+

d

dx

(F − u′

∂F

∂u′

)= 0

Using the assumption that ∂F∂x = 0 results in

d

dx

(F − u′

∂F

∂u′

)= 0

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 6: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Brachistochrone problem

I Formulation and first attempt to prove was done by Galileo,1638. Brachistos - shortest. Chronos - time.

I John Bernoulli – 1696 solved the problemand challenged math world (Acta Eroditorium)

“Given points A and B in a vertical plane, to find thepath AB down which a movable point M must, by virtueof its weight, proceed from A to B in the shortestpossible time”

- The solution curve is very known by the geometers (cycloid)

- He gave one year for the mathematicians of the time to solvethe problem

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 7: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Solutions were presented by

- Leibniz (received letter 9/6/1696, sent back solution16/6/1696)

- Newton - sent an anonymous answer the very night..

A

B

x1

y1

x2

y2

Figure: Brachistochrone

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 8: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Let ds =√

1 + y ′2dx be a length element.

Energy conservation

1

2m(dsdt

)2︸ ︷︷ ︸

kinetic

− mgy︸︷︷︸potential

≡ E0 =m

2V 20 −mgy0

⇒(dsdt

)2= 2g(α+ y), α =

V 20

2g− y0,

Our integral becomes:

T =

∫dt

dsds =

∫ x2

x1

√1 + y ′2dx√2g(α+ y)

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 9: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 1:

min∫ x2

x1

√1 + y ′2dx√y + α

Fx = 0 then the Euler -Lagrange equation is:

H = y ′Fy ′ − F = c

y′2√

1 + y ′2√y + α

−√1 + y ′2

√y + α

=−1√

1 + y ′2√y + α

= c −→

1√1 + y ′2

√y + α

=1√2b

b > 0

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 10: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Or, more plainly:(α+ y)(1 + y

′2) = 2b (1)

Note:

Fy =

√1 + y ′2

(α+ y)3/2= 0, (2)

so we cannot take a shortcut..Note: =⇒ y ′ ≡ 0 are not extremals of our functional because ofthe physical problem we solve (kinetic energy..).In order to solve ( 1), let us denote

y ′(x) = − tanτ

2, −π

2<

τ

2<

π

2.

=⇒ α+ y =2b

1 + y ′2. (3)

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 11: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

=2b

1 + tan2( τ2 )=

2b cos2( τ2 )

cos2( τ2 ) + sin2( τ2 )(4)

= b 2 cos2τ

2= b(1 + cos τ),

ory = b(1 + cos τ)− α.

dx

dτ=

dx

dy

dy

dτ=(4)

− 1

tan τ2

(−b sin τ)

= b(1 + cos τ) (5)

Integrating Eq. 5, we obtain

=⇒ x = a+ b(τ + sin τ) ,−π ≤ τ ≤ π.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 12: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 2: (Hyperbolic Geodesics)

min

∫ 2

1

√1 + y ′2

xdx

y(1) = 0 y(2) = 1

F =

√1 + y ′2

x

F is independent of y , and therefore we use

Fy ′ = c −→ y ′

x√

1 + y ′2= c

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 13: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

y′2 = c2x2(1 + y

′2)

y′2(1− c2x2) = c2x2

y ′ = ± cx√1− c2x2

y = ±√1− c2x2

c+ c2

(y − c2)2 + x2 =

1

c2

boundary conditions =⇒ c =1√5

c2 = 2

And the solution is:

(y − 2)2 + x2 = 5

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 14: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 3: Constrained maximumFind a curve y(x) with fixed endpoints y(±1) = 0 and perimeter

S =

∫ −1

−1

√1 + y ′2dx ,

which maximizes the area

A(y) =

∫ 1

−1

ydx .

SolutionConstruct the Lagrangian

L(y) =

∫ 1

−1

ydx + λ

(∫ 1

−1

√1 + y ′2dx − S

),

and denote

F (x , y , y ′) = y + λ

√1 + y ′2.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 15: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 3: Constrained maximum (cont.)The Euler-Lagrange equation

0 =d

dxFy ′ − Fy =

d

dx

(λy ′√1 + y ′2

)− 1.

Integration w.r.t. x yields

λy ′√1 + y ′2

= x − α,

where α = const. Substitute y ′ = tan θ:

λy ′√

1 + y ′2= λ

sin θcos θ√

1 + sin2 θcos2 θ

= λsin θcos θ√

sin2 + cos2 θcos2 θ

= λsin θ

cos θ

√cos2

1= λ sin θ,

from where

sin θ =x − α

λ.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 16: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 3: Constrained maximum (cont.)

Substituting again

y ′ = tan θ =sin θ

cos θ=

± sin θ√1− sin2 θ

=±(x − α)

λ√1− (x−α)2

λ2

=±(x − α)√λ2 − (x − α)2

.

Integration w.r.t. x yields (table of integrals or Mathematica)

y =√λ2 − (x − α)2 + β,

or

(x − α)2 + (y − β)2 = λ2

where β = const. The latter equation describes a part of a circle withradius λ centered at (α, β). The exact values of the constants aredetermined using the endpoint conditions and the perimeter constraint.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 17: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 4Note about the Beltrami identity: it merely states a necessarycondition for an extremum of the functional.Q: Show that a solution of the Beltrami identity does not have tosolve the Euler Lagrange equation.A: Look at ∫ (

1

2(u′)2 − u

)dx

and the function u ≡ 1, for which the Beltrami identity holds

d

dx

(F − u′Fu′

)=

d

dx

(1

2(u′)2 − u − u′(u′)

)=

d

dx

(−1

2(u′)2 − u

)= −(u′)(u′′)− u′ = 0,

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 18: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Problem 4 (Cont.)and yet,

Fu −d

dxFu′ =

−1− d

dx(u′) = −1− u′′ = −1.

In fact, according to the E-L equation, extrema of the functionalare of the form

u(x) = −x2 + ax + b

This is physically not very surprising – the integrand represents thekinetic energy T of a mass plus its potential energy −V , in 1D.The resulting functions describe a free-fall behavior, subject toinitial position and velocity. The functional is known as the actionintegral, or action.Hamilton’s principle states that the path of a particle (in a systemwhich conserves the total energy, E = T − V ) must be such thatit describes an extremum of the action integral.

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 19: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

A practical example:Optical flow – Horn and Schunck’s method

Given 2 images, we would like to find a field that translates pixelsfrom one image to the next

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 20: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Optical flow, Horn and Schunck’s method (cont.)

In a 1D world, we would look at an image flow field u(x) thatmoves pixels from I1 to I2. We would like to preserve thebrightness between the two images. This is known as thebrightness constancy assumption.Using 1st order Taylor approximation, we would get:

I1(x + u) ≈ I1(x) + I1,xu.

Using the brightness constancy assumption, we have

I1,xu + I1 − I2 ≈ 0

.. but this is only approximate, and our images are usually 2D..

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 21: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Optical flow, Horn and Schunck’s method (cont.)

In a 2D image case, we denote the field at each point asu(x , y), v(x , y). Taylor approximation of I now reads:

I1(x + u, y + v) ≈ I1 + I1,xu + I1,yv .

The brightness constancy assumption gives us the followingfunctional on u, v :∫

Ω(I1,xu + I1,yv + I1 − I2)

2dΩ

.. but this is not enough! We need some way to propagateinformation in the field.. Otherwise, the constraint

Ixu + Iyv = It

will not suffice (2 variables, 1 equation).

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 22: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Optical flow, Horn and Schunck’s method (cont.)

Since using a single constraint is not enough to determine u andv .. We therefore add regularization to the functional:∫

Ω

[(I1,xu + I1,yv + I1 − I2)

2 + λ(|∇u|2 + |∇v |2)]dΩ

Denoting It = I2 − I1, We can write the equation as:

∫Ω

[(I 2x u

2 + I 2y v2 + I 2t + 2Ix Iyuv + 2Ix Itu + 2Ix Itv)+λ(u2x + u2y + v2x + v2y )

]dΩ

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 23: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Optical Flow, Horn and Schunck’s method (cont.)

Writing the two Euler-Lagrange equations (for u and v), we get:

(2I 2x u + 2Ix Iyv) + λ

(d

dxux +

d

dyuy

)︸ ︷︷ ︸

∆u

= −2Ix It

(2Ix Iyu + 2I 2y v) + λ

(d

dxvx +

d

dyvy

)︸ ︷︷ ︸

∆v

= −2Iy It

We see that this regularization boils down to diffusing thecomponents u, v of the field.. This is not a coincidence!

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II

Page 24: Calculus of variations II - Technionwebcourse.cs.technion.ac.il/236861/Winter2011-2012/... · 236861 Numerical Geometry of Images Tutorial 2 Calculus of variations II Guy Rosman ⃝c

Optical Flow, Horn and Schunck’s method (cont.)If we add several more tricks, we can obtain a nice result, (aftersome work...):

Figure: Optical flow ( taken from A. Bruhn and J. Weickert, IJCV’05)

Guy Rosman 236861 - Tutorial 2 - Calculus of Variations II