# Shape context

﻿
Shape context

Shape Context is the term given by Serge Belongie and Jitendra Malik to the feature descriptor they first proposed in their paper "Matching with Shape Contexts" in 2000cite conference
author = S. Belongie and J. Malik
title = Matching with Shape Contexts
url = http://ieeexplore.ieee.org/iel5/6885/18538/00853834.pdf
booktitle = IEEE Workshop on Contentbased Access of Image and Video Libraries (CBAIVL-2000)
year = 2000
] . Shape context can be used in object recognition.

Theory

The shape context is intended to be a way of describing shapes that allows for measuring shape similarity and the recovering of point correspondences . The basic idea is to pick $n$ points on the contours of a shape. For each point $p_i$ on the shape, consider the $n - 1$ vectors obtained by connecting $p_i$ to all other points. The set of all these vectors is a rich description of the shape localized at that point but is far too detailed. The key idea is that the distribution over relative positions is a robust, compact, and highly discriminative descriptor. So, for the point $p_i$, the coarse histogram of the relative coordinates of the remaining $n - 1$ points,

$h_i\left(k\right) = #\left\{q e p_i : \left(q - p_i\right) in mbox\left\{bin\right\}\left(k\right)\right\}$

is defined to be the shape context of $p_i$. The bins are normally taken to be uniform in log-polar space. The fact that the shape context is a rich and discriminative descriptor can be seen in the figure below, in which the shape contexts of two different versions of the letter "A" are shown.

(a) and (b) are the sampled edge points of the two shapes. (c) is the diagram of the log-polar bins used to compute the shape context. (d) is the shape context for the circle, (e) is that for the diamond, and (f) is that for the triangle. As can be seen, since (d) and (e) are the shape contexts for two closely related points, they are quite similar, while the shape context in (f) is very different.

Now in order for a feature descriptor to be useful, it needs to have certain invariances. In particular it needs to be invariant to translation, scale, small perturbations, and depending on application rotation. Translational invariance come naturally to shape context. Scale invariance is obtained by normalizing all radial distances by the mean distance $alpha$ between all the point pairs in the shape cite journal
author = S. Belongie, J. Malik, and J. Puzicha
title = Shape Matching and Object Recognition Using Shape Contexts
url = http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/belongie-pami02.pdf
journal = IEEE Transactions on Pattern Analysis and Machine Intelligence
volume = 24
issue = 24
date = April 2002
pages = 509–521
doi = 10.1109/34.993558
] cite conference
author = S. Belongie, J. Malik, and J. Puzicha
title = Matching Shapes
url = http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/belongie-iccv01.pdf
booktitle = Eighth IEEE International Conference on Computer Vision (July 2001)
date=July 2001
] although the median distance can also be usedcite conference
author = S. Belongie, J. Malik, and J. Puzicha
title = Shape Context: A new descriptor for shape matching and object recognition
booktitle = NIPS 2000
year = 2000
] . Shape contexts are empirically demonstrated to be robust to deformations, noise, and outliers using synthetic point set matching experiments [cite conference
author = H. Chui and A. Rangarajan
title = A new algorithm for non-rigid point matching
booktitle = CVPR
volume = 2
pages = 44-51
date=June 2000
] .

One can provide complete rotation invariance in shape contexts. One way is to measure angles at each point relative to the direction of the tangent at that point (since the points are chosen on edges). This results in a completely rotationally invariant descriptor. But of course this is not always desired since some local features lose their discriminative power if not measured relative to the same frame. Many applications in fact forbid rotation invariance e.g. distinguishing a "6" from a "9".

Use in Shape Matching

A complete system that uses shape contexts for shape matching consists of the following steps (which will be covered in more detail in the #Details of Implementation section):

# Finding a list of points on shape edges
# Computing the shape context of each point found in step 1
# Calculating the cost of matching each point in the first shape to each point of the second shape
# Find the one-to-one matching that minimizes the total cost of matching. This is an instance of the assignment problem.
# Find a transformation (e.g. Affine, Thin plate spline, etc) that maps one shape to the other (essentially aligning the two shapes)
# Calculate the "shape distance" between the two shapes as a weighted sum of the shape context distance, image appearance distance, and bending energy (a measure of how much transformation is required to bring the two shapes into alignment)

Now that the shape distance has been calculated, the distance can be used in a nearest-neighbor classifier for a number of different object recognition problems.

Details of Implementation

tep 1: Finding a list of points on shape edges

The approach essentially assumes that the shape of an object is essentially captured by a finite subset of the points on the internal or external contours on the object. These can be simply obtained using the Canny edge detector and picking a random set of points from the edges. Note that these points need not and in general do not correspond to key-points such as maxima of curvature or inflection points. It is preferable to sample the shape with roughly uniform spacing, though it is not critical .

tep 2: Computing the shape context

This step is described in detail in the Theory section.

tep 3: Computing the cost matrix

Consider two points $p$ and $q$ that have normalized K-bin histograms (i.e. shape contexts) $g\left(k\right)$ and $h\left(k\right)$. As shape contexts are distributions represented as histograms, it is natural to use the $chi^2$ test statistic as the "shape context cost" of matching the two points:

$C_S = frac\left\{1\right\}\left\{2\right\}sum_\left\{k=1\right\}^K frac\left\{ \left[g\left(k\right) - h\left(k\right)\right] ^2\right\}\left\{g\left(k\right) + h\left(k\right)\right\}$

The values of this range from 0 to 1 .In addition to the shape context cost, an extra cost based on the appearance can be added. For instance, it could be a measure of tangent angle dissimilarity (particularly useful in digit recognition):

This is half the length of the chord in unit circle between the unit vectors with angles $heta_1$ and $heta_2$. Its values also range from 0 to 1. Now the total cost of matching the two points could be a weighted-sum of the two costs:

Now for each point $p_i$ on the first shape and a point $q_j$ on the second shape, calculate the cost as described and call it $C_\left\{i,j\right\}$. This is the cost matrix.

tep 4: Finding the matching that minimizes total cost

Now, a one-to-one matching $pi \left(i\right)!$ that matches each point $p_i$ on shape 1 and $q_j$ on shape 2 that minimizes the total cost of matching,

$H\left(pi\right) = sum_i Cleft \left(p_i,q_\left\{pi \left(i\right)\right\} ight \right)$

is needed. This can be done in $O\left(N^3\right)$ time using the Hungarian method, although there are more efficient algorithms [cite journal
author = R. Jonker and A. Volgenant
title = A Shortest Augmenting Path Algorithm for Dense and Sparse Linear Assignment Problems
journal = Computing
volume = 38
pages = 325–340
year = 1987
doi = 10.1007/BF02278710
] .To have robust handling of outliers, one can add "dummy" nodes that have a constant but reasonably large cost of matching to the cost matrix. This would cause the matching algorithm to match outliers to a "dummy" if there is no real match.

tep 5: Modeling Transformation

Given the set of correspondences between a finite set of points on the two shapes, a transformation $T : Bbb\left\{R\right\}^2 o Bbb\left\{R\right\}^2$ can be estimated to map any point from one shape to the other. There are several choices for this transformation, described below.

Affine

The affine model is a standard choice: $T\left(p\right) = Ap + o!$. The least squares solution for the matrix $A$ and the translational offset vector $o$ is obtained by:

$o = frac\left\{1\right\}\left\{n\right\}sum_\left\{i=1\right\}^n left \left(p_i - q_\left\{pi\left(i\right)\right\} ight \right), A = \left(Q^+ P\right)^t$

Where with a similar expression for $Q!$. $Q^+!$ is the pseudoinverse of $Q!$.

Thin Plate Spline

The thin plate spline (TPS) model is the most widely used model for transformations when working with shape contexts. A 2D transformation can be separated into two TPS function to model a coordinate transform:$T\left(x,y\right) = left \left(f_x\left(x,y\right),f_y\left(x,y\right) ight \right)$where each of the $f_x!$ and $f_y!$ have the form:

and the kernel function $U\left(r\right)!$ is defined by $U\left(r\right) = r^2log r^2!$. The exact details of how to solve for the parameters can be found elsewhere [cite conference
author = M.J.D. Powell
title = A Thin Plate Spline Method for Mapping Curves into Curves in Two Dimensions
booktitle = Computational Techniques and Applications (CTAC '95)
year = 1995
] [cite journal
author = J. Duchon
title = Splines Minimizing Rotation-Invariant Semi-Norms in Sobolev Spaces
journal = Constructive Theory of Functions of Several Variables
pages = 85–100
] but it essentially involves solving a linear system of equations. The bending energy (a measure of how much transformation is needed to align the points) will also be easily obtained.

Regularized TPS

The TPS formulation above has exact matching requirement for the pairs of points on the two shapes. For noisy data, it is best to relax this exact requirement. If we let $v_i$ denote the target function values at corresponding locations $p_i = \left(x_i,y_i\right)$ (Note that for $f_x$, $v_i$ would $x\text{'}$ the x-coordinate of the point corresponding to $p_i$ and for $f_y$ it would be the y-coordinate, $y\text{'}$), relaxing the requirement amounts to minimizing$H \left[f\right] = sum_\left\{i=1\right\}^n\left(v_i - f\left(x_i,y_i\right)\right)^2 + lambda I_f$ where $I_f!$ is the bending energy and $lambda!$ is called the regularization parameter. This $f$ that minimizes $H \left[f\right]$ can be found in a fairly straightforward way [cite book
author = G. Wahba
title = Spline Models for Observational Data
publisher = Soc. Industrial and Applied Math
year = 1990
] . If one uses normalize coordinates for $\left(x_i,y_i\right)mbox\left\{ and \right\} \left(x\text{'}_i,y\text{'}_i\right)$, then scale invariance is kept. However, if one uses the original non-normalized coordinates, then the regularization parameter needs to be normalized.

Note that in many cases, regardless of the transformation used, the initial estimate of the correspondences contains some errors which could reduce the quality of the transformation. If we iterate the steps of finding correspondences and estimating transformations (i.e. repeating steps 2-5 with the newly transformed shape) we can overcome this problem. Typically, three iterations are all that is needed to obtain reasonable results.

tep 6: Computing the shape distance

Now, a shape distance between two shapes $P!$ and $Q!$. This distance is going to be a weighted sum of three potential terms:

Shape context distance: this is the symmetric sum of shape context matching costs over best matching points: $D_\left\{sc\right\}\left(P,Q\right) = frac\left\{1\right\}\left\{n\right\}sum_\left\{p in P\right\} arg underset\left\{q in Q\right\}\left\{min\right\} C\left(p,T\left(q\right)\right) + frac\left\{1\right\}\left\{m\right\}sum_\left\{q in Q\right\} arg underset\left\{p in P\right\}\left\{min\right\} C\left(p,T\left(q\right)\right)$

Where $T\left(.\right)$ is the estimated TPS transform that maps the points in $Q$ to those in $P$.

Appearance cost: After establishing image correspondences and properly warping one image to match the other, one can define an appearance cost as the sum of squared brightness differences in Gaussian windows around corresponding image points:$D_\left\{ac\right\}\left(P,Q\right) = frac\left\{1\right\}\left\{n\right\}sum_\left\{i=1\right\}^nsum_\left\{Delta in Z^2\right\} G\left(Delta\right)left \left[I_P\left(p_i + Delta\right) - I_Q\left(T\left(q_\left\{pi\left(i\right)\right\}\right) + Delta\right) ight \right] ^2$

where $I_P!$ and $I_Q!$ are the gray-level images ($I_Q!$ is the image after warping) and $G!$ is a Gaussian windowing function.

Transformation cost: The final cost $D_\left\{be\right\}\left(P,Q\right)!,$ measures how much transformation is necessary to bring the two images into alignment. In the case of TPS, it is assigned to be the bending energy.

Now that we have a way of calculating the distance between two shapes, we can use a nearest neighbor classifier (k-NN) with distance defined as the shape distance calculated here. The results of applying this to different situations is given in the following section.

Results

Digit Recognition

The authors Serge Belongie and Jitendra Malik tested their approach on the [http://yann.lecun.com/exdb/mnist/ MNIST dataset of handwritten digits] . Currently, more than 50 algorithms have been tested on the database. The database has a training set of 60,000 examples, and a test set of 10,000 examples. The error rate for this approach was 0.63% using 20,000 training examples and 3-NN. At the time of publication, this error rate was the lowest. Currently, the lowest error rate is 0.39%.

ilhouette Similarity-based Retrieval

The authors experimented with the MPEG-7 shape silhouette database, performing Core Experiment CE-Shape-1 part B, which measures performance of similarity-based retrieval [cite journal
author = S. Jeannin and M. Bober
title = Description of core experiments for MPEG-7 motion/shape. Technical Report ISO/IEC JTC 1/SC 29/WG 11 MPEG99/N2690, MPEG-7, Seoul
date=March 1999
] . The database has 70 shape categories and 20 images per shape category. Performance of a retrieval scheme is tested by using each image as a query and counting the number of correct images in the top 40 matches. For this experiment, the authors increased the amount of points sampled from each shape. Also, since the shapes in the database sometimes were rotated or flipped, the authors took defined the distance between a reference shape and query shape to be minimum shape distance between the query shape and either the unchanged reference, the vertically flipped, or the reference horizontally flipped . With these changes, they obtained a retrieval rate of 76.45%, which by 2002 was the best.

3D Object Recognition

The next experiment performed on shape contexts involved the 20 common household objects in the [http://www1.cs.columbia.edu/CAVE/software/softlib/coil-20.php Columbia Object Image Library (COIL-20)] . Each object has 72 views in the database. In the experiment, the method was trained on a number of equally spaced views for each object and the remaining views were used for testing. A 1-NN classifier was used. The results are shown to the right. The authors also developed an "editing" algorithm based on shape context similarity and k-medoid clustering that improved on their performance .

Shape contexts were used to retrieve the closest matching trademarks from a database to a query trademark (useful in detecting trademark infringement). The figure to the left depicts nearest neighbor retrieval results from a database of 300 trademarks. No visually similar trademark was missed by the algorithm (verified manually by the authors).

* [http://www.eecs.berkeley.edu/Research/Projects/CS/vision/shape/sc_digits.html Matching with Shape Contexts]
* [http://yann.lecun.com/exdb/mnist/ MNIST database of handwritten digits]
* [http://www1.cs.columbia.edu/CAVE/software/softlib/coil-20.php Columbia Object Image Library (COIL-20)]
* [http://www.vision.caltech.edu/Image_Datasets/Caltech101/ Caltech101 Database]

References

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• Shape context — Construction d un contexte de contour. Shape context, que l on peut traduire par contexte de contour, est un algorithme de détection de caractéristique et un descripteur, présenté par des chercheurs de l université de Californie à Berkeley pour… …   Wikipédia en Français

• Shape grammar — Shape grammars in computation are a specific class of production systems that generate geometric shapes. With shape grammars, forms can be created that are not stored in the computer previously. Shape grammars have been studied in particular in… …   Wikipedia

• Context-sensitive help — is a kind of online help that is obtained from a specific point in the state of the software, providing help for the situation that is associated with that state. Context sensitive help, as opposed to general online help or online manuals, doesn… …   Wikipedia

• Shape of the Universe — Edge of the Universe redirects here. For the Bee Gees song, see Edge of the Universe (song). The local geometry of the universe is determined by whether Omega is less than, equal to or greater than 1. From top to bottom: a spherical universe, a… …   Wikipedia

• Formative Context — is an important theory developed by Roberto Unger. Unger is a Political Scientist but the theory has been heavily drawn on and used within the Social Study of Information Systems.In the field of Information Systems Claudio Ciborra and Giovan… …   Wikipedia

• Scale-invariant feature transform — Feature detection Output of a typical corner detection algorithm …   Wikipedia

• Histogram of oriented gradients — Histogram of Oriented Gradient descriptors, or HOG descriptors, are feature descriptors used in computer vision and image processing for the purpose of object detection. The technique counts occurrences of gradient orientation in localized… …   Wikipedia

• au̯(e)-9, au̯ed-, au̯er- (*aku̯ent- : aḫu̯ent-) —     au̯(e) 9, au̯ed , au̯er (*aku̯ent : aḫu̯ent )     English meaning: to flow, to wet; water, etc.     Deutsche Übersetzung: “benetzen, befeuchten, fließen”     Note: From Root angʷ(h)i : ‘snake, worm” derived Root akʷü (more properly ǝkʷü ):… …   Proto-Indo-European etymological dictionary

• Scale-invariant feature transform — Exemple de résultat de la comparaison de deux images par la méthode SIFT (Fantasia ou Jeu de la poudre, devant la porte d’entrée de la ville de Méquinez, par Eug …   Wikipédia en Français

• Ekolid — context In the Dungeons Dragons fantasy role playing game, the ekolid is a type of demon.Ekolids belong to the ancient race of demon called obyrith. Being obiryths, ekolids have monstrous forms, which can drive mad anyone who dares look at them.… …   Wikipedia