lecture-4 - cs.ucf.edu · lecture-4 computing optical flow hamburg taxi seq. 2. 3 horn&schunck...

19
Lecture-4 Computing Optical Flow Hamburg Taxi seq

Upload: others

Post on 02-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

1

Lecture-4

Computing Optical Flow

Hamburg Taxi seq

Page 2: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

2

Page 3: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

3

Horn&Schunck Optical Flow

df (x, y, t)dt

=∂f∂x

dxdt

+∂f∂y

dydt

+∂f∂t

= 0

brightness constancy eq0=++ tyx fvfuf

Sequence Image ),,( tyxf

Page 4: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

4

Horn&Schunck Optical Flow

f x y t f x y tfx

dxfy

dyft

dt( , , ) ( , , )= + + +∂∂

∂∂

∂∂

Taylor Series),,(),,( dttdyydxxftyxf +++=

brightness constancy eq0=++ tyx fvfuf0=++ dtfdyfdxf tyx

Interpretation of optical flow eq

y

t

y

x

ffu

ffv −−=

df

f ft

x y

=+2 2

d=normal flow

p=parallel flow

Equation of st.line

0=++ tyx fvfuf

Page 5: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

5

Horn&Schunck (contd)

variational calculus{( ) ( )}∫∫ + + + + + +f u f v f u u v v dxdyx y t x y x y

2 2 2 2 2λ

( ) ( )

( ) (( )

f u f v f f u

f u f v f f vx y t x

x y t y

+ + + =

+ + + =

λ

λ

2

2

0

0

( ) ( )( ) (( )f u f v f f u uf u f v f f v vx y t x av

x y t y av

+ + + − =

+ + + − =

λ

λ

00

u u fPD

v v fPD

av x

av y

= −

= −

P f u f v f

D f fx av y av t

x y

= + +

= + +λ 2 2

discrete version

min

yyxx uuu +=∆2

Algorithm-1

• k=0• Initialize u vK K

uK = uavk−1 − fx

PD

vk = vavK−1 − fy

PD

P f u f v f

D f fx av y av t

x y

= + +

= + +λ 2 2

• Repeat until some error measure is satisfied(converges)

Page 6: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

6

Derivatives

• Derivative: Rate of change of some quantity – Speed is a rate of change of a distance– Acceleration is a rate of change of speed

Derivative

xx fxfx

xxfxfdxdf

=′=∆

∆−−= →∆ )()()(lim 0

dtdva

dtdsv

=

= speed

acceleration

Page 7: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

7

Examples

3

42

42 xxdxdy

xxy

+=

+=

x

x

exdxdy

exy

−+=

+=

)1(cos

sin

Second Derivative

xxx fxf

dxdf

=′′= )(

22

2

3

42

122

42

xdx

yd

xxdxdy

xxy

+=

+=

+=

Page 8: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

8

Discrete Derivative

)()()(lim 0 xfx

xxfxfdxdf

x ′=∆

∆−−= →∆

)(1

)1()( xfxfxfdxdf ′=

−−=

)()1()( xfxfxfdxdf ′=−−=

(Finite Difference)

Discrete Derivative

)()1()1( xfxfxfdxdf ′=−−+=

)()1()( xfxfxfdxdf ′=+−=

)()1()( xfxfxfdxdf ′=−−= Left difference

Right difference

Center difference

Page 9: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

9

Example

F(x)=10 10 10 10 20 20 20F’(x)=0 0 0 0 10 0 0F’’(x)=0 0 0 0 10 -10 0

-1 1 left difference1 -1 right difference-1 0 1 center difference

Left difference

Derivatives in Two Dimensions

yyyxfyxff

yf

xyxxfyxff

xf

yxf

yy

xx

∆∆−−

==∂∂

∆∆−−

==∂∂

→∆

→∆

),(),(lim

),(),(lim

),(

0

0

x

y

yx

yx

ff

ff

ff

1

22

tandirection

)(magnitude

VectorGradient ),(

−==

+=

θ

Laplacian2 =+=∆ yyxx fff

(partial Derivatives)

Page 10: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

10

Derivatives of an Image

xf 101101101

−−−

yf 111000111 −−−

=

20202010102020201010202020101020202010102020201010

),( yxI

=

0000000303000030300003030000000

xI

Derivative & average

Prewit

Derivatives of an Image

=

0000000000000000000000000

yII(x,y) =

10 10 20 20 2010 10 20 20 2010 10 20 20 2010 10 20 20 2010 10 20 20 20

Page 11: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

11

Laplacian

0 −14

0

−14

1 −14

0 −14

0

fxx + fyy

Convolution

Page 12: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

12

Convolution (contd)

),(*),(),(

),(),(),(1

1

1

1

yxgyxfyxh

jigjyixfyxhi j

=

++= ∑ ∑−= −=

h(x, y) = f (x −1,y −1)g(−1,−1) + f (x, y −1)g(0,−1) + f (x +1,y −1)g(1,−1) + f (x −1, y)g(−1,0) + f (x, y)g(0,0) + f (x +1,y)g(1,0) + f (x −1, y +1)g(−1,1) + f (x, y +1)g(0,1) + f (x +1, y +1)g(1,1)

Derivative Masks

xf

image second1111

imagefirst 1111

−−

−−

yf

image second1111

imagefirst 1111

−−

−−

tf

image second1111

imagefirst 1111

−−−−

Apply first mask to 1st imageSecond mask to 2nd imageAdd the responses to get f_x, f_y, f_t

Page 13: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

13

Synthetic Images

Results

One iteration 10 iterations

4=λ

Page 14: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

14

Lucas & Kanade (Least Squares)

• Optical flow eq

tyx fvfuf −=+

999

111

tyx

tyx

fvfuf

fvfuf

−=+

−=+

M

=

9

1

9

1

9

1

t

t

y

y

x

x

f

f

vu

f

f

f

fMMM

tfAu =

• Consider 3 by 3 window

Lucas & Kanade

tTT

tTT

t

fAAAu

fAAuA

fAu

1)( −=

=

=

2)(min tyixi fvfuf ++∑

Page 15: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

15

Lucas & Kanade

0)(

0)(

=++

=++

yitiyixi

xitiyixi

ffvfuf

ffvfuf

2)(min tyixi fvfuf ++∑

( fxi∑ u + fyiv + f ti) fxi = 0

( fxi∑ u + fyiv + f ti) fyi = 0

fxi2∑ u + fxi∑ fyiv = − fxi∑ f ti

fxi fyi∑ u + fyi2∑ v = − fyi∑ f ti

fxi2∑ fxi fyi∑

fxi fyi∑ fyi2∑

uv

=

− fxi f ti∑

− fyi f ti∑

Page 16: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

16

Lucas & Kanade

=

∑∑

∑∑−

tiyi

tixi

yiyixi

yixixi

ff

ff

fff

fff

vu

1

2

2

−=

∑∑

∑∑

∑ ∑∑ tiyi

tixi

xiyixi

yixiyi

yixiyixi ff

ff

fff

fff

ffffvu

2

2

222 )(

1

∑ ∑∑

∑ ∑ ∑∑

∑ ∑∑

∑ ∑ ∑∑

−=

+−=

222

2

222

2

)(

)(

yixiyixi

tiyixiyixitixi

yixiyixi

tiyiyixitixiyi

ffff

fffffffv

ffff

fffffffu

Lucas-Kanade without pyramids

Fails in areas of large motion

Page 17: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

17

Lucas-Kanade with Pyramids

Comments

• Horn-Schunck and Lucas-Kanade optical method works only for small motion.

• If object moves faster, the brightness changes rapidly, 2x2 or 3x3 masks fail to estimate spatiotemporal derivatives.

• Pyramids can be used to compute large optical flow vectors.

Page 18: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

18

Page 19: Lecture-4 - cs.ucf.edu · Lecture-4 Computing Optical Flow Hamburg Taxi seq. 2. 3 Horn&Schunck Optical Flow df (x,y,t) dt = ... Algorithm-1 •k=0 • Initialize uv K K uK =u av k−1

19