computational photography and image manipulation cmpt 469...

154
Computational Photography and Image Manipulation CMPT 469 / 985, Fall 2019 Week 10 Transforms and Panoramas 1

Upload: others

Post on 07-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Computational Photography and Image ManipulationCMPT 469 / 985, Fall 2019

Week 10

Transforms and Panoramas

1

Page 2: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Slide credits

• Slides thanks to James Tompkin along with his acknowledgements.

2

Page 3: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

P9 papers – presentations on Nov 19, Tuesday

• Zhu et al., AverageExplorer: Interactive Exploration and Alignment of Visual Data Collections, SIGGRAPH 2014

• Presentation

• Discussion:

• Arev et al., Automatic Editing of Footage from Multiple Social Cameras, SIGGRAPH 2014

• Presentation:

• Discussion:

3

Page 4: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image Transformations

image filtering: change range of image

g(x) = T(f(x))

f

x

T

f

x

f

x

T

f

x

image warping: change domain of image

g(x) = f(T(x))

Page 5: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image Transformations

T

T

f

f g

g

image filtering: change range of image

g(x) = T(f(x))

image warping: change domain of image

g(x) = f(T(x))

Page 6: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Parametric (global) warping

Transformation T is a coordinate-changing machine:

p’ = T(p)

What does it mean that T is global and parametric?• Is the same for any point p

• Can be described by just a few numbers (parameters)

Let’s represent T as a matrix:

p’ = Mp

T

p = (x,y) p’ = (x’,y’)

𝑥′𝑦′

=𝑎 𝑏𝑐 𝑑

𝑥𝑦

𝑥′𝑦′

= 𝑴𝑥𝑦

Page 7: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

What happens?

𝑥′𝑦′

=1 00 1

𝑥𝑦1.

Input image

𝑥′𝑦′

=2 00 2

𝑥𝑦

2.

𝑥′𝑦′

=2 00 0.5

𝑥𝑦

3.

4. 𝑥′𝑦′

=−1 00 0.5

𝑥𝑦𝑥′

𝑦′=

1 0.10 1

𝑥𝑦

5.

Page 8: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Think-Pair-Share – What happens?

Input imageOutput image

1.2.

3.

4.

𝑥′𝑦′

1 −0.20 1

𝑥𝑦

𝑥′𝑦′

=1 0.10 1

𝑥𝑦

0,0

𝑥′𝑦′

=1 00 1

𝑥𝑦1.

𝑥′𝑦′

=2 00 2

𝑥𝑦

2.

𝑥′𝑦′

=2 00 0.5

𝑥𝑦

3.

4. 𝑥′𝑦′

=−1 00 0.5

𝑥𝑦𝑥′

𝑦′=

1 0.10 1

𝑥𝑦

5.

0,0

5.

Page 9: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2x2 Matrices

2D Mirror about Y axis

yyxx

=−=

''

−=

yx

yx

1001

''

2D Mirror over (0,0)

yyxx

−=−=

''

−=

yx

yx

1001

''

Page 10: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Scaling

Scaling operation:

Or, in matrix form:

byy

axx

=

=

'

'

=

y

x

b

a

y

x

0

0

'

'

scaling matrix S

What’s the inverse of S?

Uniform scaling => a = b

2

X2,

Y0.5

Page 11: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2-D Rotation

x = r cos (f)

y = r sin (f)

x’ = r cos (f + )

y’ = r sin (f + )

Trigonometric identity for angle sum

x’ = r cos(f) cos() – r sin(f) sin()

y’ = r sin(f) cos() + r cos(f) sin()

Substitute…

x’ = x cos() - y sin()

y’ = x sin() + y cos()

(x, y)

(x’, y’)

f

r

r

Page 12: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2-D Rotation

This is easy to capture in matrix form:

Even though sin() and cos() are nonlinear functions of ,

• x’ is a linear combination of x and y

• y’ is a linear combination of x and y

What is the inverse transformation?

• Rotation by –

• For rotation matrices

( ) ( )

( ) ( )

−=

y

x

y

x

cossin

sincos

'

'

TRR =−1

R

Properties of rotation matrices:

- Square

- Determinant is 1det = cos 𝜃 cos 𝜃 − (− sin 𝜃 sin(𝜃))

- Orthogonal basis (inverse is

transpose). This means:

- Dot product of any row or column

with itself is 1.

- Dot product of a row with any

other row is 0.

- Dot product of a column with any

other column is 0.

Page 13: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2x2 Matrices

What types of transformations can be

represented with a 2x2 matrix?

2D Identity?

yyxx

==''

=

yx

yx

1001

''

2D Scale around (0,0)?

ysy

xsx

y

x

*'

*'

=

=

=

y

x

s

s

y

x

y

x

0

0

'

'

Page 14: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2x2 Matrices

What types of transformations can be

represented with a 2x2 matrix?

2D Rotate around (0,0)?

yxyyxx

*cos*sin'*sin*cos'

+=−=

−=

y

x

y

x

cossin

sincos

'

'

2D Shear?

yxshy

yshxx

y

x

+=

+=

*'

*'

=

y

x

sh

sh

y

x

y

x

1

1

'

'

Page 15: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2x2 Matrices

What types of transformations can be

represented with a 2x2 matrix?

2D Translation?

y

x

tyy

txx

+=

+=

'

'

Only linear 2D transformations

can be represented with a 2x2 matrix

NO!

Page 16: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Parametric (global) warping

Examples of parametric warps:

Translation

RotationScale / aspect

Shear

perspective cylindrical

Mirror

2x2 matrices

Page 17: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

All 2D Linear Transformations

Linear transformations are combinations of …

• Scale,

• Rotation,

• Shear, and

• Mirror

Properties of linear transformations:

• Origin maps to origin

• Lines map to lines

• Parallel lines remain parallel

• Ratios are preserved

• Closed under composition

=

y

x

dc

ba

y

x

'

'

=

yx

lkji

hgfe

dcba

yx''

Page 18: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous Coordinates

Q: How can we represent translation as a 3x3 matrix?

y

x

tyy

txx

+=

+=

'

'

Page 19: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous Coordinates

Represent coordinates in 2

dimensions with a 3-vector

⎯⎯⎯⎯⎯ →⎯

1

coords shomogeneou y

x

y

xHomogeneous

coords

Page 20: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous Coordinates

Add a 3rd coordinate to every 2D point

• (x, y, w) represents a point at location (x/w, y/w)

• (x, y, 0) represents a point at infinity

• (0, 0, 0) is not allowed

Convenient coordinate

system to represent many

useful transformations 1 2

1

2(2,1,1) or (4,2,2) or (6,3,3)

x

y

Page 21: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous Coordinates

Q: How can we represent translation as a 3x3 matrix?

A: Using the rightmost column:

=

100

10

01

y

x

t

t

ranslationT

y

x

tyy

txx

+=

+=

'

'

Page 22: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Translation

Example of translation

+

+

=

=

11100

10

01

1

'

'

y

x

y

x

ty

tx

y

x

t

t

y

x

tx = 2

ty = 1

Homogeneous Coordinates

Page 23: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Basic 2D Transformations

Basic 2D transformations as 3x3 matrices

=

1100

0cossin

0sincos

1

'

'

y

x

y

x

=

1100

10

01

1

'

'

y

x

t

t

y

x

y

x

=

1100

01

01

1

'

'

y

x

sh

sh

y

x

y

x

Translate

Rotate Shear

=

1100

00

00

1

'

'

y

x

s

s

y

x

y

x

Scale

Page 24: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Matrix Composition

Transformations can be combined by matrix multiplication

because they are linear!

=

w

yx

sysx

tytx

w

yx

100

0000

1000cossin0sincos

100

1001

'

''

p’ = T(tx,ty) R() S(sx,sy) p

Page 25: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Parametric (global) warping

Examples of parametric warps:

Translation

RotationScale / aspect

ShearMirror

2x2 matrices

3x3

homogeneous

matrices

Page 26: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Affine Transformations

Affine transformations are combinations of …

• Linear transformations, and

• Translations

Properties of affine transformations:

• Origin does not necessarily map to origin

• Lines map to lines

• Parallel lines remain parallel

• Ratios are preserved

• Closed under composition

• Models change of basis

Will the last coordinate w always be 1?

=

w

yx

fedcba

w

yx

100

''

Page 27: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective Transformations

Projective transformations …

• Affine transformations, and

• Projective warps

Properties of projective transformations:

• Origin does not necessarily map to origin

• Lines map to lines

• Parallel lines do not necessarily remain parallel

• Ratios are not preserved

• Closed under composition

• Models change of basis

=

w

yx

ihg

fedcba

w

yx

'

''

Page 28: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Parametric (global) warping

Examples of parametric warps:

Translation

RotationScale / aspect

Shear

perspective

Mirror

2x2 matrices

3x3 matrices

Page 29: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

2D image transformations

These transformations are a nested set of groups

• Closed under composition and inverse is a member

Page 30: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Recovering Transformations

What if we know f and g and want to recover

the transform T?• e.g. better align images from Project 1

• willing to let user provide correspondences

– How many do we need?

x x’

T(x,y)

y y’

f(x,y) g(x’,y’)

?

Page 31: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Translation: # correspondences?

How many correspondences needed for

translation?

How many Degrees of Freedom?

What is the transformation matrix?

x x’

T(x,y)

y y’

?

=

100

'10

'01

yy

xx

pp

pp

M

Page 32: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Euclidian: # correspondences?

How many correspondences needed for

translation+rotation?

How many DOF?

x x’

T(x,y)

y y’

?

Page 33: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Affine: # correspondences?

How many correspondences needed for affine?

How many DOF?

x x’

T(x,y)

y y’

?

Page 34: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective: # correspondences?

How many correspondences needed for projective?

How many DOF?

x x’

T(x,y)

y y’

?

Page 35: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image warping

Given a coordinate transform (x’,y’) = T(x,y) and

a source image f(x,y), how do we compute a

transformed image g(x’,y’) = f(T(x,y))?

x x’

T(x,y)

f(x,y) g(x’,y’)

y y’

Page 36: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

f(x,y) g(x’,y’)

Forward warping

Send each pixel f(x,y) to its corresponding location

(x’,y’) = T(x,y) in the second image

x x’

T(x,y)

Q: what if pixel lands “between” two pixels?

y y’

Page 37: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

f(x,y) g(x’,y’)

Forward warping

Send each pixel f(x,y) to its corresponding location

(x’,y’) = T(x,y) in the second image

x x’

T(x,y)

Q: what if pixel lands “between” two pixels?

y y’

A: distribute color among neighboring pixels (x’,y’)

– Known as “splatting”

– Check out griddata in Matlab

Page 38: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

f(x,y) g(x’,y’)x

y

Inverse warping

Get each pixel g(x’,y’) from its corresponding

location

(x,y) = T-1(x’,y’) in the first image

x x’

Q: what if pixel comes from “between” two pixels?

y’T-1(x,y)

Page 39: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

f(x,y) g(x’,y’)x

y

Inverse warping

Get each pixel g(x’,y’) from its corresponding location

(x,y) = T-1(x’,y’) in the first image

x x’

T-1(x,y)

Q: what if pixel comes from “between” two pixels?

y’

A: Interpolate color value from neighbors– nearest neighbor, bilinear, Gaussian, bicubic

– Check out interp2 in Matlab

Page 40: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Forward vs. inverse warping

Q: Which is better?

A: usually inverse—eliminates holes• however, it requires an invertible warp function—not always possible...

Page 41: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Pinhole camera model

Forsyth

f

f = Focal length

c = Optical center of the camera

c

Real

object

Page 42: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projection: world coordinates→image coordinates

Camera

Center

(0, 0, 0)

=

Z

Y

X

P.

.

. f Z Y

=

V

Up

.V

U

Z

fXU *−=

Z

fYV *−=

What is the effect if f and Z are equal?

p = distance from

image center

Image

center

(u0, v0)

Page 43: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Slide Credit: Savarese

Camera (projection) matrix

XtRKx =x: Image Coordinates: (u,v,1)

K: Intrinsic Matrix (3x3)

R: Rotation (3x3)

t: Translation (3x1)

X: World Coordinates: (X,Y,Z,1)

Ow

iw

kw

jwR,t

X

x

Extrinsic Matrix

Page 44: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective geometry

• 2D point in cartesian = (x,y) coordinates

• 2D point in projective = (x,y,w) coordinates

Idea from www.tomdalling.com

Y

X

Projector

Page 45: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective geometry

• 2D point in cartesian = (x,y) coordinates

• 2D point in projective = (x,y,w) coordinates

Y

X

Projector W

Idea from www.tomdalling.com

Page 46: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Varying w

w1 w2 < w1

Projected image becomes smaller.

Y

X

Projector

Y

X

Projector

Page 47: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective geometry

• 2D point in projective = (x,y,w) coordinates

– w defines the scale of the projected image.

– Each x,y point becomes a ray!

Y

X

Projector W

Page 48: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projective geometry

• In 3D, point (x,y,z) becomes (x,y,z,w)

• Perspective is w varying with z:

– Objects far away are appear smaller

B’

C’

Page 49: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous coordinates

Converting to homogeneous coordinates

2D (image) coordinates 3D (scene) coordinates

Converting from homogeneous coordinates

2D (image) coordinates 3D (scene) coordinates

Page 50: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homogeneous coordinates

Scale invariance in projection space

=

=

w

y

wx

kw

ky

kwkx

kw

ky

kx

w

y

x

k

Homogeneous Coordinates

Cartesian Coordinates

E.G., we can uniformly scale the projective space, and it will still

produce the same image -> scale ambiguity

Page 51: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Slide Credit: Savarese

Camera (projection) matrix

XtRKx =x: Image Coordinates: (u,v,1)

K: Intrinsic Matrix (3x3)

R: Rotation (3x3)

t: Translation (3x1)

X: World Coordinates: (X,Y,Z,1)

Ow

iw

kw

jwR,t

X

x

Extrinsic Matrix

Page 52: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

X0IKx =

=

10100

000

000

1z

y

x

f

f

v

u

w

K

Slide Credit: Savarese

Projection matrix

Intrinsic Assumptions

• Unit aspect ratio

• Optical center at (0,0)

• No skew

Extrinsic Assumptions• No rotation

• Camera at (0,0,0)

X

x(0,0,0)

Page 53: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Projection: world coordinates→image coordinates

Camera

Center

(0, 0, 0)

=

Z

Y

X

P.

.

. f Z Y

=

V

Up

.V

U

Z

fXU *−=

Z

fYV *−=

p = distance from

image center

Image

center

(u0, v0)

Page 54: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Remove assumption: known optical center

X0IKx =

=

10100

00

00

1

0

0

z

y

x

vf

uf

v

u

w

Intrinsic Assumptions

• Unit aspect ratio

• No skew

Extrinsic Assumptions• No rotation

• Camera at (0,0,0)

James Hays

K

Page 55: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Remove assumption: equal aspect ratio

X0IKx =

=

10100

00

00

1

0

0

z

y

x

vf

uf

v

u

w y

x

Intrinsic Assumptions• No skew

Extrinsic Assumptions• No rotation

• Camera at (0,0,0)

James Hays

Page 56: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Remove assumption: non-skewed pixels

X0IKx =

=

10100

00

0

1

0

0

z

y

x

vf

usf

v

u

w y

x

Intrinsic Assumptions Extrinsic Assumptions• No rotation

• Camera at (0,0,0)

Note: different books use different notation for parameters James Hays

Page 57: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Oriented and Translated Camera

Ow

iw

kw

jw

t

R

X

x

James Hays

Page 58: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Allow camera translation

XtIKx =

=

1100

010

001

100

0

1

0

0

z

y

x

t

t

t

vf

usf

v

u

w

z

y

x

y

x

Intrinsic Assumptions Extrinsic Assumptions• No rotation

James Hays

Page 59: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

3D Rotation of Points

Rotation around the coordinate axes, counter-clockwise:

=

=

−=

100

0cossin

0sincos

)(

cos0sin

010

sin0cos

)(

cossin0

sincos0

001

)(

z

y

x

R

R

R

p

p’

γ

y

z

Slide Credit: Saverese

x

Page 60: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Allow camera rotation

XtRKx =

=

1100

0

1 333231

232221

131211

0

0

z

y

x

trrr

trrr

trrr

vf

usf

v

u

w

z

y

x

y

x

James Hays

Page 61: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Demo – Kyle Simek

• “Dissecting the Camera Matrix”

• Three-part blog series

• http://ksimek.github.io/2012/08/14/decompose/

• http://ksimek.github.io/2012/08/22/extrinsic/

• http://ksimek.github.io/2013/08/13/intrinsic/

• “Perspective toy”

• http://ksimek.github.io/perspective_camera_toy.html

Page 62: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Orthographic Projection

• Special case of perspective projection

– Distance from the COP to the image plane is infinite

– Also called “parallel projection”

– What’s the projection matrix?

Image World

Slide by Steve Seitz

=

11000

0010

0001

1z

y

x

v

u

w

Page 63: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Geometry for a simple stereo system

• First, assuming parallel optical axes, known camera

parameters (i.e., calibrated cameras):

Two cameras, simultaneous views

Page 64: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

• Assume parallel optical axes, known camera parameters

(i.e., calibrated cameras). What is expression for Z?

Similar triangles (pl, P, pr) and

(Ol, P, Or):

Geometry for a simple stereo system

Z

T

fZ

xxT rl =−

−+

lr xx

TfZ

−=

disparity

Page 65: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

• Given p in left image, where can corresponding

point p’ be?

Stereo correspondence constraints

Page 66: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Stereo correspondence constraints

Page 67: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Geometry of two views constrains where the

corresponding pixel for some image point in the first view

must occur in the second view.

• It must be on the line carved out by a plane

connecting the world point and optical centers.

Epipolar constraint

Page 68: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

• Epipolar Plane

Epipole

Epipolar Line

Baseline

Epipolar geometry

Epipole

http://www.ai.sri.com/~luong/research/Meta3DViewer/EpipolarGeo.html

Page 69: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

• Baseline: line joining the camera centers

• Epipole: point of intersection of baseline with image plane

• Epipolar plane: plane containing baseline and world point

• Epipolar line: intersection of epipolar plane with the image

plane

• All epipolar lines intersect at the epipole

• An epipolar plane intersects the left and right image planes

in epipolar lines

Epipolar geometry: terms

Why is the epipolar constraint useful?

Page 70: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Fundamental matrix

Let x be a point in left image, x’ in right image

Epipolar relation

• x maps to epipolar line l’

• x’ maps to epipolar line l

Epipolar mapping described by a 3x3 matrix F:

It follows that:

l’l

x x’

𝑙′ = 𝐹𝑥𝑙 = 𝐹𝑇𝑥′

𝑥′𝐹𝑥 = 0

Page 71: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Fundamental matrix

This matrix F is called

• the “Essential Matrix”

– when image intrinsic parameters are known

• the “Fundamental Matrix”

– more generally (uncalibrated case)

Can solve for F from point correspondences

• Each (x, x’) pair gives one linear equation in entries of F

• F has 9 entries, but really only 7 degrees of freedom.

• With 8 points it is simple to solve for F, but it is also possible with 7. See Marc

Pollefey’s notes for a nice tutorial

𝑥′𝐹𝑥 = 0

Page 72: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Stereo image rectification

Page 73: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Stereo image rectification

• Reproject image planes onto a common plane parallel to the line between camera centers

• Pixel motion is horizontal after this transformation

• Two homographies (3x3 transform), one for each input image reprojection

➢ C. Loop and Z. Zhang. Computing Rectifying Homographies for Stereo Vision. IEEE Conf. Computer Vision and Pattern Recognition, 1999.

Page 74: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Rectification example

Page 75: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Potential matches for x have to lie on the corresponding line l’.

Potential matches for x’ have to lie on the corresponding line l.

Summary: Key idea: Epipolar constraint

x x’

X

x’

X

x’

X

Page 76: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Big idea

As with high dynamic range imaging, we

are compensating for the shortcomings of

traditional cameras by capturing and

fusing multiple images.

Today we will assume that correspondence

between photos is known and we focus on

finding and applying homographies.

Page 77: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homographies and Panoramas

cs129: Computational Photography

James Hays, Brown, Fall 2012

Slides from Steve Seitz, Rick

Szeliski, Alexei Efros, Fredo

Durand, and Kristin Grauman

Page 78: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

Slide from Brown & Lowe

Page 79: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

• Human FOV = 200 x 135°

Slide from Brown & Lowe

Page 80: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Why Mosaic?

Are you getting the whole picture?

• Compact Camera FOV = 50 x 35°

• Human FOV = 200 x 135°

• Panoramic Mosaic = 360 x 180°

Slide from Brown & Lowe

Page 81: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Panoramic Photos are old

Sydney,1875

Beirut, late 1800’s

Page 82: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Panorama Capture

Page 83: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Mosaics: stitching images together

virtual wide-angle camera

Page 84: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

How to do it?

Basic Procedure

• Take a sequence of images from the same position

– Rotate the camera about its optical center

• Compute transformation between second image and first

• Transform the second image to overlap with the first

• Blend the two together to create a mosaic

• If there are more images, repeat

…but wait, why should this work at all?

• What about the 3D geometry of the scene?

• Why aren’t we using it?

Page 85: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Aligning images

Translations are not enough to align the images

left on top right on top

Page 86: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

A pencil of rays contains all views

real

camerasynthetic

camera

Can generate any synthetic camera view

if it has the same center of projection!

Page 87: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

mosaic PP

Image reprojection

The mosaic has a natural interpretation in 3D• The images are reprojected onto a common plane

• The mosaic is formed on this plane

• Mosaic is a synthetic wide-angle camera

Page 88: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image reprojection

Basic question• How to relate two images from the same camera center?

– how to map a pixel from PP1 to PP2

PP2

PP1

Answer• Cast a ray through each pixel in PP1

• Draw the pixel where that ray intersects PP2

But don’t we need to know the geometry

of the two planes with respect to the eye?

Observation:

Rather than thinking of this as a 3D reprojection,

think of it as a 2D image warp from one image to another

Page 89: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Back to Image Warping

Translation

2 unknowns

Affine

6 unknowns

Perspective

8 unknowns

Which t-form is the right one for warping PP1 into PP2?

e.g. translation, Euclidean, affine, projective

Page 90: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homography

A: Projective – mapping between any two PPs with the

same center of projection

• rectangle should map to arbitrary quadrilateral

• parallel lines aren’t maintained

• but must preserve straight lines

• Equal to: project, rotate, reproject

called Homography PP2

PP1

=

1

yx

*********

w

wy'wx'

H pp’

To apply a homography H

• Compute p’ = Hp (regular matrix multiply)

• Convert p’ from homogeneous to image

coordinates

Page 91: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image warping with homographies

image plane in front image plane below

black area

where no pixel

maps to

Page 92: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Image rectification

To unwarp (rectify) an image

• Find the homography H given a set of p and p’ pairs

• How many correspondences are needed?

• Tricky to write H analytically, but we can solve for it!

• Find such H that “best” transforms points p into p’

• Use least-squares!

pp’

Page 93: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homography

=

1

yx

*********

w

wy'wx'

H pp’

wyw

wxw

,

( )yx = ,

( )yx,

To apply a given homography H

• Compute p’ = Hp (regular matrix multiply)

• Convert p’ from homogeneous to image

coordinates

Page 94: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Homography

( )11, yx ( )11, yx

To compute the homography given pairs of corresponding

points in the images, we need to set up an equation where

the parameters of H are the unknowns…

( )22 , yx ( )22 , yx

( )nn yx , ( )nn yx ,

Page 95: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Least Squares Example

Say we have a set of data points (X1,X1’), (X2,X2’), (X3,X3’), etc.

(e.g. person’s height vs. weight)

We want a nice compact formula (a line) to predict X’s from Xs:

Xa + b = X’

We want to find a and b

How many (X,X’) pairs do we need?

What if the data is noisy?

'

22

'

11

XbaX

XbaX

=+

=+

=

'

2

'

1

2

1

1

1

X

X

b

a

X

XAx=B

=

.........

1

1

1

'

3

'

2

'

1

3

2

1

X

X

X

b

a

X

X

X

overconstrained

2min BAx −

Page 96: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Solving for homographies

Can set scale factor i=1. So, there are 8 unknowns.

Set up a system of linear equations:

Ah = b

where vector of unknowns h = [a,b,c,d,e,f,g,h]T

Need at least 8 eqs, but the more the better…

Solve for h. If overconstrained, solve using least-squares:

>> help lmdivide

=

1

y

x

ihg

fed

cba

w

wy'

wx'

p’ = Hp

2min bAh −

Page 97: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Example system for finding homography

Source: Paul Heckbert, Fundamentals of Texture Mapping and Image Warping

Page 98: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Mosaics: main steps• Collect correspondences (manually)

• Solve for homography matrix H

– Least squares solution

• Warp content from one image frame to the other to combine: say im1 into im2 reference frame

– Determine bounds of the new combined image

• Where will the corners of im1 fall in im2’s coordinate frame?

• We will attempt to lookup colors for any of these positions we can get from im1. : meshgrid

– Compute coordinates in im1’s reference frame (via homography) for all points in that range: H-1

– Lookup all colors for all these positions from im1

• Inverse warp : interp2 (watch for nans : isnan)

• Overlay im2 content onto the warped im1 content.

– Careful about new bounds of the output image: minx, miny

Page 99: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

im2im1

Page 100: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Mosaics: main steps• Collect correspondences (manually)

• Solve for homography matrix H

– Least squares solution

• Warp content from one image frame to the other to combine: say im1 into im2 reference frame

– Determine bounds of the new combined image

• Where will the corners of im1 fall in im2’s coordinate frame?

• We will attempt to lookup colors for any of these positions we can get from im1. : meshgrid

– Compute coordinates in im1’s reference frame (via homography) for all points in that range: H-1

– Lookup all colors for all these positions from im1

• Inverse warp : interp2 (watch for nans : isnan)

• Overlay im2 content onto the warped im1 content.

– Careful about new bounds of the output image: minx, miny

Page 101: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

im2im1

Page 102: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Mosaics: main steps• Collect correspondences (manually)

• Solve for homography matrix H

– Least squares solution

• Warp content from one image frame to the other to combine: say im1 into im2 reference frame

– Determine bounds of the new combined image

• Where will the corners of im1 fall in im2’s coordinate frame?

• We will attempt to lookup colors for any of these positions we can get from im1. : meshgrid

– Compute coordinates in im1’s reference frame (via homography) for all points in that range: H-1

– Lookup all colors for all these positions from im1

• Inverse warp : interp2 (watch for nans : isnan)

• Overlay im2 content onto the warped im1 content.

– Careful about new bounds of the output image: minx, miny

Page 103: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

im1 warped into reference frame of im2.im2

im1

Use interp2 to ask for the colors (possibly interpolated) from im1 at all the positions needed in im2’s reference frame.

Page 104: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Mosaics: main steps• Collect correspondences (manually)

• Solve for homography matrix H

– Least squares solution

• Warp content from one image frame to the other to combine: say im1 into im2 reference frame

– Determine bounds of the new combined image

• Where will the corners of im1 fall in im2’s coordinate frame?

• We will attempt to lookup colors for any of these positions we can get from im1. : meshgrid

– Compute coordinates in im1’s reference frame (via homography) for all points in that range: H-1

– Lookup all colors for all these positions from im1

• Inverse warp : interp2 (watch for nans : isnan)

• Overlay im2 content onto the warped im1 content.

– Careful about new bounds of the output image: minx, miny

Page 105: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James
Page 106: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Fun with homographies

St.Petersburg

photo by A. Tikhonov

Virtual camera rotations

Original image

Page 107: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Analyzing patterns and shapes

Automatically

rectified floor

The floor (enlarged)

What is the shape of the b/w floor pattern?

Slide from Criminisi

Page 108: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

From Martin Kemp The Science of Art

(manual reconstruction)

Au

tom

ati

c r

ecti

ficati

on

Analyzing patterns and shapes

2 patterns have been discovered !

Slide from Criminisi

Page 109: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Automatically rectified floor

St. Lucy Altarpiece, D. Veneziano

Analyzing patterns and shapes

What is the (complicated)

shape of the floor pattern?

Slide from Criminisi

Page 110: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

From Martin Kemp, The Science of Art

(manual reconstruction)

Automatic

rectification

Analyzing patterns and shapes

Slide from Criminisi

Page 111: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Analyzing patterns and shapes

The Ambassadors by Hans Holbein the Younger, 1533

Page 112: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Julian Beever: Manual Homographies

http://users.skynet.be/J.Beever/pave.htm

Page 113: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

changing camera center

Does it still work? synthetic PP

PP1

PP2

Page 114: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Planar scene (or far away)

PP3 is a projection plane of both centers of projection,

so we are OK!

This is how big aerial photographs are made

PP1

PP3

PP2

Page 115: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Planar mosaic

Page 116: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANSAC and projections

© Jeffrey Martin (jeffrey-martin.com)

most slides from Steve Seitz,

Rick Szeliski, and Alexei A. Efros; James Hays

Page 117: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Suppose we have estimated correspondences, but some are bad

What do we do about the “bad” matches?

Page 118: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANdom SAmple Consensus

Select one match, count inliers

Page 119: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANdom SAmple Consensus

Select one match, count inliers

Page 120: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Least squares fit

Find “average” translation vector

Page 121: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANSAC for estimating homography

RANSAC loop:

1. Select four feature pairs (at random)

2. Compute homography H (exact)

3. Compute inliers where SSD(pi’, H pi) < ε

4. Keep largest set of inliers

5. Re-compute least-squares H estimate on all of the

inliers

Page 122: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANSAC

The key idea is not that there are more inliers than outliers, but that the

outliers are wrong in different ways.

Page 123: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

RANSAC

Page 124: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

mosaic PP

Do we have to project onto a plane?

Page 125: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James
Page 126: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Full Panoramas

What if you want a 360 field of view?

mosaic Projection Cylinder

Page 127: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

• Map 3D point (X,Y,Z) onto cylinder

Cylindrical projection

X

Y

Z

unit cylinder

unwrapped cylinder

• Convert to cylindrical coordinates

cylindrical image

• Convert to cylindrical image coordinates

Page 128: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Cylindrical Projection

Y

X

Page 129: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Inverse Cylindrical projection

X

Y

Z

(X,Y,Z)

(sin,h,cos)

Page 130: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Cylindrical panoramas

Steps

• Reproject each image onto a cylinder

• Blend

• Output the resulting mosaic

Page 131: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Cylindrical image stitching

What if you don’t know the camera rotation?

• Solve for the camera rotations

– Note that a rotation of the camera is a translation of the cylinder!

Page 132: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Assembling the panorama

Stitch pairs together, blend, then crop

Page 133: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Problem: Drift

Vertical Error accumulation

• small (vertical) errors accumulate over time

• apply correction so that sum = 0 (for 360° pan.)

Horizontal Error accumulation

• can reuse first/last image to find the right panorama radius

Page 134: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Full-view (360°) panoramas

Page 135: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Spherical projection

unwrapped sphere

• Convert to spherical coordinates

spherical image

• Convert to spherical image coordinates

X

Y

Z),,(

1)ˆ,ˆ,ˆ(

222ZYX

ZYXzyx

++=

• Map 3D point (X,Y,Z) onto sphere

f

)ˆ,ˆ,ˆcoscossincos(sin zyx(= ) fff

Page 136: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Spherical Projection

Y

X

Page 137: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Inverse Spherical projection

X

Y

Z

(x,y,z)

(sinθcosφ,cosθcosφ,sinφ)

cos φ

φ

cos θ cos φ

sin φ

Page 138: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

3D rotation

Rotate image before placing on unrolled

sphere

(x,y,z)

(sinθcosφ,cosθcosφ,sinφ)

cos φ

φ

cos θ cos φ

sin φ

_ _

_ _

p = R p

Page 139: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Full-view Panorama

+

+

+

+

Page 140: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Distortion

Radial distortion of the image

• Caused by imperfect lenses

• Deviations are most noticeable for rays that pass through the

edge of the lens

No distortion Pin cushion Barrel

Page 141: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Radial distortion

Correct for “bending” in calibrated wide field of view lenses

Use this instead of normal projection

if we know radial distortion coefficients 𝜅1and 𝜅2

Page 142: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Polar Projection

Extreme “bending” in ultra-wide fields of view

Page 143: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Optimize over more parameters: Bundle Adjustment

New images initialised with rotation, focal length of best matching image

Page 144: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Optimize over more parameters: Bundle Adjustment

New images initialised with rotation, focal length of best matching image

Page 145: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Multi-band Blending

Burt & Adelson 1983

• Blend frequency bands over range l

Page 146: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Project 5: Bells and Whistles

Blending and Compositing

• use homographies to combine images or video and images together in an

interesting (fun) way. E.g.

– put fake graffiti on buildings or chalk drawings on the ground

– replace a road sign with your own poster

– project a movie onto a building wall

– etc.

Page 147: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Bells and Whistles

Capture creative/cool/bizzare panoramas

• Example from UW (by Brett Allen):

• Ever wondered what is happening inside your fridge while you are not looking?

Page 148: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Bells and Whistles

Video Panorama

• Capture two (or more) stationary videos (either from the same point, or of a

planar/far-away scene). Compute homography and produce a video mosaic. Need

to worry about synchronization (not too hard).

• e.g. capturing a football game from the sides of the stadium

Page 149: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

More panorama / homography examples

Eunjeong Ryu (E.J), 2004

Ben Hollis, 2004

Ben Hollis, 2004

Matt Pucevich , 2004

Page 150: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

WHAT CUES HELP US TO PERCEIVE DEPTH

(AND 3D SHAPE IN GENERAL)?

Think-Pair-Share

Page 151: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Shading

[Figure from Prados & Faugeras 2006]

Page 152: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Focus/defocus

[figs from H. Jin and P. Favaro, 2002]

Images from

same point of

view, different

camera

parameters

3d shape / depth

estimates

Page 153: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Texture

[From A.M. Loh. The recovery of 3-D structure using visual texture patterns. PhD thesis]

Page 154: Computational Photography and Image Manipulation CMPT 469 ...yagiz/cpim/2019-CPIM-10-Transformations.pdf · Week 10 Transforms and Panoramas 1. Slide credits •Slides thanks to James

Perspective effects

Image credit: S. Seitz