Lecture 05
Lecture 05
Image alignment
Alignment applications
• A look into the past
Source: S. Lazebnik
Alignment applications
Panorama stitching
Source: S. Lazebnik
Alignment applications
Recognition
of object
instances
Source: S. Lazebnik
Alignment
Difficulties
• Noise (typically 1-3 pixels)
• Outliers (often 30-50%)
• Many-to-one matches or multiple objects
Source: S. Lazebnik
Alignment challenges
Occlusion,
clutter
Source: S. Lazebnik
Feature-based alignment
• Search sets of feature matches that agree in terms of:
a) Local appearance
b) Geometric configuration
?
Source: S. Lazebnik
• Robust alignment
• Descriptor-based feature matching
• RANSAC
Source: S. Lazebnik
Alignment as fitting
• Previous lectures: fitting a model to features in one image
M
Find model M that minimizes
xi
∑ residual( x , M )
i
i
Source: S. Lazebnik
Alignment as fitting
• Previous lectures: fitting a model to features in one image
M
Find model M that minimizes
xi
∑ residual( x , M )
i
i
xi
x'i Find transformation T
T that minimizes
∑ residual(T ( x ), xʹ)
i
i i
Source: S. Lazebnik
2D transformation models
• Similarity
(translation,
scale, rotation)
• Affine
• Projective
(homography)
Source: S. Lazebnik
( xi , yi )
( xiʹ, yiʹ)
xʹi = Mx i + t
⎡ xiʹ ⎤ ⎡ m1 m2 ⎤ ⎡ xi ⎤ ⎡ t1 ⎤
⎢ yʹ ⎥ = ⎢m ⎥ ⎢ ⎥ +⎢ ⎥ Want to find M, t to minimize
⎣ i⎦ ⎣ 3 m4 ⎦ ⎣ yi ⎦ ⎣t2 ⎦ n
2
∑ || xi − Mxi − t ||
i =1
ʹ
Source: S. Lazebnik
( xi , yi )
( xiʹ, yiʹ)
⎡ m1 ⎤
⎢ ⎥
⎡ ! ⎤ ⎢m2 ⎥ ⎡!⎤
⎢x 1 0⎥⎥ ⎢ m3 ⎥ ⎢⎢ xiʹ ⎥⎥
⎡ xiʹ ⎤ ⎡ m1 m2 ⎤ ⎡ xi ⎤ ⎡ t1 ⎤ ⎢ i yi 0 0
⎢ yʹ ⎥ = ⎢m ⎥ ⎢ ⎥ +⎢ ⎥ ⎢ ⎥=
⎣ i⎦ ⎣ 3 m4 ⎦ ⎣ yi ⎦ ⎣t2 ⎦ ⎢0 0 xi yi 0 1⎥ ⎢m4 ⎥ ⎢ yiʹ ⎥
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎣ ! ⎦ t1 ⎣!⎦
⎢ ⎥
⎢⎣ t 2 ⎥⎦
Source: S. Lazebnik
Homography
• The transformation between two views of a planar
surface
Fitting a homography
• Recall: homogeneous coordinates
Fitting a homography
• Recall: homogeneous coordinates
Fitting a homography
• Equation for homography:
⎡ xiʹ ⎤ ⎡ h11 h12 h13 ⎤ ⎡ xi ⎤ λ xʹi = H xi
λ ⎢⎢ yiʹ ⎥⎥ = ⎢⎢h21 h22 h23 ⎥⎥ ⎢⎢ yi ⎥⎥
⎢⎣ 1 ⎥⎦ ⎢⎣h31 h32 h33 ⎥⎦ ⎢⎣ 1 ⎥⎦
xʹi × H xi = 0
T T T
x
⎡ i⎤ ʹ ⎡h x
1 i
⎤ ⎡ y ʹ h
i 3 i x − h 2 xi
⎤
⎢ yʹ ⎥ × ⎢hT x ⎥ = ⎢ hT x − xʹ hT x ⎥
⎢ i⎥ ⎢ 2 i⎥ ⎢ 1 i i 3 i ⎥
⎢⎣ 1 ⎥⎦ ⎢⎣hT3 xi ⎥⎦ ⎢⎣ xiʹ hT2 xi − yiʹ h1T xi ⎥⎦
⎢ xT T
0 − xn x n ⎦
ʹ T⎥
⎣ n
• H has 8 degrees of freedom (9 parameters, but scale is
arbitrary)
• One match gives us two linearly independent equations
• Homogeneous least squares: find h minimizing ||Ah||2
• Eigenvector of ATA corresponding to smallest eigenvalue
• Four matches needed for a minimal solution
• For more info, see Sec. 4.1 in (Hartley & Zisserman)
Source: S. Lazebnik
( xi , yi )
( xiʹ, yiʹ)
Source: S. Lazebnik
?
Source: S. Lazebnik
• Extract features
Source: S. Lazebnik
• Extract features
• Compute putative matches
Source: S. Lazebnik
• Extract features
• Compute putative matches
• Loop:
• Hypothesize transformation T
Source: S. Lazebnik
• Extract features
• Compute putative matches
• Loop:
• Hypothesize transformation T
• Verify transformation (search for other matches consistent
with T)
Source: S. Lazebnik
• Extract features
• Compute putative matches
• Loop:
• Hypothesize transformation T
• Verify transformation (search for other matches consistent
with T)
Source: S. Lazebnik
?
Source: S. Lazebnik
?
() = ()
feature feature
descriptor descriptor
Feature descriptors
• Recall: feature detection and description
Source: S. Lazebnik
Feature descriptors
• Simplest descriptor: vector of raw intensity values
• How to compare two such vectors?
• Sum of squared differences (SSD)
2
SSD(u, v ) = ∑ (ui − vi )
i
– Not invariant to intensity change
• Normalized correlation
(u − u ) ( v − v ) ∑ i
(ui − u )(vi − v )
ρ (u, v) = ⋅ =
|| u − u || || v − v || ⎛ ⎞⎛ ⎞
2 2
⎜ ∑ (u j − u ) ⎟⎜ ∑ (v j − v ) ⎟
⎜ ⎟⎜ ⎟
⎝ j ⎠⎝ j ⎠
– Invariant to affine intensity change
Source: S. Lazebnik
Feature matching
• Generating putative matches: for each patch in one
image, find a short list of patches in the other image
that could match it based solely on appearance
?
Source: S. Lazebnik
Source: Y. Furukawa
Source: S. Lazebnik
Threshold of 0.8
provides good
separation
RANSAC
• The set of putative matches contains a very high
percentage of outliers
RANSAC loop:
1. Randomly select a seed 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
Putative matches
Source: S. Lazebnik
Matched B2
B1
2. Solve for affine keypoints
transformation parameters
Input
Image Stored
Image
Matching Keypoints
⎡ x⎤
⎡ x ʹ⎤ ⎡ a b c ⎤⎢ ⎥
⎢ y ʹ⎥ = ⎢d e ⎥ y
⎣ ⎦ ⎣ f⎦ ⎥⎢
⎢⎣ 1 ⎥⎦
⎡a ⎤
⎡ x1 y1 1 0 0 0⎤ ⎢ b ⎥ ⎡ x1ʹ ⎤
⎢ ⎥
⎢0 0 0 x1 y1 1 ⎢ c ⎥ ⎢ y1ʹ ⎥
⎥
⎢ ⎥⎢ ⎥ = ⎢ ⎥
⎢ x2 y2 1 0 0 0⎥ ⎢ d ⎥ ⎢ x2ʹ ⎥
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎣ .! ⎦ e ⎣!⎦
⎢ ⎥
⎣f⎦
Source: D. Hoeim
Finding the objects (in detail)
1. Match interest points from input image to database image
2. Get location/scale/orientation using Hough voting
• In training, each point has known position/scale/orientation wrt
whole object
• Matched points vote for the position, scale, and orientation of the
entire object
• Bins for x, y, scale, orientation
– Wide bins (0.25 object length in position, 2x scale, 30 degrees
orientation)
– Vote for two closest bin centers in each direction (16 votes
total)
3. Geometric verification
• For each bin with at least 3 keypoints
• Iterate between least squares fit and checking for inliers and
outliers
4. Report object if > T inliers (T is typically 3, can be computed to match
some probabilistic threshold)
Examples of recognized objects
Training
[Lowe04]
Slide credit: David Lowe
Key concepts
Alignment as robust fitting
• Affine transformations
• Homographies
• Descriptor-based feature
matching
• RANSAC