48
Geometric Transformation and Image Warping Prof. Xin Yang HUST

Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Geometric Transformation and

Image Warping

Prof. Xin Yang

HUST

Page 2: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Definitions

T

Geometric transformation: Given two images, what is the transformation T between corresponding coordinates? Image Warping: Given a source image and a transformation T, what does the transformed output look like?

Page 3: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Obtain a wider angle view by combining multiple images.

image fro

m S. Seitz

. . .

Motivations: Panaroma

Page 4: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Time-lapse Mining from Internet Photos

Page 5: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Motivations: Analyzing Patterns and Shapes

Automatically rectified floor

The floor (enlarged)

What is the shape of the b/w floor pattern?

Slide from Antonio Criminisi

Page 6: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Motivations: Image Editing

Page 7: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Global Geometric Transformation

Original Translation Rotation Aspect

Scaling Affine Perspective

Page 8: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Global Geometric Transformation

• Transformation T is a coordinate-changing machine:

p’ = T(p)

• What does it mean that T is global? – It is the same for any point p

– It can be described by just a few numbers (parameters)

• Let’s represent T as a matrix:

T

p = (x, y) p’ = (x’,y’)

1 2

3 4

'

'

x

y

ta ax x xT

ta ay y y

Source: Alyosha Efros

Page 9: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

1 2

3 4

'

'

x

y

ta ax x xT

ta ay y y

Translation

' 1 0

' 0 1

x

y

tx x

ty y

Rotation

' cos sin

' sin cos

x x

y y

' 0

' 0

x a x

y b y

' 0

' 0

x a x

y a y

Aspect Scaling

Affine

' a cos bsin

' sin bcos

x

y

tx x

ty a y

Perspective

'

' f

1 1 1

x a b c x

y d e y

m n

Page 10: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

How to Estimate Geometric Transformation

1 2

3 4

'

'

x

y

ta ax x xT

ta ay y y

Estimate T is to estimate parameters a1, a2, a3, a4 , tx, ty

Three correspondences can compute a transformation Given a set of correspondences (include both inliers and outliers) How to derive a correct T?

Inliers: correct pairs of matching points which comply with the true transformation Outliers: erroneous pairs of matching points from two images which hurt the quality of parameter estimates

Page 11: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Outliers affect least squares fit

Page 12: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Outliers affect least squares fit

Page 13: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for Estimate Geometric Transformation

• 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 14: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

Source: R. Raguram Lana Lazebnik

Page 15: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

Least-squares fit

Source: R. Raguram Lana Lazebnik

Page 16: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

Source: R. Raguram Lana Lazebnik

Page 17: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

Source: R. Raguram Lana Lazebnik

Page 18: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

Source: R. Raguram Lana Lazebnik

Page 19: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

4. Select points consistent with model

Source: R. Raguram Lana Lazebnik

Page 20: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

4. Select points consistent with model

5. Repeat hypothesize-and-verify loop

Source: R. Raguram Lana Lazebnik

Page 21: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

21

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

4. Select points consistent with model

5. Repeat hypothesize-and-verify loop

Source: R. Raguram Lana Lazebnik

Page 22: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

22

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

4. Select points consistent with model

5. Repeat hypothesize-and-verify loop

Uncontaminated sample

Source: R. Raguram Lana Lazebnik

Page 23: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting example

1. Randomly select minimal subset of points

2. Hypothesize a model

3. Compute error function

4. Select points consistent with model

5. Repeat hypothesize-and-verify loop

Source: R. Raguram Lana Lazebnik

Page 24: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for line fitting

• Repeat N times:

• Draw s points uniformly at random

• Fit line to these s points

• Find inliers to this line among the remaining points (i.e., points whose distance from the line is less than t)

• If there are d or more inliers, accept the line and refit using all inliers

Lana Lazebnik

Page 25: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

• That is an example fitting a model

• (line)…

• What about fitting a transformation (translation)?

Page 26: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC example: Translation

Select one match, count inliers

Page 27: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC example: Translation

Select one match, count inliers

Page 28: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC example: Translation

Find “average” translation vector

Page 29: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC for estimating homography

• RANSAC loop:

• 1. Select four feature pairs (at random)

• 2. Compute homography H (exact)

• 3. Compute inliers where SSD(pi’, Hpi)< ε

• 4. Keep largest set of inliers

• 5. Re-compute least-squares H estimate on all of the inliers

Slide credit: Steve Seitz

Page 30: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

RANSAC pros and cons

• Pros – Simple and general

– Applicable to many different problems

– Often works well in practice

• Cons – Lots of parameters to tune

– Doesn’t work well for low inlier ratios (too many iterations, or can fail completely)

– Can’t always get a good initialization of the model based on the minimum number of samples

Lana Lazebnik

Page 31: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Recent Work for Geometric Transformation based on Correspondences

• O. Chum et al. Matching with PROSAC – Progressive Sample Consensus. In Proc. of CVPR, 2005

• C. Sweeney et al. gDLS: A Scalable Solution to the Generalized Pose and Scale Problem. In Proc. of ECCV, 2014

Page 32: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Mosaics

Obtain a wider angle view by combining multiple images.

image fro

m S. Seitz

. . .

T1

T2 T3

Page 33: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Image warping

Given a coordinate transform T and a source image f(x,y),

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

x x’

T(x,y)

f(x,y) g(x’,y’)

y y’

Slide from Alyosha Efros, CMU

Page 34: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Image warping

• Send each pixel f(x,y) to its corresponding location (x’,y’) = T(x,y) in the second image

Q: what if pixel lands “between” two pixels?

f(x,y) g(x’,y’) x x’

T(x,y)

y y’

Slide from Alyosha Efros, CMU

Page 35: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Image warping

• Send each pixel f(x,y) to its corresponding location (x’,y’) = T(x,y) in the second image

Q: what if pixel lands “between” two pixels?

f(x,y) g(x’,y’) x x’

T(x,y)

y y’

A: Interpolate color value from neighbors – nearest neighbor, bilinear…

Slide from Alyosha Efros, CMU

Page 36: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Bilinear interpolation

Sampling at f(x,y):

Slide from Alyosha Efros, CMU

Page 37: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Nearest Neighbor (3X)

HQ 3Xhttp://en.wikipedia.org/wiki/Image_scaling

HQ (3X)

Page 38: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Recap: How to stitch together a panorama (a.k.a. mosaic)?

• Basic Procedure

– Take a sequence of images from the same position • Rotate the camera about its optical center

– Compute transformation (homography) between second image and first using corresponding points.

– Transform the second image to overlap with the first.

– Blend the two together to create a mosaic.

– (If there are more images, repeat)

Source: Steve Seitz

Page 39: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

Source: L. Lazebnik

Page 40: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

• Extract features

Source: L. Lazebnik

Page 41: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

• Extract features • Compute putative matches

Source: L. Lazebnik

Page 42: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

• Extract features • Compute putative matches • Loop:

– Hypothesize transformation T (small group of putative matches that are related by T)

Source: L. Lazebnik

Page 43: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

• 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 44: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Robust feature-based alignment

• 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 45: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Creating and Exploring a Large Photorealistic Virtual Space

Josef Sivic, Biliana Kaneva, Antonio Torralba, Shai Avidan and William T. Freeman, Internet Vision Workshop, CVPR 2008. http://www.youtube.com/watch?v=E0rboU10rPo

Page 46: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t
Page 47: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t
Page 48: Image warping and stitching - UC Santa Barbaralbmedia.ece.ucsb.edu/member/uweb/Teaching/website/PPT/...How to Estimate Geometric Transformation 12 34 ' ' x y x x xaa t T y y yaa t

Summary: transformation & warping

• Write 2d transformations as matrix-vector multiplication

• Estimating geometric transformations: solve for unknown parameters given corresponding points from two views (exemplar method: RANSAC).

• Mosaics: uses homography and image warping to merge views taken from same center of projection