Image Stitching: Computer Vision Jia-Bin Huang, Virginia Tech
Image Stitching: Computer Vision Jia-Bin Huang, Virginia Tech
Image Stitching: Computer Vision Jia-Bin Huang, Virginia Tech
Add example
Computer Vision
Jia-Bin Huang, Virginia Tech
Many slides from S. Seitz and D. Hoiem
Administrative stuffs
• Getting help?
• Piazza
• Jia-Bin’s office hour: 3:30 – 4:30 PM Monday (440
Whittemore Hall)
• Accommodation
• Send me an email
Review: Camera Projection Matrix R
jw
t
kw
Ow
iw
X
u f s u0 r11 r12 r13 tx
x K R t X
Y
w v 0 f v0 r21 r22 r23 ty
Z
1 0 0 1 r31 r32 r33 t z
1
3
Review: Camera Calibration
Method 1: Use an object (calibration grid) with
known geometry
• Correspond image points to 3d points
• Get least squares solution (or non-linear solution)
Known 2d image Known 3d
coordinates locations
X
wu m11 m12 m13 m14 Y
wv m m22 m23 m24
21 Z
w m31 m32 m33 m34
1
𝑿
𝒊 = 𝑹 −𝟏
𝑲 −𝟏
𝒑𝒊
𝑲= 0
0
[ 1
𝑓
0
𝑣0
1
𝑢0
]
[ ]
0 −
𝒑⊤
𝒊
( 𝑲 −𝟏 )⊤ ( 𝑹 −𝟏 )⊤ (𝑹¿¿ − 𝟏)(𝑲 ¿ ¿− 𝟏) 𝒑 𝒋=𝟎 ¿ ¿ 𝑓 𝑓
𝑲 − 1= 1 𝑣
0 − 0
𝑓 𝑓
Constraints for , 0 0 1
=0
… Eqn (1)
=0
… Eqn (2)
=0
… Eqn (3)
Special properties of R
• inv(R)=RT
• Each row and column of
R has unit length
Slide by Steve Seitz
Measuring height vz
r
vanishing line (horizon)
t0 t
vx v vy
H R H
b0
b
t b vZ r H
r b vZ t R
image cross ratio
8
This class: Image Stitching
• Combine two or more overlapping images to make
one larger image
Add example
Camera Center
Problem set-up
.X
• x = K [R t] X x
• x' = K' [R' t'] X
• t=t'=0 x'
f f'
• Definition
• General mathematics:
homography = projective linear transformation
• Vision (most common usage):
homography = linear transformation between two
image planes
• Examples
• Project 3D surface into frontal view
• Relate two views that differ only by rotation
Homography example:
Image rectification
p’
p
Freedom HP Commercial
Image Stitching Algorithm Overview
4. Combine images
Computing homography
Assume we have four matched points: How do we
compute homography H?
w' u'
h1 h2 h3
H h4 h6
x ' Hx x ' w' v '
h5
w' h7 h8 h9
h1
h
2
h3
u v 1 0 0 0 uu vu u
h4
0 h0 h h5
0 0 u v 1 uv vv v
h6
h7
h8
h
9
Computing homography
h1 Matlab
h h1 h2 h3
h H h4 h5 h6
2 [U, S, V] = svd(A);
h = V(:, end);
h7 h8 h9
h9
Explanations of SVD and solving homogeneous linear systems
Computing homography
Normalized DLT
1. Normalize coordinates for each image
a) Translate for zero mean
~
b) Scale so that average
x Tx ~ to origin is ~sqrt(2)
distance
x Tx
– This makes problem better behaved numerically
~107-108)
H
(see HZ p.
1 ~
2. Compute using DLT
H T normalized
in HT coordinates
3. Unnormalize: x i Hx i
Computing homography
• Assume we have matched points with outliers: How do
we compute homography H?
HZ Tutorial ‘99
Computing homography
• Assume we have matched points with outliers: How do we
compute homography H?
HZ Tutorial ‘99
Automatic Image Stitching
x
x
f f
Planar
Planar
Cylindrical Mapping
x
x
f
f
Cylindrical
Recognizing Panoramas
Some of following material from Brown and Lowe 2003 talk Brown and Lowe 2003, 2007
Recognizing Panoramas
Input: N images
1. Extract SIFT points, descriptors from all images
2. Find K-nearest neighbors for each point (K=4)
3. For each image
a) Select M candidate matching images by counting
matched keypoints (m=6)
b) Solve homography Hij for each matched image
Recognizing Panoramas
Input: N images
1. Extract SIFT points, descriptors from all images
2. Find K-nearest neighbors for each point (K=4)
3. For each image
a) Select M candidate matching images by counting
matched keypoints (m=6)
b) Solve homography Hij for each matched image
c) Decide if match is valid (ni > 8 + 0.3 nf )
# keypoints in
# inliers
overlapping area
Recognizing Panoramas (cont.)
• Choosing seams
• Blending
Choosing seams
• Easy method
• Assign each pixel to image with nearest center
im1 im2
x x
Image 2
Image 1
Choosing seams
• Easy method
• Assign each pixel to image with nearest center
• Create a mask:
• mask(y, x) = 1 iff pixel should come from im1
• Smooth boundaries (called “feathering”):
• mask_sm = imfilter(mask, gausfil);
• Composite
• imblend = im1_c.*mask + im2_c.*(1-mask);
im1 im2
x x
Image 2
Image 1
Choosing seams
• Better method: dynamic program to find seam
along well-matched regions
Illustration: http://en.wikipedia.org/wiki/File:Rochester_NY.jpg
Gain compensation
• Simple gain adjustment
• Compute average RGB intensity of each image in overlapping
region
• Normalize intensities by ratio of averages
Multi-band Blending
0
1
1. Compute Laplacian
pyramid of images and
mask
3. Reconstruct complete
image
Blending comparison (IJCV
2007)
Blending Comparison
Further reading
• Alignment
• Initially, perform cross-correlation of small patches aided by
accelerometer to find good regions for matching
• Register by matching points (KLT tracking or RANSAC with FAST (similar
to SIFT) points) or correlational matching
• Blending
• Linear (or similar) blending, using a face detector to avoid blurring face
regions and choose good face shots (not blinking, etc)
http://www.patentlyapple.com/patently-apple/2012/11/apples-cool-iphone-5-panorama-app-revealed-in-5-patents.html
Things to remember
• Homography relates rotating cameras