Top Banner
1 Photogrammetry & Robotics Lab Image Template Matching Using Cross Correlation Cyrill Stachniss The slides have been created by Cyrill Stachniss.
46

Image Template Matching Using Cross Correlation

Apr 03, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Image Template Matching Using Cross Correlation

1

Photogrammetry & Robotics Lab

Image Template Matching Using Cross Correlation

Cyrill Stachniss

The slides have been created by Cyrill Stachniss.

Page 2: Image Template Matching Using Cross Correlation

2

Example: Image Alignment Using Corresponding Points

Image courtesy: Efros

Page 3: Image Template Matching Using Cross Correlation

3

Example: Image Alignment Using Corresponding Points

Image courtesy: Efros

Page 4: Image Template Matching Using Cross Correlation

4

Estimating 3D Information

Given corresponding points and the orientation of the cameras, we can compute the point locations in 3D

Image courtesy: Schindler

Page 5: Image Template Matching Using Cross Correlation

5

Data Association

§  If we know the corresponding points, (and the orientation of cameras), we can perform a 3D reconstruction

§  For stereo image matching, images are taken under similar conditions

Question: Can we localize a local image patch in another image?

Page 6: Image Template Matching Using Cross Correlation

6

Data Association

Image courtesy: Förstner, Wenzel

Page 7: Image Template Matching Using Cross Correlation

7

Data Association

Image courtesy: Förstner

How to know which parts of both images correspond to each other?

Page 8: Image Template Matching Using Cross Correlation

8

Cross Correlation DE: “Kreuzkorrelation”

Page 9: Image Template Matching Using Cross Correlation

9

Cross Correlation (CC)

Cross correlation is a powerful tool to: §  Find certain image content in an image §  Determine its location in the image

Key assumption: Images differ only by §  Translation §  Brightness §  Contrast

Page 10: Image Template Matching Using Cross Correlation

10

Template Matching

template

§  Find the location of a small template image within a (larger) image

§  Usually: size of template << size of image

image

?

Page 11: Image Template Matching Using Cross Correlation

11

Template Matching

template and a point Pm

§  Find the location of a small template image within a (larger) image

§  Usually: size of template << size of image

image

x

(0,0) j

i

u

v q

p

x ?

Page 12: Image Template Matching Using Cross Correlation

12

Principle §  Given image g1(i, j) and template g2(p, q) §  Find offset between g1 and g2

Image courtesy: Förstner

Page 13: Image Template Matching Using Cross Correlation

13

Assumptions

§  Geometric transformation

Two unknowns §  Radiometric transformation

§  Intensities of each pixel in g2 are linearly dependent of those of g1

§  Two additional unknowns

translation only

contrast

brightness

Page 14: Image Template Matching Using Cross Correlation

14

Problem Definition

Task: Find the offset that maximizes the similarities of the corresponding intensity values

How to quantify “similarity”?

Page 15: Image Template Matching Using Cross Correlation

15

Typical Measures of Similarity

§  Sum of squared differences (SSD)

§  Sum of absolute differences (SAD)

§  Maximum of differences

No invariance against changes in brightness and contrast!

Page 16: Image Template Matching Using Cross Correlation

16

Cross Correlation Function

Best estimate of the offset is given by maximizing the cross correlation coefficient over all possible locations

Page 17: Image Template Matching Using Cross Correlation

17

Normalized Cross Correlation

Standard deviation of intensity values of the template

Standard deviation of intensity values of the image in the area overlayed by template

Product of the variations of intensities from mean in template and image

Page 18: Image Template Matching Using Cross Correlation

18

Normalized Cross Correlation

Standard deviation of intensity values of template g2

Number of pixels in g2

Sum over all rows and columns of the template g2

Mean of intensities in g2

Page 19: Image Template Matching Using Cross Correlation

19

Normalized Cross Correlation

Standard deviation of intensity values of g1 in the area overlapping with template g2 given offset

Number of pixels in g2 !!

Mean of intensity values in overlap area

Sum over all rows and columns in overlap area with template g2

Page 20: Image Template Matching Using Cross Correlation

20

Normalized Cross Correlation

Covariance between intensity values of g1 and in the overlap area with template g2 given offset

Page 21: Image Template Matching Using Cross Correlation

21

Search Strategies

How to search the best position?

?

Image courtesy: Förstner

Page 22: Image Template Matching Using Cross Correlation

22

Exhaustive Search §  For all offsets

compute

§  Select offset for which is maximized

Page 23: Image Template Matching Using Cross Correlation

23

Complexity

§  Full search in the 2D translation parameters

§  In theory we can also search for rotation and other parameters

§  Complexity increases exponentially with the dimension of the search space

Dimension of search space

Number of possible locations in dimension d

Page 24: Image Template Matching Using Cross Correlation

24

Coarse-To-Fine Strategy Using an Image Pyramid §  Iteratively use resized image from

large to small §  Start on top of the pyramid §  Match gives initialization for next level

Image courtesy: Förstner

Page 25: Image Template Matching Using Cross Correlation

25

Example

Cross correlation of §  a and A: ? §  b and B: ? §  c and C: ? §  d and D: ?

Page 26: Image Template Matching Using Cross Correlation

26

Example

Cross correlation of §  a and A: no match, ρ = 1 everywhere §  b and B: ? §  c and C: ? §  d and D: ?

Page 27: Image Template Matching Using Cross Correlation

27

Example

Cross correlation of §  a and A: no match, ρ = 1 everywhere §  b and B: several matches, ρ = 1 at every cross §  c and C: ? §  d and D: ?

Page 28: Image Template Matching Using Cross Correlation

28

Example

Cross correlation of §  a and A: no match, ρ = 1 everywhere §  b and B: several matches, ρ = 1 at every cross §  c and C: no match §  d and D: ?

Page 29: Image Template Matching Using Cross Correlation

29

Example

Cross correlation of §  a and A: no match, ρ = 1 everywhere §  b and B: several matches, ρ = 1 at every cross §  c and C: no match §  d and D: exactly one match

Page 30: Image Template Matching Using Cross Correlation

30

Basic Cross Correlation

§  Searches for a template image in another image

§  CC is fast and easy to compute §  CC allows for variations in translation,

brightness, contrast §  Changes in brightness and contrast

though cross correlation function §  Search space defined by the

translation parameters

Page 31: Image Template Matching Using Cross Correlation

31

Subpixel Estimation for Cross Correlation

Page 32: Image Template Matching Using Cross Correlation

32

Subpixel Estimation

§  Result of template matching by cross correlation is integer-valued

§  More precise estimate can be obtained through subpixel estimation

Page 33: Image Template Matching Using Cross Correlation

33

Subpixel Estimation

Page 34: Image Template Matching Using Cross Correlation

34

Subpixel Estimation

Page 35: Image Template Matching Using Cross Correlation

35

Subpixel Estimation

Page 36: Image Template Matching Using Cross Correlation

36

Subpixel Estimation

Page 37: Image Template Matching Using Cross Correlation

37

Subpixel Estimation

§  Result of template matching by cross correlation is integer valued

§  More precise estimate can be obtained through subpixel estimation

Procedure §  Fit a locally smooth surface through

around the initial position §  Estimate its local maximum

Page 38: Image Template Matching Using Cross Correlation

38

Subpixel Estimation

§  Fit a quadratic function around

NCC function in

maximum at unknown

Page 39: Image Template Matching Using Cross Correlation

39

Subpixel Estimation

§  Fit a quadratic function around

§  Compute first derivative

§  At maximum:

NCC function in

maximum at unknown

Page 40: Image Template Matching Using Cross Correlation

40

Subpixel Estimation

§  First derivative §  Hessian §  We can rewrite this to §  which leads to

§  and finally to

Page 41: Image Template Matching Using Cross Correlation

41

Subpixel Estimation

§  For an image, consists of

Sobel

Operators for 2nd derivatives

Page 42: Image Template Matching Using Cross Correlation

42

Subpixel Estimation

Operators from the chapter “local operators”

Sobel 2nd derivatives

Page 43: Image Template Matching Using Cross Correlation

43

Discussion

§  CC provides the optimal solution when considering only translations

§  Using subpixel estimation, we can obtain a 1/10 pixel precision

§  CC assumes equal and uncorrelated noise in both images

§  CC cannot deal with occlusions §  Optimizations for certain situation

(zero mean signals, const. variance)

Page 44: Image Template Matching Using Cross Correlation

44

Discussion

§  Quality drops considerably when violating the model assumptions §  rotation >20° §  scale difference >30%

Page 45: Image Template Matching Using Cross Correlation

45

Summary §  Cross correlation is a standard

approach for localizing a template image patch in another image

§  CC is fast and easy to compute §  CC allows for variations in translation,

brightness, contrast §  Subpixel estimation up to 1/10 pixel

Page 46: Image Template Matching Using Cross Correlation

46

Literature

§  Szeliski, Computer Vision: Algorithms and Applications, Chapter 4

§  Förstner, Scriptum Photogrammetrie I, Chapter “Matching / Kreuzkorrelation”