Image stitching
Digital Visual Effectsg Yung-Yu Chuang
with slides by Richard Szeliski, Steve Seitz, Matthew Brown and Vaclav Hlavac
Image stitching
• Stitching = alignment + blending geometrical photometric registration registration
Applications of image stitching
• Video stabilization
Vid i i
• Video summarization
• Video compression
• Video matting
• Panorama creation
• Panorama creation
Video summarization
Video compression Object removal
input video
Object removal
remove foreground
Object removal
estimate background
Object removal
background estimation
Panorama creation
Why panorama?
• Are you getting the whole picture?
C t C FOV 50 35°
– Compact Camera FOV = 50 x 35°
Why panorama?
• Are you getting the whole picture?
C t C FOV 50 35°
– Compact Camera FOV = 50 x 35°
– Human FOV = 200 x 135°
Why panorama?
• Are you getting the whole picture?
C t C FOV 50 35°
– Compact Camera FOV = 50 x 35°
– Human FOV = 200 x 135°
P i M i 360 180°
– Panoramic Mosaic = 360 x 180°
Panorama examples
• Like HDR, it is a topic of computational photography seeking ways to build a better photography, seeking ways to build a better camera mostly in software.
M t h d
• Most consumer cameras have a panorama mode
• Mars:
http://www.panoramas.dk/fullscreen3/f2_mars97.html
• Earth:
http://www.panoramas.dk/new-year-2006/taipei.html http://www.360cities.net/
http://www.360cities.net/
What can be globally aligned?
• In image stitching, we seek for a matrix to globally warp one image into another Are any globally warp one image into another. Are any two images of the same scene can be aligned this way?
this way?
– Images captured with the same center of j ti
projection
– A planar scene or far-away scene
A pencil of rays contains all views
real synthetic
camera y
camera
Can generate any synthetic camera viewg y y
as long as it has the same center of projection!
Mosaic as an image reprojection
mosaic projection plane
• The images are reprojected onto a common plane
• The mosaic is formed on this planeThe mosaic is formed on this plane
• Mosaic is a synthetic wide-angle camera
Changing camera center
• Does it still work? synthetic PP PP1
PP2
Planar scene (or a faraway one)
PP3 PP1
PP2
• PP3 is a projection plane of both centers of projection, so we are OK!
• This is how big aerial photographs are made
Motion models
• Parametric models as the assumptions on the relation between two images
relation between two images.
2D Motion models Motion models
Translation Affine Perspective 3D rotation
2 unknowns 6 unknowns 8 unknowns 3 unknowns
A case study: cylindrical panorama
• What if you want a 360 field of view?
mosaic projection cylinder
Cylindrical panoramas
• Steps
– Reproject each image onto a cylinder – Blend
– Output the resulting mosaic
Cylindrical panorama
1. Take pictures on a tripod (or handheld) 2 W li d i l di
2. Warp to cylindrical coordinate 3. Compute pairwise alignments 4. Fix up the end-to-end alignment 5 Blending
5. Blending
6. Crop the result and import into a viewer
It is required to do radial distortion correction for better stitching results!
correction for better stitching results!
Taking pictures
K id i t i d h d
Kaidan panoramic tripod head
Translation model
Try to align this in PaintShop Pro
Where should the synthetic camera be
real synthetic
camera y
camera
• The projection plan of some camera
• Onto a cylinder
• Onto a cylinder
Cylindrical projection
Adopted from http://www.cambridgeincolour.com/tutorials/image-projections.htm
Cylindrical projection
Cylindrical projection
Adopted from http://www.cambridgeincolour.com/tutorials/image-projections.htm
Cylindrical projection
y
unwrapped cylinder
x
y
θ
x f
θ
Cylindrical projection
y
unwrapped cylinder
x
y
z f
θ
f
x
Cylindrical projection
y
unwrapped cylinder
x
y
z f
s=f
gives less distortionf
distortionx
Cylindrical reprojection
top-down viewp Focal lengthFocal length – the dirty secret…– the dirty secret
f = 180 (pixels) f = 280 f = 380 Image 384x300
A simple method for estimating f
w
d f p
f
Or, you can use other software, such as AutoStich, to help.
to help.
Input images Cylindrical warping
Blending
• Why blending: parallax, lens distortion, scene motion exposure difference
motion, exposure difference
Blending
Blending Blending
Assembling the panorama
• Stitch pairs together blend then crop
• Stitch pairs together, blend, then crop
Problem: Drift
• Error accumulation
– small errors accumulate over time
Problem: Drift
(x1,y1)
(xn,yn)
• Solution • copy of first
• Solution
– add another copy of first image at the end – there are a bunch of ways to solve this problem
image
– 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”
End-to-end alignment and crop
Viewer: panorama
+ +
+ +
+ + +
+
+ +
example: http://www.cs.washington.edu/education/courses/cse590ss/01wi/projects/project1/students/dougz/index.html
Viewer: texture mapped model
example: http://www.panoramas.dk/
Cylindrical panorama
1. Take pictures on a tripod (or handheld) 2 W li d i l di
2. Warp to cylindrical coordinate 3. Compute pairwise alignments 4. Fix up the end-to-end alignment 5 Blending
5. Blending
6. Crop the result and import into a viewer
Determine pairwise alignment?
• Feature-based methods: only use feature points to estimate parameters
to estimate parameters
• We will study the “Recognising panorama”
paper published in ICCV 2003
• Run SIFT (or other feature algorithms) for each
• Run SIFT (or other feature algorithms) for each image, find feature matches.
Determine pairwise alignment
• p’=Mp, where M is a transformation matrix, p and p’ are feature matches
and p are feature matches
• It is possible to use more complicated models
h ffi ti
such as affine or perspective
• For example, assume M is a 2x2 matrix
y x m m
m m y
x
22 21
12 11
' '
• Find M with the least square error
n
2
y m21 m22 y
i
p Mp
1
' 2
Determine pairwise alignment
x' m11 m12 x x1m11 y1m12 x1'
y' m21 m22 y x1m21 y1m22 y1'
• Overdetermined system
0 0 '
' 1 1 11
1 1 1 1
0 0
0 0
y x m
y x y x
'
12 2 2
2 0 0 x
m m y
x
' 22
21
0
0 n
n
n m x
m y
x
0 0 xn yn yn'
Normal equation
Given an overdetermined system
b Ax
the normal equation is that which minimizes the sum of the square differences between left and sum of the square differences between left and right sides
b A Ax
A
T
TWhy?
Normal equation
2)
( x Ax b
E ( )
a
11a
1b
1
mb
x a
a
: :
:
...
11 1
11
: :
: :
1
m
b
x :
: :
a
n1... a
nmb
nnxm n equations m variables nxm, n equations, m variables
Normal equation
m a x
m a1jxj b1
j
j j j
j
j a x b
x b
a 1
1 1 1
1 1
: : :
m ij
j ij i
m
j
j
ijx b a x b
a
1 1
: b
Ax
m j
m j
b
1 1
: : :
n
m
j
j nj n
j
j
nj b a x b
x a
1 1
n m aijxj biE
2
)
2(
x
Ax b
i
i j
j
ijx b
a E
1 1
)
(
x Ax bNormal equation
n
m
b
E
2
)
2(
A b
i
i j
j
ijx b
a E
1 1
)
(
x Ax b
0
xE
2
i1n
i m
j
ij
x b a
a
x1
n m n1 1
i j
j
j
i
i i i
j j
ij
i
a x a b
a
1 1
1 1
1
2
2
) (
2
0 E A
TAx A
Tb
b A Ax
A
T
T→ ) (
2
0 A Ax A b
x
→ A Ax A b
Normal equation
Ax
b
2
Ax
b Ax b
T T T
xAxTAT bbT
AxAx bb
T T
b b b A x Ax b Ax A x
b Ax b
A x
T T
T T
T
T
A b x A b x b bAx A
xT T
T T
T T
T
b A Ax
AT
2
T2
E
xDetermine pairwise alignment
• p’=Mp, where M is a transformation matrix, p and p’ are feature matches
and p are feature matches
• For translation model, it is easier.
n
i
i i i
i x m y y
x m E
1
' 2 2
' 2 1
0 E
1
0 m
• What if the match is false? Avoid impact of outliers.
RANSAC
• RANSAC = Random Sample Consensus
A l i h f b fi i f d l i h
• An algorithm for robust fitting of models in the presence of many data outliers
• Compare to robust statistics
• Given N data points xi, assume that mjority of them are generated from a model with
them are generated from a model with parameters , try to recover .
RANSAC algorithm
Run k times:
(1) d l d l
How many times?
How big?
(1) draw n samples randomly
(2) fit parameters with these n samples
How big?
Smaller is better
(3) for each of other N-n points, calculate its distance to the fitted model count the its distance to the fitted model, count the number of inlier points, c
O t t ith th l t Output with the largest c
How to define?
Depends on the problem.
How to determine k
p: probability of real inliers
P: probability of success after k trials P: probability of success after k trials k
p
nP 1 ( 1 p ) P 1 ( 1 )
n samples are all inliers a failure
f il ft k t i l failure after k trials
) 1
l ( P
n p k) 1
log(
) 1 log(
p
nk P
3 0.5 356 0.6 97
for P=0.99
) 1
log( p
6 0.5 293
Example: line fitting
Example: line fitting
n=2 n=2
Model fitting
Measure distances Count inliers
c=3 c=3
Another trial
c=3 c=3
The best model
c=15 c=15
RANSAC for Homography RANSAC for Homography
RANSAC for Homography Applications of panorama in VFX
• Background plates I b d li h i
• Image-based lighting
Troy (image-based lighting)
http://www.cgnetworks.com/story custom.php?story id=2195&page=4 http://www.cgnetworks.com/story_custom.php?story_id 2195&page 4