Next: Motion Planning Up: Computational Geometry Previous: Simplifying Polygons

## Shape Similarity

Input description: Two polygonal shapes, and .

Problem description: How similar are and ?

Discussion: Shape similarity is a problem that underlies much of pattern recognition. Consider a system for optical character recognition (OCR). We have a known library of shape models representing letters and the unknown shapes we obtain by scanning a page. We seek to identify an unknown shape by matching it to the most similar shape model.

The problem of shape similarity is inherently ill-defined, because what ``similar'' means is application dependent. Thus no single algorithmic approach can solve all shape matching problems. Whichever method you select, expect to spend a large chunk of time tweaking it so as to achieve maximum performance. Don't kid yourself - this is a difficult problem.

Among your possible approaches are:

• Hamming Distance - Assume that your two polygons have been overlaid one on top of the other. The Hamming distance measures the area of symmetric difference between the two polygons, in other words, the area of the regions lying within one of the two polygons but not both of them. If the two polygons are identical, and properly aligned, the Hamming distance will be zero. If the polygons differ only in a little noise at the boundary, then the Hamming distance will be small if the polygons are properly aligned. If the two polygons are completely disjoint, then the Hamming distance is the sum of the areas of the two polygons.

Computing the area of the symmetric difference reduces to finding the intersection or union of two polygons, as discussed in Section , and then computing areas, as discussed in . The difficult part of computing Hamming distance is finding the right alignment, or overlay, of the two polygons. For certain applications, such as OCR, the overlay problem is simplified because the characters are inherently aligned with the page and thus not free to rotate. Hamming distance is particularly simple and efficient to compute on bit-mapped images, since after alignment all we do is sum the differences of the corresponding pixels.

Although Hamming distance makes sense conceptually and can be simple to implement, it captures only a crude notion of shape and is likely to be ineffective in most applications.

• Hausdorff distance - An alternative distance metric is Hausdorff distance, which identifies the point on that is the maximum distance from and returns this distance. The Hausdorff distance is not symmetrical, for the distance from to is not necessarily the distance from to . Note the difference between Hamming and Hausdorff distance. A large but thin protrusion from one of the models will have a large effect on the Hausdorff distance but little on the Hamming distance. However, a fattening of the entire boundary of one of the models (as is liable to happen with boundary noise) by a small amount will increase the Hamming distance yet have little effect on the Hausdorff distance.

Which is better, Hamming or Hausdorff? It depends upon your application. As with Hamming distance, computing the right alignment between the polygons can be difficult and time-consuming. Again, Hausdorff distance captures only a crude notion of shape.

• Comparing Skeletons - A more powerful approach to shape similarity uses thinning (see Section ) to extract a tree-like skeleton for each object. This skeleton captures many aspects of the original shape. The problem now reduces to comparing the shape of two such skeletons, using such features as the topology of the tree and the lengths/slopes of the edges. This comparison can be modeled as a form of subgraph isomorphism (see Section ), with edges allowed to match whenever their lengths and slopes are sufficiently similar.
• Neural Networks - A final method for shape comparison uses neural networks, which are discussed in Section . Neural nets prove a reasonable approach to recognition problems when you have a lot of data to experiment with and no particular ideas of what to do with it. First, you must identify a set of easily computed features of the shape, such as area, number of sides, and number of holes. Based on these features, a black-box program (the neural network training algorithm) takes your training data and produces a classification function. This classification function accepts as input the values of these features and returns a measure of what the shape is, or how close it is to a particular shape.

How good are the resulting classifiers? It depends upon the application. Like any ad hoc method, neural networks usually take a fair amount of tweaking and tuning to realize their full potential.

One caveat. Because your classifier was developed by a black box, you never really know why your classifier is making its decisions, so you can't know when it will fail. An interesting case was a system built for the military to distinguish between images of cars and tanks. It performed very well on test images but disastrously in the field. Eventually, someone realized that the car images had been filmed on a sunnier day than the tanks, and the program was classifying solely on the presence of clouds in the background of the image!

Implementations: The Stuttgart Neural Network Simulator supports many types of networks and training algorithms, as well as sophisticated graphical visualization tools under X11. It has been ported to many flavors of UNIX. It is available for ftp from ftp.informatik.uni-stuttgart.de [129.69.211.2] in directory /pub/SNNS as SNNSv4.1.tar.gz (1.4 MB, Source code) and SNNSv4.1.Manual.ps.gz (1 MB, Documentation). It may be best to first have a look at the file SNNSv4.1.Readme. More information can be found in the WWW under http://www.informatik.uni-stuttgart.de/ipvr/bv/projekte/snns/snns.html

An alternate distance metric between polygons can be based on its angle turning function [ACH 91]. An implementation in C of this turning function metric by Eugene K. Ressler is provided on the algorithm repository http://www.cs.sunysb.edu/ algorith.

Notes: General books on pattern classification algorithms include [DH73, JD88]. A wide variety of computational geometry approaches to shape similarity testing have been proposed, including [AMWW88, ACH 91, Ata84, AE83, BM89, OW85].

A linear-time algorithm for computing the Hausdorff distance between two convex polygons is given in [Ata83], with algorithms for the general case reported in [HK90].

Related Problems: Graph isomorphism (see page ), thinning (see page ).

Next: Motion Planning Up: Computational Geometry Previous: Simplifying Polygons

Algorithms
Mon Jun 2 23:33:50 EDT 1997