Shape recognition using genetic algorithms

Shape recognition is a challenging task when shapes overlap, forming noisy, occluded, partial shapes. The paper uses a genetic algorithm for matching input shapes with model shapes described in terms of features such as line segments and angles (extracted using traditional algorithms). The quality of matching is gauged using a measure derived from attributed shape grammars. Preliminary results, using shapes with about 30 features each, are extremely encouraging.


Introduction
Shape recognition is an important problem studied by numerous researchers.Given a set of model shapes and an input shape, the problem consists of identifying which of the model shapes are present in the input shape.For example, most robotics applications for part inspection and VLSI design involve locating and identifying objects.For shapes of objects that are occluded, or touch or overlap with other objects, a exible shape recognition algorithm is needed to identify overlapping shapes, making use of incomplete information.
The Generalized Hough Transform (GHT) 3] is one technique widely used in shape matching algorithms.Although this approach can be used for partial shape matching, the time-consuming nature of GHT makes it impossible to use it for realtime applications with large data.Turney et al. 14] suggested improvements to the GHT approach.The performance of such algorithms depend on how shapes are represented, and the extraction of combinations of global and local features of the model Author for correspondence: C. K. Mohan, 2-120 Center for Science and Technology, School of CIS, Syracuse University, Syracuse, NY 13244-4100; 315-443-2322/(fax) 1122; eozcan/mohan@top.cis.syr.edushapes.Model shape features are compared with features extracted from the input shape 1,4,8,10].Neural networks also provide powerful tools for solving the shape recognition problem 10,11,16].Yang et al. 15] proposed an algorithm which uses the attributed string representation for shapes and a two-layer network of Hop eld-like modules.
In this paper, a new approach is proposed for partial shape matching which utilizes genetic algorithms (GAs) and attributed string representations 12,13].The GA gave robust matching results for the test shapes, providing rotation and size independence.Di Ianni 5] has also applied GAs for matching shapes but the results they obtained were not encouraging, possibly because of using raw pixel arrays rather than shape features.Bala and Wechsler 2] use GAs to develop morphological operators that can discriminate among classes containing different shapes, not directly for shape matching.
Section 2 is an overview of attributed string representation.The new algorithm is introduced in Section 3. Section 4 describes experimental results, and the conclusions are presented in Section 5.

Attributed Strings
Attributed strings are used for the representation of shapes.Each shape is a polygon, made up of line segments.A string of features (x 1 ; x 2 ; :::; x i ; :::; x n ) is used to represent each shape.Each feature x i = (l i ; i ) is formed of two attributes: the length l i of the corresponding line segment, and the relative angle i it forms with the preceding line segment x i?1 .Example: The quadrilateral in Figure 1 Lengths are not normalized using the total length of a shape, since overlapped shapes may have a total length di erent from the sum of the lengths of the constituent shapes.This would cause the length information to be unreliable during the matching process.
Example: After normalization, the quadrilateral in Figure 1 is represented as: 3 Genetic Algorithm for Shape Matching Genetic Algorithms (GAs) were introduced by J. Holland 7], and have been used to solve many difcult problems 6].We assume familiarity with GA notation.
Given an input shape with n features and S model shapes with a total number of M features, we can cast partial shape matching as the problem of nding n matching features from M features.The search space is immense, of size ranging up to M n , since the input shape may contain multiple partial instances of the same model shape.

Representation
Each individual maps each input shape feature to one of the model shape features.Each individual is represented as a list of lists in which each entry has two slots, one showing the matching model shape and the other showing its corresponding feature.We use the following notation: For each feature, the normalized lengths and angles are obtained by the functions l and .
Input shape I = (I 1 ; I 2 ; :::; I n ), where I p is the pth feature, consisting of attributes (l(I p ); (I p )). Size of input shape jIj = n, the number of features in I.
The model shapes are M 1 ; M 2 ; :::; M S , where M j = (M j;1 ; M j;2 ; :::; M j;mj ); where M j;r is the rth feature of the jth model shape, consisting of attributes (l(M j;r ); (M j;r )).Size of the jth model shape jM j j = m j .
Each individual P = (P 1 ; P 2 ; :::; P k ; :::; P n ) corresponds to a mapping from input shape features to model shape features such that P k = (I k ) = m j;i , where 1 k n, 1 j S, and 1 i m j .

Initialization
The initial population is a set of randomly chosen individuals.Each individual is obtained as follows.First, an input shape feature I k is randomly chosen, and mapped to a randomly chosen feature M j;r in a randomly chosen model shape M j .Features I k+1 ; I k+2 ; : : : are then mapped to M j;r+1 ; M j;r+2 , etc., with the features of M j being traversed in circular manner.After assigning all possible features of M j , if any input shape features remain unassigned, then the next unassigned input shape feature I k+mj is mapped to a new randomly chosen model shape feature, M j 0 ;r 0 , followed by mapping as many as possible of the remaining input shape features I k+mj+1 ; I k+mj+2 ; : : : to M j 0 ;r 0 +1 ; M j 0 ;r 0 +2 ; : : :.This process is repeated until all input shape features have been assigned, tracing through input shape features in circular sequence, i.e., I 1 is the feature presumed to follow I n .
The size of the population is kept twice the size of the number of features of the input shape.

Fitness
The tness of an individual describes how well each feature of the input shape matches with the model shape feature to which it is matched.Fitness also depends on the degree of consistency between model features to which neighboring shape features are mapped.
Fitness is calculated by testing the compatibility of the input shape features and the corresponding model features to which an individual maps them The constant c is chosen in our experiments so that di erences upto =18 are considered negligible.If two successive features are not mapped by an individual to the same model shape, we use The distance between two features is compared with a threshold value.If the distance is small, then the corresponding primitive is marked as matched.Otherwise, the features are not considered to have matched: 0 otherwise The tness function penalizes the number of models to which input shape features are mapped by an individual.Fitness is calculated using the following formula:

Selection Mechanism
A linear ranking strategy was used during reproduction, with the best individual being allocated roughly ve times more o spring than the worst individual.An elitist survival selection mechanism was also used: the best two third (67%) of all individuals in a generation are allowed to survive into the next generation.These choices were made arbitrarily.

Operators
Crossover and mutation generate new individuals, and hill climbing is used to improve the solutions obtained.
Traditional one-point crossover (1PTX) is applied to the individuals, producing two children.
Mutation randomly chooses points on an individual, and maps input shape features to the features of randomly chosen model shapes.All the individuals are mutated with 30% mutation rate.This rate yielded the best performance in an experiment although the algorithm was successful even when lower mutation rates were used.
Hill climbing is applied to improve the mappings obtained at the borders between feature sequences mapped to di erent model shapes.
Each hill climbing step attempts to improve the tness of an individual by shifting the \intersection point" (between feature sequences mapped to di erent model shapes) in either direction, replacing the relevant component by the most appropriate feature from the model to which neighboring shape features are mapped.For instance, if (I k ) = M j;i and (I k+1 ) = M j 0 ;i 0 , hill climbing changes either (I k ) to M j 0 ;i 0 ?1 or (I k+1 ) to M j;i+1 , in case such a change improves tness.

Experimental Results
In our experiments, all shapes are polygons described as a sequence of adjacent features.Three sets of model shapes were used.The rst set is shown in Figure 2, the second set is shown in Figure 3 and the third set is shown in Figure 4.The total number of features of rst, second and third sets of model shapes were 77, 131 and 436 respectively.All of the input shapes used in the experiments can be found in Figure 5.In the gures, all the input and model shapes are uniquely numbered.We use the pre xes \i" and \m" to refer to input and model shapes, respectively, e.g., \i2" is the second input shape.
Input shapes i0, i1, i2, i3 and i4 constitute the rst set of input shapes in which the algorithm attempts to search for model shapes of the rst set; i5 and i6 constitute the second set; and i7, i8 and i9 constitute the third set.Except i6, all of the input shapes are obtained by overlapping two or three model shapes; in i6, the model shapes m8 and m9 are touching each other.The shape i2 is formed by overlapping two occurrences of the same model shape m5.Also, i5 is formed of m7 and m3, with m3 scaled to a size about 3 times larger than its original size; a similar case occurs in i7.The number of features of input shapes and the corresponding overlapping model shape labels are shown in Table 1.
Several experiments were rst performed to determine appropriate parameter values of the GA.For instance, experiments were conducted with input shape i3, varying mutation rate in the presence and absence of crossover and hill climbing.The experimental results, indicated in Table 2, show that each operator does not perform satisfactorily by itself.The algorithm works best if all of the three operators (crossover, mutation and hill climbing) are used.In such a case, the algorithm converged in tens of generations to the correct matching result (Figure 6).
Experimental results are summarized in Table 3.In the rst set of experiments, the input shape contains more features than each of the overlapping model shapes.In the second set of experiments, the input shape contains fewer features than one of the overlapping model shapes used.In the third set of experiments, a larger database is used.
Since our algorithm performs size invariant matching, input shapes such as i8 can also be matched successfully.In all cases, the algorithm succeeded in nding the model shapes, even if the input shape contained overlapped instances of the same model shape, as in i2.
Each test was repeated 100 times for i0-i6 and 50 times for i7-i9.Except in the case of i4, the correct result was found in every experiment with every input shape.For i4, 1 out of 100 runs converged to a wrong matching result.
As shown in Table 3, correct results are reached in 8-21 generations, on average.The maximum number of generations, in each run, was xed to be twice as large as the total number of model shape features.The number of hill climbing moves is larger, depending on the size of the input shape and the number of model shapes.Average system run times were less than a minute in all experiments, on a Sun workstation.
If a model shape is symmetric, and the input shape was obtained by overlapping such a symmet-ric shape with another model shape, there might be more than one possible solution, of equally good quality.This phenomenon was observed in the case of i2 and i5.

Conclusion
A new approach for shape recognition is developed, which combines genetic algorithms and attributed string representations.Outline features of shapes are represented using attributed strings.Each line segment is associated with a feature of two attributes: length and angle.Relative lengths and angles are used for size invariance.Experimental results show that the GA has been successful in shape-matching experiments attempted so far.
This new approach fro shape matching has several advantages.Firstly, it is much more computationally e cient than exhaustive search algorithms.Secondly, it is space-e cient compared to neural network models, most of which have large memory requirements.The algorithm is fast, and explores a relatively small number of elements of the search space.The use of many-individual populations and operations such as crossover overcomes the primary problem faced by a greedy algorithm which tends to get stuck in locally optimal solutions.So far, only polygons without holes have been used as model shapes and input shapes.Current work involves applying this promising algorithm to larger databases with many more model shapes, and analyzing input shapes containing a larger number of overlapping model shapes.

Figure 1 :
Figure 1: Attributed string representation of a shape.

Fitness
= ?(Number of partial shapes + Number of unmatched features of input shape)

Figure 2 :
Figure 2: Normalized model shapes used for the rst set of experiments.

Figure 3 :
Figure 3: Normalized model shapes used for the second set of experiments.

Figure 4 :
Figure 4: Normalized model shapes used for the third set of experiments.

Figure 5 :
Figure 5: Normalized input shapes used for the experiments.

Figure 6 :
Figure 6: Average tness and best tness, plotted against number of generations, for input shape i3, averaged over 10 runs.

Table 1 :
Composition of input shapes: number of features and model shapes used to obtain each input shape.

Table 2 :
Matching frequency (rate of discovery of correct solution) and average number of generations, in 25 runs for i3, varying the GA operators (Maximum number of generations is 154).

Table 3 :
Average number of generations, tness values and hill-climbing steps, in over 50 runs.