image stitching and alignment - ucsbyfwang/courses/cs281b/notes/6-stitching.pdfso far, algorithms...

98
Image Stitching and Alignment

Upload: others

Post on 22-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Image Stitching and Alignment

Page 2: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Multiple Images

So far, algorithms deal with a single, static image

In the real world, a static pattern is a rarity, continuous

motion and change are the rule

Human eyes are well-equipped to take advantage of

motion or change in an image sequence

Stitching (Alignment) and Motion

Stitching has a “global” model – all pixel movement can be

explained by a simple mathematic model (far field, pure rotational,

pure translation)

2D motion field is a “local” model – pixels by themselves

(similarity in a local neighborhood only)

Page 3: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

General Taxonomy

Camera motion and the Scene is static

Driving, panorama

Near field (hard) vs. Far field (easy)

General camera motion (hard) vs. special camera motion (e.g.,

rotation only, easier)

General scene (hard) vs. special scene (planar, easier)

Object motion and the camera is stationary

Surveillance

Background modeling and subtraction

Both camera and object are moving

Sports video, driving, diving, etc.

Page 4: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Alignment

Homographies

Rotational Panoramas

RANSAC

Global alignment

Warping

Blending

Page 5: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motivation: Recognition

Page 6: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motivation: medical image

registration

Page 7: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motivation: Mosaics

Getting the whole picture

Consumer camera: 50˚ x 35˚

Page 8: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motivation: Mosaics

Getting the whole picture

Consumer camera: 50˚ x 35˚

Human Vision: 176˚ x 135˚

Page 9: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motivation: Mosaics

Getting the whole picture

Consumer camera: 50˚ x 35˚

Human Vision: 176˚ x 135˚

Panoramic Mosaic = up to 360 x 180°

Page 10: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Motion models

What happens when we take two images with a camera

and try to align them?

• translation?

• rotation?

• scale?

• affine?

• perspective?

Page 11: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Image Warping

image filtering: change range of image

g(x) = h(f(x))

image warping: change domain of image

g(x) = f(h(x))

f

x

h

f

x

f

x

hf

x

Page 12: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Image Warping

image filtering: change range of image

g(x) = h(f(x))

image warping: change domain of image

g(x) = f(h(x))

h

h

f

f g

g

Page 13: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Parametric (global) warping

Examples of parametric warps:

translation rotation aspect

affineperspective

cylindrical

Page 14: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Image Warping

Given a coordinate transform x’ = h(x) and a source image

f(x), how do we compute a transformed image g(x’) =

f(h(x))?

f(x) g(x’)x x’

h(x)

Page 15: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Forward Warping

Send each pixel f(x) to its corresponding location x’ = h(x)

in g(x’)

f(x) g(x’)x x’

h(x)

• What if pixel lands “between” two pixels?

Page 16: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Forward Warping

Send each pixel f(x) to its corresponding location x’ = h(x)

in g(x’)

f(x) g(x’)x x’

h(x)

• What if pixel lands “between” two pixels?

• Answer: add “contribution” to several pixels,

normalize later (splatting)

Page 17: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Inverse Warping

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

h(x) in f(x)

f(x) g(x’)x x’

h(x)

• What if pixel comes from “between” two pixels?

Page 18: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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…

Slide from Alyosha Efros, CMU

Page 19: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Bilinear interpolationSampling at f(x,y):

Slide from Alyosha Efros, CMU

Page 20: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Interpolation

Possible interpolation filters:

nearest neighbor

bilinear

bicubic (interpolating)

sinc / FIR

Needed to prevent “jaggies”

and “texture crawl”

Page 21: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

2D coordinate transformations

translation: x’ = x + t x = (x,y)

rotation: x’ = R x + t

similarity: x’ = s R x + t

affine: x’ = A x + t

perspective:x’ H x x = (x,y,1)

(x is a homogeneous coordinate)

These all form a nested group (closed w/ inv.)

Page 22: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Homogeneous Coordinates

consistent representation for all linear transform (including

translation)

can be concatenated & pre-computed

( , ) ( , , ),

( , , ) ( / , / )

x y wx wy w w

wx wy w wx w wy w

0

Page 23: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

x

y

T

T

x

y

x

y

x

y

x

y

S

S

x

y

x

y

x

y

'

'

'

'

cos sin

sin cos

'

'

1

1 0

0 1

0 0 1 1

1

0

0

0 0 1 1

1

0 0

0 0

0 0 1 1

x

y TRS

x

y

'

' ( )

1 1

Page 24: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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 25: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

2D Affine Transformations

Affine transformations are combinations of …

Linear transformations, and

Translations

Parallel lines remain parallel

w

yx

fedcba

w

yx

100

''

Page 26: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Projective Transformations

Projective transformations:

Affine transformations, and

Projective warps

Parallel lines do not necessarily remain parallel

w

yx

ihg

fedcba

w

yx

'

''

Page 27: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Fitting an affine transformation

Affine model approximates perspective projection of planar

objects.

Page 28: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Fitting an affine transformation

• Assuming we know the correspondences, how do we get

the transformation?

),( ii yx ),( ii yx

2

1

43

21

t

t

y

x

mm

mm

y

x

i

i

i

i

Page 29: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Fitting an affine transformation

• Assuming we know the correspondences, how do we get

the transformation?

),( ii yx ),( ii yx

2

1

43

21

t

t

y

x

mm

mm

y

x

i

i

i

i

i

i

ii

ii

y

x

t

t

m

m

m

m

yx

yx

2

1

4

3

2

1

1000

0100

Page 30: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Fitting an affine transformation

• How many matches (correspondence pairs) do we need to

solve for the transformation parameters?

• Once we have solved for the parameters, how do we

compute the coordinates of the corresponding point for

?

i

i

ii

ii

y

x

t

t

m

m

m

m

yx

yx

2

1

4

3

2

1

1000

0100

),( newnew yx

Page 31: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Panoramas

Obtain a wider angle view by combining multiple images.

ima

ge fro

m S

. Seitz

. . .

Page 32: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

How to stitch together a panorama?

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?

Source: Steve Seitz

Page 33: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Panoramas: generating synthetic views

real

camerasynthetic

camera

Can generate any synthetic camera view

as long as it has the same center of projection!

Page 34: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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 cameraSource: Steve Seitz

Page 35: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

mosaic PP

Image reprojection

The mosaic has a natural interpretation in 3D as a plane

This is true even if the real scene is not planar as long as you have the same focal point

Source: Steve Seitz

Page 36: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

In reality

The scene is not planar

But if you are shooting panorama against far-away objects (e.g.,

from the south rim of the Grand Canyon against the north rim), the

distance variation can be ignored

Panorama works best for far-field scene

The rotation is about the person holding the camera, not

the camera’s focal center

If the scene is far away, such small deviation does not matter

In fact, image stitching works well if you exercise some

caution

Why all phones these days have the panorama mode

Page 37: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Homography How to relate two images from the same camera center?

how to map a pixel from PP1 to PP2?

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

A projective transform is a mapping between any two PPs with

the same center of projection

rectangle should map to arbitrary quadrilateral

parallel lines aren’t

but must preserve straight lines

called Homography

PP2

PP1

1

yx

*********

w

wy'wx'

H pp’

Page 38: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Homography

1

yx

*********

w

wy'wx'

H pp’

w

yww

xw,

yx ,

yx,

To apply a given homography H

• Compute p’ = Hp (regular matrix multiply)

• Convert p’ from homogeneous to image

coordinates

Page 39: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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 40: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Number of measurements required

At least as many independent equations as degrees

of freedom required

Example:

Hxx'

11

λ

333231

232221

131211

y

x

hhh

hhh

hhh

y

x

2 independent equations / point

8 degrees of freedom

4x2≥8

Page 41: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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:

Work well if i is not close to 0 (not recommended!)

1

y

x

ihg

fed

cba

w

wy'

wx'

p’ = Hp

2min bAh

Page 42: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Direct Linear Transformation

(DLT)

ii Hxx 0Hxx ii

i

i

i

i

xh

xh

xh

Hx3

2

1

T

T

T

iiii

iiii

iiii

ii

yx

xw

wy

xhxh

xhxh

xhxh

Hxx12

31

23

TT

TT

TT

0

h

h

h

0xx

x0x

xx0

3

2

1

TTT

TTT

TTT

iiii

iiii

iiii

xy

xw

yw

Tiiii wyx ,,x

0hA i

𝐻 =ℎ1𝑇

ℎ2𝑇

ℎ3𝑇

Page 43: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Direct Linear Transformation

(DLT)

Equations are linear in h

0

h

h

h

0xx

x0x

xx0

3

2

1

TTT

TTT

TTT

iiii

iiii

iiii

xy

xw

yw

0AAA 321 iiiiii wyx

0hA i

• Only 2 out of 3 are linearly independent

(indeed, 2 eq/pt)

0

h

h

h

x0x

xx0

3

2

1

TTT

TTT

iiii

iiii

xw

yw

(only drop third row if wi’≠0)

• Holds for any homogeneous

representation, e.g. (xi’,yi’,1)

Page 44: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Direct Linear Transformation

(DLT)

Solving for H

0Ah 0h

A

A

A

A

4

3

2

1

size A is 8x9 or 12x9, but rank 8

Trivial solution is h=09T is not interesting

1-D null-space yields solution of interest

pick for example the one with 1h

Page 45: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Direct Linear Transformation

(DLT)

Over-determined solution

No exact solution because of inexact measurement

i.e. “noise”

0Ah 0h

A

A

A

n

2

1

Find approximate solution

- Additional constraint needed to avoid 0, e.g.

- not possible, so minimize

1h

Ah0Ah

Page 46: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

DLT algorithm

Objective

Given n≥4 2D to 2D point correspondences {xi↔xi’},

determine the 2D homography matrix H such that xi’=Hxi

Algorithm

(i) For each correspondence xi ↔xi’ compute Ai. Usually

only two first rows needed.

(ii) Assemble n 2x9 matrices Ai into a single 2nx9 matrix A

(iii) Obtain SVD of A. Solution for h is last column of V

(iv) Determine H from h

Page 47: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

changing camera center Does it still work?

Not for near fieldsynthetic PP

PP1

PP2

True pointFalse point 1

False point 2

Page 48: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

changing camera center Does it still work?

For far field oksynthetic PP

PP1

PP2

True pointFalse point 1

False point 2

Page 49: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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

Source: Alyosha Efros

Page 50: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Grauman

Page 51: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,
Page 52: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Outliers

Outliers can hurt the quality of our parameter

estimates, e.g.,

an erroneous pair of matching points from two images

an edge point that is noise, or doesn’t belong to the line we

are fitting.

Grauman

Page 53: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Example: least squares line fitting

Assuming all the points that belong to a particular line are

known

Grauman

Page 54: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Outliers affect least squares fit

Page 55: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Outliers affect least squares fit

Page 56: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC

RANdom Sample Consensus

Approach: we want to avoid the impact of outliers, so

let’s look for “inliers”, and use those only.

Intuition: if an outlier is chosen to compute the

current fit, then the resulting line won’t have much

support from rest of the points.

Page 57: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC

RANSAC loop:

1. Randomly select a seed group of points on which to base

transformation estimate (e.g., a group of matches)

2. Compute transformation from seed group

3. Find inliers to this transformation

4. If the number of inliers is sufficiently large, re-compute

least-squares estimate of transformation on all of the inliers

Keep the transformation with the largest number of inliers

Page 58: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Task:

Estimate best line

Slide credit: Jinxiang Chai, CMU

Page 59: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Sample two points

Page 60: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Fit Line

Page 61: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Total number of points within

a threshold of line.

Page 62: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Repeat, until get a good result

Page 63: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Repeat, until get a good result

Page 64: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC Line Fitting Example

Repeat, until get a good result

Page 65: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

How Many Trials?Well, theoretically it is C(n,p) to find all possible p-tuples

Very expensive

tries inset good oneleast at got :))1(1(1

tries all indata badgot :))1(1(

bad is sample oneleast at :)1(-1

good are samples all:)1(

data good of fraction:)1(

data bad of fraction:

))1(1(1

mp

m

p

mp

mp

p

p

mp

Page 66: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

How Many Trials (cont.)

Make sure the probability is high (e.g. >95%)

given p and epsilon, calculate m

p 5% 10

%

20

%

25

%

30

%

40

%

50

%

1 1 2 2 3 3 4 5

2 2 2 3 4 5 7 11

3 2 3 5 6 8 13 23

4 2 3 6 8 11 22 47

5 3 4 8 12 17 38 95

Page 67: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Best Practice

Randomized selection

can completely

remove outliers

“plutocratic”

Results are based on a

small set of features

LS is most fair,

everyone get an equal

say

“democratic”

But can be seriously

influenced by bad data

Use randomized algorithm to remove outliers

Use LS for final “polishing” of results (using all

“good” data)

Allow up to 50% outliers theoretically

Page 68: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC example: Translation

Putative matches

Source: Rick Szeliski

Page 69: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC example: Translation

Select one match, count inliers

Page 70: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC example: Translation

Select one match, count inliers

Page 71: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

RANSAC example: Translation

Find “average” translation vector

Page 72: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

Source: L. Lazebnik

Page 73: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

• Extract features

Source: L. Lazebnik

Page 74: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

• Extract features

• Compute putative matches

Source: L. Lazebnik

Page 75: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

• Extract features

• Compute putative matches

• Loop:

Hypothesize transformation T (small group of putative matches

that are related by T)

Source: L. Lazebnik

Page 76: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

• Extract features

• Compute putative matches

• Loop:

Hypothesize transformation T (small group of putative matches

that are related by T)

Verify transformation (search for other matches consistent with T)

Source: L. Lazebnik

Page 77: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Feature-based alignment outline

• Extract features

• Compute putative matches

• Loop:

Hypothesize transformation T (small group of putative matches

that are related by T)

Verify transformation (search for other matches consistent with T)

Source: L. Lazebnik

Page 78: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Panoramas

What if you want a 360 field of view?

mosaic Projection Cylinder

Szeliski

Page 79: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Cylindrical panoramas

Steps

Project each image onto a cylinder (warp)

Estimate motion (a pure translation now)

Blend

Optional: project it back (unwarp)

Output the resulting mosaic

Page 80: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

f = 180 (pixels)

Cylindrical Panoramas

Map image to cylindrical or spherical coordinates

need known focal length

Work only if a single tilt (e.g., camera on tripod)

Image 384x300 f = 380f = 280

Page 81: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Determining the focal length

1. Initialize from homography H

(see text or [SzSh’97])

2. Use camera’s EXIF tags (approx.)

3. Use a tape measure

4. Try and error

1m4m

Page 82: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Practical Methods for F

Use program jhead

(http://www.sentex.net/~mwandel/jhead/)

Mac, Windows, and Linux

Sample outputs

Page 83: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Calculating F

With image resolution (width x height), CCD width and f

f*(width/CCD width) or 5.4*(1600/5.23) = 1652 (pixels)

With equivalent f (35mm film is 36mmx24mm)

(equivalent f)*(width/36) or 36*(1600/36) = 1600 (pixels)

If you don’t have the above (more often than not), guess!

No zoom f ~ (picture width in pixels)

2x zoom f ~ 2 * (picture width in pixels)

Page 84: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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

– s defines size of the final image

Page 85: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Cylindrical warping

Given focal length f and

image center (xc,yc)

X

Y

Z

(X,Y,Z)

(sin,h,cos)

Page 86: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Spherical warping

Given focal length f and

image center (xc,yc)

X

Y

Z

(x,y,z)

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

cos φ

φ

cos θ cos φ

sin φ

Page 87: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

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 88: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Radial distortion

Correct for “bending” in wide field of view lenses

Page 89: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Fisheye lens

Extreme “bending” in ultra-wide fields of view

Page 90: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Image Stitching

1. Align the images over each other

camera pan ↔ translation on cylinder

2. Blend the images together

Page 91: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Assembling the panorama

Stitch pairs together, blend, then crop

Page 92: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Problem: Drift

Error accumulation

small (vertical) errors accumulate over time

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

Page 93: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Problem: Drift

Solution

add another copy of first image at the end

this gives a constraint: yn = y1

there are a bunch of ways to solve this problem

add displacement of (y1 – yn)/(n -1) to each image after the first

compute a global warp: y’ = y + ax

run a big optimization problem, incorporating this constraint

best solution, but more complicated

known as “bundle adjustment”

(x1,y1)

copy of first

image

(xn,yn)

Page 94: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Full-view (360° spherical)

panoramas

Page 95: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Full-view Panorama

+

+

+

+

Page 96: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Texture Mapped Model

Page 97: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Global alignment

• Register all pairwise overlapping images

• Use a 3D rotation model (one R per image)

• Use direct alignment (patch centers) or feature based

• Infer overlaps based on previous matches (incremental)

• Optionally discover which images overlap other images

using feature selection (RANSAC)

Page 98: Image Stitching and Alignment - UCSByfwang/courses/cs281b/notes/6-stitching.pdfSo far, algorithms deal with a single, static image In the real world, a static pattern is a rarity,

Bundle adjustment formulations

All pairs optimization:

Full bundle adjustment, using 3-D point positions

Bundle adjustment using 3-D ray:

All-pairs 3-D ray formulation:

Projected point 3-D ray from point

Map 2D point i in image j to 2D point in image k

Map 3D point i in to 2D point in image i

3-D ray from point i

3-D ray from points i and j

Confidence / uncertainty of point i in image j