1 An Efficiently Computable Metric for Comparing Polygonal Shapes Esther M. Arkin, L. Paul Chew,...

Preview:

Citation preview

1

An Efficiently Computable Metric for Comparing Polygonal ShapesEsther M. Arkin, L. Paul Chew, Daniel P. Huttenlocher, Klara Kedem, Joseph S.B. Mitchell

Liron Katav, Ilya Mirsky

A B

C D

2

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

3

Introduction Model-based recognition is concerned with

comparing a shape A, which is stored as a model for some particular object, with a shape B, which is found to exist in an image.

If A and B are close to be the same object, then the vision system should report a match and return a measure of how good the match is.

27/12/2010

A model of a circle

4

Introduction (cont’d)To be useful this measure should satisfy several properties:

It should be a metric. It should be invariant under translation, rotation,

scaling, in other words it should measure shape alone.

It should be reasonably easy to compute. It should match our intuition (i.e., answers should

be similar to those that a person might give). It should be insensitive to small perturbations.

27/12/2010

5

Introduction (cont’d) This article presents a method for comparing

polygons, that has the specified properties. The method is based on the L2 distance between

the turning functions of the 2 polygons. It works for both convex and non-convex polygons

and runs in time , where m and n are the number of vertices composing the 2 shapes.

The domain of the problem is polygons in the plane.

27/12/2010

6

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

7

DefinitionsDistance functions for plane:

A distance function is a metric iff: for all A and B. (triangle inequality)

27/12/2010

Ilya Mirsky
Remove?Add metric of distance between functions (integral)

8

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

9

Representation of Polygons1. Circular list of vertices, vertex is a coordinate pair.

2. Turning function which measures the counterclockwise tangent as a function of the arc-length s, measured from some reference point O on A’s boundary.

27/12/2010

O

V4

V3

V2V1

x axisO

10

Representation of Polygons (cont’d) measures the angle between the polygon edge and

some reference orientation (such as the x-axis). For subsequent polygon edge s, measures the angle

between the edge and the one that precedes in the polygon in counterclockwise order, for the whole length.

keeps track of the turning that takes place, increasing with left-hand turns, and decreasing with right-hand turns.

27/12/2010

s

s

O

2

O

V3

V2

x axis

V1

V1 V2 V3

11

Representation of Polygons (cont’d)

27/12/2010

The turning function

The turning function accumulates turns. Notice that it increases with left-hand turns, and decreases with right-hand turns.

s

s

2v

v

1

a

b

c

d

e

f

0

x axisva

b

c

d

e

f

12

Representation of Polygons (cont’d)Properties of function:

WLOG, assuming polygon is rescaled so that the total perimeter is 1,.

For a convex polygon A, is a monotone function starting at some value and increasing to .

For a non-convex polygon, may become arbitrarily large, since it accumulates the total amount of turn, which can grow as the polygon “spirals” inward.

The domain can be extended to whole by allowing angles to accumulate. Thus, for a simple closed polygon for all .

27/12/2010

13

Representation of Polygons (cont’d)Properties of function:

is well defined for arbitrary (not necessarily simple or closed or polygonal) paths A in the plane.

When the path is polygonal, is piecewise-constant, with jump points corresponding to the vertices of A.

Rotation of A corresponds to a simple shift of in the rotation direction.

Changing the location of the origin O by along the perimeter corresponds to a horizontal shift of the function , and is given by .

27/12/2010

14

Representation of Polygons (cont’d)Recall that we set out to design a distance function that was invariant to rotation, choice of reference point, and scale. 

Scale- handled by letting the length parameter s to range from 0 to 1. 

Rotation- If the order of the vertices remains the same, then the "inner angles" don't change, only the angle made with the first vertex changes.  Therefore, the only difference between the turning functions for a polygon A and a rotated copy A' is the first angle. Hence, let be the rotation angle, then the turning function of A’ will be the same as that for A, except that it will be shifted vertically by .

27/12/2010

Representation of Polygons (cont’d)

27/12/201015

Rotation only affects the first angle vx axisv

s

s

2v

v

10

x axisv

s

s

2v

v

10

16

Representation of Polygons (cont’d) Change of the reference point- Suppose the new

reference point is at position s = t in the polygon before the change.  In the new graph of the turning function, the actual angles and lengths remain the same, only the graph is shifted horizontally by t.

27/12/2010

s

s

O

2

0

V3V2

x axis

V1

17

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

18

Distance FunctionGiven two turning functions for polygons A and B denoted ΘA(s) and ΘB(s), we want to measure the similarity of the two polygons, invariant to rotation and choice of reference point in terms of these functions. In other words, we want to find the minimum distance between ΘA(s) and ΘB(s), over all possible ways to shift ΘA(s) horizontally by an amount t, and vertically by an amount θ.  When the notion of distance used is Euclidean distance (L2), then the distance d(A, B) is given by:

27/12/2010

Distance Function (cont’d)

27/12/201019

Minimization Problem

A s

B s

20

Distance Function (cont’d)Observations:

It’s a metric. It’s convex function- notice that d2(A, B)2 is a sum

of quadratic terms and is therefore a convex function. In order to compute the distance, we must minimize over all t's and θ's. Notice also that a minimum for d2(A, B) is a minimum for d2(A, B)2.  Since the latter function is convex, it admits a single minimum. This means that for a given value of t, the optimum value of θ depends on this t only and is unique. Thus, we have but a single-variable minimization problem.

27/12/2010

21

Distance Function (cont’d) Lemma: If we have the t that minimizes d2(A,

B)2, then the minimum θ* for this t is given by:

α remains constant for any value of t. It is the difference in the areas under ΘA(s) and ΘB(s), each computed as the sum of the products of length and height of each linear piece of the functions.

27/12/2010

22

Distance Function (cont’d)Suppose we know this θ*(t).  Then:

27/12/2010

1 2

0,1 0

1 2 2

0,1 0

1 2 2

0,1 0

1 2 2

0,1 0

min

min 2

min

min

A Bt

A B A Bt

A Bt

A Bt

s t s t ds

s t s t t s t s ds

s t s t ds

s t s ds t

2 ,d A B

23

Distance Function (cont’d) Now it remains to show how to compute |ΘA(s+t) -

ΘB(s)| for each t. 

Note that ΘA(s+t) is a copy of ΘA(s) read from t to t+1.  Since ΘA(s) can be defined over the whole real line (not just on [0, 1]), simply by repeating the pattern of the turning function infinitely to the left and to the right, with the pattern to the left increasing in height by 2π for each unit and the pattern to the right decreasing in height by 2π for each unit. 

27/12/2010

24

Distance Function (cont’d)

27/12/2010

s

s

2v

v

10 2

25

Distance Function (cont’d)Consider discontinuities of ΘA(s+t) and ΘB(s) in [0,1].  They make the rectangular strips made by the functions and the dashed lines. If polygon A has n vertices and polygon B has m vertices, then the number of "strips" made in this way is m + n - 1 (each vertex contributes a "step" of the turning angle function).

27/12/2010

A s

B s

26

Distance Function (cont’d) The portion between ΘA(s+t) and ΘB(s) over the interval

ds forms a rectangular strip.  In order to evaluate |ΘA(s+t) - ΘB(s)| over the interval ds, |

ΘA(s+t) - ΘB(s)| is computed as the height of the rectangular strip and ds is computed as the width of this strip. 

For a given t, we may now evaluate d2(A, B), since we know how to compute |ΘA(s+t) - ΘB(s)|, ds, and since θ*(t) is computed from t. 

Finally, we take the minimum over all t's.  Suppose the minimum distance occurs for some t*.  Then the best match between the two turning functions ΘB(s) and ΘA(s) occurs when ΘA(s) is shifted horizontally by t* and vertically by θ*(t*).

27/12/2010

27

Observations:

27/12/2010

During the shifting operation the breakpoints of ΘA(s+t) collide with the breakpoints of

ΘB(s). We define a critical event as a value of t where such colliding occurs.

There are m*n critical events. The distance function achieves its minimum at

one of the critical events. So, we get m*n possible values for t. This is

the number of ways in which a discontinuity of ΘA(s) can be aligned with a discontinuity of ΘB(s)

Ilya Mirsky
Why The distance function achieves its minimum at one of the critical events?

28

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

29

Algorithm Description

27/12/2010

1. For each of the mn critical events t for ΘA(s) and ΘB(s):

1.1. Find the function ΘA(s+t)

1.2. For each of the m+n-1 rectangular strips made by ΘA(s+t) and  ΘB(s):

1.2.1. Compute the height | ΘA(s+t) - ΘB(s)|, width ds, and θ*(t) 1.2.2. Get a final answer for the distance for this value of t 

1.3. Update the value of the current minimal distance    

2. Return the minimum distance

30

Time Complexity

27/12/2010

Calculation of the function ΘA(s+t) for a given t takes constant time (using the trick with extending ΘA(s) to the whole real line).

So does computing the height |ΘA(s+t) - ΘB(s)|, width ds, and θ*(t) within one rectangular strip, and also the updates of the distance take constant time.

we conclude that the algorithm runs in O(nm(n+m)) time.

The O(nm(n+m)) complexity could be improved to O(nmlog(nm)) by using more complex algorithm.

31

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

32

Examples

27/12/2010

33

Examples

27/12/2010

Distance : 0.485 Horizontal shift: 0.319 Vertical shift:-1.928

34

Examples

27/12/2010

35

Examples

27/12/2010

Distance : 0.847 Horizontal shift: 0.999 Vertical shift:-6.174

36

Examples

27/12/2010

Distance : 0.963 Horizontal shift: 0.228 Vertical shift:-2.03

37

Examples

27/12/2010

Resemblance to square and triangle, in decreasing order

Distance from original shape

38

Outline1. Introduction2. Definitions3. Representation of Polygons4. Distance Function5. The Algorithm6. Examples7. References

27/12/2010

39

References

27/12/2010

Esther M. Arkin, L. Paul Chew, Daniel P. Huttenlocher, Klara Kedem, Joseph S.B. Mitchell; “An Efficiently Computable Metric for Comparing Polygonal Shapes”, 1991.

http://www.cim.mcgill.ca/~sveta/pr/ http://www.wikipedia.org