1 of 94

Automatic Image Alignment, Part 3

with a lot of slides stolen from

Steve Seitz and Rick Szeliski

© Mike Nese

CS180: Intro to Comp. Vision and Comp. Photo

Alexei Efros, UC Berkeley, Fall 2024

2 of 94

Feature-space outliner rejection

Can we now compute H from the blue points?

    • No! Still too many outliers…
    • What can we do?

3 of 94

Matching features

What do we do about the “bad” matches?

4 of 94

RAndom SAmple Consensus

Select one match, count inliers

5 of 94

RAndom SAmple Consensus

Select one match, count inliers

6 of 94

Least squares fit

Find “average” translation vector

7 of 94

RANSAC for estimating homography

RANSAC loop:

  1. Select four feature pairs (at random)
  2. Compute homography H (exact)
  3. Compute inliers where dist(pi’, H pi ) < ε
  4. Keep largest set of inliers
  5. Re-compute least-squares H estimate on all of the inliers

8 of 94

RANSAC

9 of 94

Example: Recognising Panoramas

M. Brown and D. Lowe,

University of British Columbia

10 of 94

Why “Recognising Panoramas”?

11 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images

12 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images

13 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images

14 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images
  • 2D Rotations (θ, φ)
    • Ordering matching images

15 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images
  • 2D Rotations (θ, φ)
    • Ordering matching images

16 of 94

Why “Recognising Panoramas”?

1D Rotations (θ)

    • Ordering ⇒ matching images
  • 2D Rotations (θ, φ)
    • Ordering matching images

17 of 94

Why “Recognising Panoramas”?

18 of 94

RANSAC for Homography

19 of 94

RANSAC for Homography

20 of 94

RANSAC for Homography

21 of 94

Probabilistic model for verification

22 of 94

Finding the panoramas

23 of 94

Finding the panoramas

24 of 94

Finding the panoramas

25 of 94

Finding the panoramas

26 of 94

Homography for Rotation

Parameterise each camera by rotation and focal length

This gives pairwise homographies

27 of 94

Bundle Adjustment

New images initialised with rotation, focal length of best matching image

28 of 94

Bundle Adjustment

New images initialised with rotation, focal length of best matching image

29 of 94

Results

30 of 94

Bad panorama?

Output of Brown & Lowe software

31 of 94

No geometrically consistent solution

32 of 94

The Chair

David Hockney (1985)

33 of 94

Joiners are popular

4,985 photos matching joiners.

4,007 photos matching Hockney.

41 groups about Hockney

Thousands of members

Flickr statistics:

34 of 94

Main goals: ���Automate joiners�� Generalize panoramas to general image collections

Zelnik-Manor & Perona (2007)

35 of 94

Objectives

For Artists:�Reduce manual labor

Manual: ~40min.

Fully automatic

36 of 94

Objectives

For Artists:�Reduce manual labor

For non-artists:�Generate pleasing-to-the-eye joiners

37 of 94

Objectives

For Artists:�Reduce manual labor

For non-artists:�Generate pleasing-to-the-eye joiners

For data exploration:�Organize images spatially

38 of 94

What’s going on here?

39 of 94

A cacti garden

40 of 94

Principles

41 of 94

Principles

Convey topology�

Correct

Incorrect

42 of 94

Principles

Convey topology�

A 2D layering of images

Blending:

blurry

Graph-cut:

cuts hood

Desired joiner

43 of 94

Principles

Convey topology�

A 2D layering of images�

Don’t distort images�

rotate

scale

translate

44 of 94

Principles

Convey topology�

A 2D layering of images�

Don’t distort images�

Minimize inconsistencies

Good

Bad

45 of 94

Algorithm

46 of 94

Step 1: Feature matching

Brown & Lowe, ICCV’03

47 of 94

Step 2: Align

Large inconsistencies

Brown & Lowe, ICCV’03

48 of 94

Step 3: Order

Reduced inconsistencies

49 of 94

Ordering images

Try all orders: only for small datasets

50 of 94

Ordering images

Try all orders: only for small datasets�

complexity: (m+n)α�m = # images�n = # overlaps�α = # acyclic orders

51 of 94

Ordering images

Observations:

    • Typically each image overlaps with only a few others
    • Many decisions can be taken locally

52 of 94

Ordering images

Approximate solution:

    • Solve for each image independently
    • Iterate over all images

53 of 94

Can we do better?

54 of 94

Step 4: Improve alignment

55 of 94

Iterate Align-Order-Importance

56 of 94

Iterative refinement

Initial

Final

57 of 94

Iterative refinement

Initial

Final

58 of 94

Iterative refinement

Initial

Final

59 of 94

What is this?

60 of 94

That’s me reading

61 of 94

Anza-Borrego

62 of 94

Tractor

63 of 94

Art reproduction

Paolo Uccello, 1436

64 of 94

Art reproduction

Paolo Uccello, 1436

Zelnik & Perona, 2006

65 of 94

Art reproduction

Single view-point

Zelnik & Perona, 2006

66 of 94

Manual by Photographer

67 of 94

Our automatic result

68 of 94

Homage to David Hockney

69 of 94

70 of 94

This Class Project

http://www.cs.cmu.edu/afs/andrew/scs/cs/15-463/f07/proj_final/www/echuangs/

71 of 94

Limitations of Alignment

We need to know the global transform (e.g. affine, homography, etc)

72 of 94

Optical flow

Will start by estimating motion of each pixel separately

Then will consider motion of entire image

73 of 94

Why estimate motion?

Lots of uses

    • Track object behavior
    • Correct for camera jitter (stabilization)
    • Align images (even if no global transform)
    • 3D shape reconstruction
    • Special effects

74 of 94

Problem definition: optical flow

How to estimate pixel motion from image H to image I?

    • Solve pixel correspondence problem
      • given a pixel in H, look for nearby pixels of the same color in I

Key assumptions

    • color constancy: a point in H looks the same in I
      • For grayscale images, this is brightness constancy
    • small motion: points do not move very far

This is called the optical flow problem

75 of 94

Optical flow constraints (grayscale images)

Let’s look at these constraints more closely

    • brightness constancy: Q: what’s the equation?
    • small motion: (u and v are less than 1 pixel)
      • suppose we take the Taylor series expansion of I:

76 of 94

Optical flow equation

Combining these two equations

In the limit as u and v go to zero, this becomes exact

77 of 94

Optical flow equation

Q: how many unknowns and equations per pixel?

Intuitively, what does this constraint mean?

    • The component of the flow in the gradient direction is determined
    • The component of the flow parallel to an edge is unknown

78 of 94

Aperture problem

79 of 94

Aperture problem

80 of 94

Solving the aperture problem

How to get more equations for a pixel?

    • Basic idea: impose additional constraints
      • most common is to assume that the flow field is smooth locally
      • one method: pretend the pixel’s neighbors have the same (u,v)
        • If we use a 5x5 window, that gives us 25 equations per pixel!

81 of 94

RGB version

How to get more equations for a pixel?

    • Basic idea: impose additional constraints
      • most common is to assume that the flow field is smooth locally
      • one method: pretend the pixel’s neighbors have the same (u,v)
        • If we use a 5x5 window, that gives us 25*3 equations per pixel!

82 of 94

Lukas-Kanade flow

Prob: we have more equations than unknowns

    • The summations are over all pixels in the K x K window
    • This technique was first proposed by Lukas & Kanade (1981)

Solution: solve least squares problem

    • minimum least squares solution given by solution (in d) of:

83 of 94

Conditions for solvability

    • Optimal (u, v) satisfies Lucas-Kanade equation

When is This Solvable?

    • ATA should be invertible
    • ATA should not be too small due to noise
      • eigenvalues λ1 and λ2 of ATA should not be too small
    • ATA should be well-conditioned
      • λ1/ λ2 should not be too large (λ1 = larger eigenvalue)

ATA is solvable when there is no aperture problem

84 of 94

Local Patch Analysis

85 of 94

Edge

  • large gradients, all the same
  • large λ1, small λ2

86 of 94

Low texture region

  • gradients have small magnitude
  • small λ1, small λ2

87 of 94

High textured region

  • gradients are different, large magnitudes
  • large λ1, large λ2

88 of 94

Observation

This is a two image problem BUT

    • Can measure sensitivity by just looking at one of the images!
    • This tells us which pixels are easy to track, which are hard
      • very useful later on when we do feature tracking...

89 of 94

Errors in Lukas-Kanade

When our assumptions are violated

    • Brightness constancy is not satisfied
    • The motion is not small
    • A point does not move like its neighbors
      • window size is too large
      • what is the ideal window size?

90 of 94

Iterative Refinement

Iterative Lukas-Kanade Algorithm

    • Estimate velocity at each pixel by solving Lucas-Kanade equations
    • Warp H towards I using the estimated flow field

- use image warping techniques

    • Repeat until convergence

91 of 94

Revisiting the small motion assumption

Is this motion small enough?

    • Probably not—it’s much larger than one pixel (2nd order terms dominate)
    • How might we solve this problem?

92 of 94

Reduce the resolution!

93 of 94

Coarse-to-fine optical flow estimation

image I

image H

Gaussian pyramid of image H

Gaussian pyramid of image I

image I

image H

u=10 pixels

u=5 pixels

u=2.5 pixels

u=1.25 pixels

94 of 94

Coarse-to-fine optical flow estimation

image I

image J

Gaussian pyramid of image H

Gaussian pyramid of image I

image I

image H

run iterative L-K

run iterative L-K

warp & upsample

.

.

.