cs6670: computer vision - cornell · pdf filecs6670: computer vision noah snavely. ......

59
Lecture 6: Image Warping and Projection CS6670: Computer Vision Noah Snavely

Upload: doanthu

Post on 14-Mar-2018

235 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Lecture 6: Image Warping and Projection

CS6670: Computer VisionNoah Snavely

Page 2: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Readings

• Szeliski Chapter 3.5 (image warping), 9.1 (motion models)

Page 3: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Announcements

• Project 1 assigned, due next Friday 2/18

Page 4: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Point of observation

Figures © Stephen E. Palmer, 2002

Dimensionality Reduction Machine (3D to 2D)

3D world 2D image

What have we lost?• Angles

• Distances (lengths)Slide by A. Efros

Page 5: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projection properties

• Many-to-one: any points along same ray map to same point in image

• Points → points

• Lines → lines (collinearity is preserved)

– But line through focal point projects to a point

• Planes → planes (or half-planes)

– But plane through focal point projects to line

Page 6: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projection properties

• Parallel lines converge at a vanishing point

– Each direction in space has its own vanishing point

– But parallels parallel to the image plane remain parallel

Page 7: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

2D to 2D warps

• Let’s start with simpler warps that map images to other images

• Examples of 2D 2D warps:

translation rotation aspect

Page 8: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Parametric (global) warping

• Transformation T is a coordinate-changing machine:

p’ = T(p)

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

– can be described by just a few numbers (parameters)

• Let’s consider linear xforms (can be represented by a 2D matrix):

T

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

Page 9: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Common linear transformations

• Uniform scaling by s:

(0,0) (0,0)

What is the inverse?

Page 10: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Common linear transformations

• Rotation by angle θ (about the origin)

(0,0) (0,0)

What is the inverse?

For rotations:

θ

Page 11: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

2x2 Matrices

• What types of transformations can be represented with a 2x2 matrix?

2D mirror about Y axis?

2D mirror across line y = x?

Page 12: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

• What types of transformations can be represented with a 2x2 matrix?

2D Translation?

Translation is not a linear operation on 2D coordinates

NO!

2x2 Matrices

Page 13: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Homogeneous coordinates

Trick: add one more coordinate:

homogeneous image coordinates

Converting from homogeneous coordinates

x

y

w

(x, y, w)

w = 1(x/w, y/w, 1)

homogeneous plane

Page 14: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Translation

• Solution: homogeneous coordinates to the rescue

Page 15: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Affine transformations

any transformation with last row [ 0 0 1 ] we call an affine transformation

Page 16: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Basic affine transformations

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

2D in-plane rotation Shear

1100

00

00

1

'

'

y

x

s

s

y

x

y

x

Scale

Page 17: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Modeling projection

• Projection equations– Compute intersection with PP of ray from (x,y,z) to COP

– Derived using similar triangles (on board)

• We get the projection by throwing out the last coordinate:

Page 18: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Modeling projection• Is this a linear transformation?

Homogeneous coordinates to the rescue!

homogeneous image coordinates

homogeneous scene coordinates

Converting from homogeneous coordinates

• no—division by z is nonlinear

Page 19: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective Projection

Projection is a matrix multiply using homogeneous coordinates:

divide by third coordinate

This is known as perspective projection• The matrix is the projection matrix

• (Can also represent as a 4x4 matrix – OpenGL does something like this)

Page 20: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective Projection

• How does scaling the projection matrix change the transformation?

Page 21: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Orthographic projection

• Special case of perspective projection

– Distance from the COP to the PP is infinite

– Good approximation for telephoto optics

– Also called “parallel projection”: (x, y, z) → (x, y)

– What’s the projection matrix?

Image World

Page 22: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Orthographic projection

Page 23: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective projection

Page 24: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective distortion

• What does a sphere project to?

Image source: F. Durand

Page 25: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective distortion

• The exterior columns appear bigger

• The distortion is not due to lens flaws

• Problem pointed out by Da Vinci

Slide by F. Durand

Page 26: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective distortion: People

Page 27: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

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 28: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Correcting radial distortion

from Helmut Dersch

Page 29: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Distortion

Page 30: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Modeling distortion

• To model lens distortion– Use above projection operation instead of standard

projection matrix multiplication

Apply radial distortion

Apply focal length translate image center

Project to “normalized”

image coordinates

Page 31: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Other types of projection

• Lots of intriguing variants…

• (I’ll just mention a few fun ones)

Page 32: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

360 degree field of view…

• Basic approach– Take a photo of a parabolic mirror with an orthographic lens (Nayar)– Or buy one a lens from a variety of omnicam manufacturers…

• See http://www.cis.upenn.edu/~kostas/omni.html

Page 34: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Camera parameters

• How can we model the geometry of a camera?

“The World”

Camera

x

y

z

v

w

u

o

COP

Two important coordinate systems:1. World coordinate system2. Camera coordinate system

Page 35: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Camera parameters

• To project a point (x,y,z) in world coordinates into a camera

• First transform (x,y,z) into camera coordinates

• Need to know

– Camera position (in world coordinates)

– Camera orientation (in world coordinates)

• The project into the image plane

– Need to know camera intrinsics

Page 36: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projection equation

• The projection matrix models the cumulative effect of all parameters

• Useful to decompose into a series of operations

ΠXx

1****

****

****

Z

Y

X

s

sy

sx

11

0100

0010

0001

100

'0

'0

31

1333

31

1333

x

xx

x

xxcy

cx

yfs

xfs

00

0 TIRΠ

projectionintrinsics rotation translation

identity matrix

Camera parametersA camera is described by several parameters

• Translation T of the optical center from the origin of world coords

• Rotation R of the image plane

• focal length f, principle point (x’c, y’c), pixel size (sx, sy)

• blue parameters are called “extrinsics,” red are “intrinsics”

• The definitions of these parameters are not completely standardized

– especially intrinsics—varies from one book to another

Page 37: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Extrinsics

• How do we get the camera to “canonical form”?

– (Center of projection at the origin, x-axis points right, y-axis points up, z-axis points backwards)

0

Step 1: Translate by -c

Page 38: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Extrinsics

• How do we get the camera to “canonical form”?

– (Center of projection at the origin, x-axis points right, y-axis points up, z-axis points backwards)

0

Step 1: Translate by -c

How do we represent translation as a matrix multiplication?

Page 39: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Extrinsics

• How do we get the camera to “canonical form”?

– (Center of projection at the origin, x-axis points right, y-axis points up, z-axis points backwards)

0

Step 1: Translate by -cStep 2: Rotate by R

3x3 rotation matrix

Page 40: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Extrinsics

• How do we get the camera to “canonical form”?

– (Center of projection at the origin, x-axis points right, y-axis points up, z-axis points backwards)

0

Step 1: Translate by -cStep 2: Rotate by R

Page 41: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Perspective projection

(intrinsics)

in general,

: aspect ratio (1 unless pixels are not square)

: skew (0 unless pixels are shaped like rhombi/parallelograms)

: principal point ((0,0) unless optical axis doesn’t intersect projection plane at origin)

(upper triangular matrix)

(converts from 3D rays in camera coordinate system to pixel coordinates)

Page 42: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Focal length

• Can think of as “zoom”

• Also related to field of view

24mm 50mm

200mm 800mm

Page 43: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projection matrix

(t in book’s notation)

translationrotationprojection

intrinsics

Page 44: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projection matrix

0

=

(in homogeneous image coordinates)

Page 45: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Questions?

• 3-minute break

Page 46: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Image alignment

Full screen panoramas (cubic): http://www.panoramas.dk/

Mars: http://www.panoramas.dk/fullscreen3/f2_mars97.html

2003 New Years Eve: http://www.panoramas.dk/fullscreen3/f1.html

Page 47: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Why Mosaic?

• Are you getting the whole picture?

– Compact Camera FOV = 50 x 35°

Slide from Brown & Lowe

Page 48: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Why Mosaic?

• Are you getting the whole picture?

– Compact Camera FOV = 50 x 35°

– Human FOV = 200 x 135°

Slide from Brown & Lowe

Page 49: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

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 50: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Mosaics: stitching images together

Page 51: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Readings

• Szeliski:

– Chapter 3.5: Image warping

– Chapter 5.1: Feature-based alignment

– Chapter 8.1: Motion models

Page 52: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Image alignment

Image taken from same viewpoint, just rotated.

Can we line them up?

Page 53: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Image alignment

Why don’t these image line up exactly?

Page 54: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

What is the geometric relationship between these two images?

?

Page 55: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

What is the geometric relationship between these two images?

?

Page 56: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Is this an affine transformation?

Page 57: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Where do we go from here?

affine transformation

what happens when we mess with this row?

Page 58: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Projective Transformations aka Homographies aka Planar Perspective Maps

Called a homography(or planar perspective map)

Page 59: CS6670: Computer Vision - Cornell · PDF fileCS6670: Computer Vision Noah Snavely. ... Translation is not a linear operation on 2D coordinates NO! ... – Take a photo of a parabolic

Homographies

• Example on board