Abstract

In order to solve the shortcomings of traditional genetic algorithms in image matching in terms of computational speed and matching accuracy, this paper proposes a directed crossover genetic matching algorithm (DCGA) based on multilayer variation. The algorithm differs from the traditional genetic algorithm (GA) in which the crossover strategy is improved and a multilayer adaptive variation operator is introduced. The crossover operation selects a certain proportion of spherical individuals from each generation as the evolutionary target, and the rest of the individuals evolve towards it in each dimension; the variation operation stratifies the population and adopts different adaptive variation methods for different layers. Avoiding the shortcomings of traditional genetic algorithms that tend to fall into local extremes, thus alleviating premature convergence, improves the search performance of the algorithm. The algorithm proposed in this paper is compared with the commonly used genetic algorithm by testing the effect of the function and tested practically in template matching. The experimental results show that the improved genetic algorithm has better convergence speed and search accuracy.

1. Introduction

Image matching includes template matching, target matching, and dynamic pattern matching, among which template matching is the most common matching method, which is widely used in remote sensing images, medical imaging, computer vision, and many other fields. Traditional matching algorithms adopt an iterative region-dependent matching search strategy, which results in a large amount of time spent on nonoptimal matching points, making it difficult to use in real-time applications. Therefore, some foreign scholars have started to use genetic algorithms to study template matching problems, such as literature [1]. A large amount of practice has shown that traditional genetic algorithms applied to image matching may have the following shortcomings: (1) genetic operations tend to destroy the construction of individuals during recombination, resulting in the algorithm approaching a local optimum or premature maturity; (2) the computational effort of adaptation is large, resulting in the algorithm running at a speed that cannot meet the system’s real-time needs. Therefore, the genetic algorithm needs to be improved when applied to image matching.

There are two types of fast image matching algorithms in practice: the sequential similarity detection algorithm [2] (SSDA) and the multiresolution tower structure algorithm [3] (MPSA). The SSDA algorithm guarantees global optimality in image matching, but the SSDA algorithm has a variable matching time per frame with different target positions, which affects its implementation in practical engineering. The MPSA algorithm requires essentially the same matching time per frame, but its algorithm has the possibility of mismatching in principle, especially in low contrast conditions where it is more likely to be lost, and the algorithm trades the matching accuracy loss for speed improvement.

Heuristic algorithms are often used to solve optimization problems in real life, and there are three main categories: genetic algorithm, simulated annealing [4], and particle swarm optimization [5]. Compared with the other two algorithms, the genetic algorithm has the characteristics of simple and general, strong robustness, suitable for parallel processing, and high efficiency. Genetic algorithms take all individuals in the population as objects and use randomization techniques to guide an efficient search of an encoded parameter space. As Holland of the University of Michigan proposed [6], more and more researches have been carried out around this algorithm. After years of development, genetic algorithms are widely used in power grid line loss calculation [7], solving the traveling salesman problem [8], circuit design optimization [9], cloud computing resource allocation [10], job shop scheduling [11, 12], and other aspects, the algorithm is often used for the optimal solution of multipeak functions.

The main purpose of this paper is to propose a new directional crossover genetic algorithm by improving the crossover strategy and introducing the idea of multilayer adaptive mutation operator, so as to solve the problems of slow convergence and premature convergence of the genetic algorithm. The main contributions of this paper are as follows: (1) Directed crossover operator: directed crossover is an improvement to the crossover operation of traditional genetic algorithms, using the current optimal solution as the evolutionary direction of the target population, which is more responsive to the evolutionary direction of the whole population. Experimental results show that the directed crossover operator has faster convergence and higher search accuracy than the traditional genetic algorithm with a finite parent crossover operator. (2) The introduction of multilayer adaptive mutation operator: at the same time, the hierarchical adaptive mutation operator is proposed, and three kinds of mutation scale are introduced. The algorithm can adjust the variation range according to the convergence, ensuring that the algorithm can still explore the rest of the solution space while converging.

2. The Principle of Traditional Genetic Algorithm

In the genetic algorithm, n-dimensional decision vector is represented by a symbol string composed of symbols : regards each as a genetic gene, and all its possible values are called alleles. In this way, can be regarded as a chromosome composed of genetic genes. The simplest allele is composed of two integers 0 and 1, and the corresponding chromosome can be represented as a string of binary symbols. The permutation form formed by this code is the genotype of the individual, and the value corresponding to it is the phenotype of the individual. Chromosome is also called individual . For each individual , its fitness should be determined according to certain rules. The traditional genetic algorithm encodes the possible solutions of the target problem as chromosomes , the target problem is abstracted into a fitness calculation function , and the higher the fitness, the closer the chromosome is to the optimal solution of the problem. Multiple chromosomes constitute a population, and through the steps of crossover, mutation, and selection, the population converges to the optimal solution in multiple iterations.

At the beginning of the algorithm, the population is randomly generated, and the fitness of the population is calculated. Then, enter the selection link, randomly remove a part of the chromosomes according to the fitness, and supplement with the same amount of individuals with high fitness to form a new population. Then, the crossover operator is performed, the crossover probability is set to , the parent and cross to generate the child and , and the formula is as follows:

Here, is a random number between (0, 1), which reflects the inheritance degree of the offspring to the parent traits. Then, mutate individual to generate . The mutation formula is as follows:where () represents the random number in the interval , is the random number between , and represents the probability of mutation.

Cyclic execution of crossover, mutation, and selection operators can make the species chromosomes approach the optimal solution gradually, until the evolutionary algebra of the population reaches the specified value or the chromosome with the highest fitness meets the requirements. At this time, the best individual is the target searched by the algorithm. The traditional genetic algorithm is shown in Algorithm 1.

Input: :fitness function; :population; :parents; :children; :numbers of evolutions; :the predetermined number of iterations;
Output: optimal individual
1:initialize , and ;
2:repeat
3: evaluate fitness function of population
4: choose the population with higher fitness
5: select operation to according to formula (1)
6: Mutation operation to according to formula (2)
7:until

3. Directed Crossover Genetic Algorithm for Multilayer Mutation

Most of the traditional genetic algorithms use the method of limited parental crossover, which is difficult to reflect the overall situation of the population. It has the shortcomings of slow convergence speed and easy to fall into the extreme value, and the mutation operator has a single structure, resulting in poor search ability in the early operation of the algorithm and low search accuracy in the later operation. Low problem: in this paper, the idea of directional crossover is introduced, and the directional crossover operator of the algorithm is improved. At the same time, the hierarchical adaptive mutation operator is optimized, and a directional crossover genetic algorithm based on multilayer mutation is constructed.

3.1. Directional Crossing

The crossover process of the traditional genetic algorithm often adopts the crossover of two parents. In order to make the population converge faster, researchers have proposed some methods of multiparent crossover, such as the three-parent crossover operator mentioned in literature [13, 14], from three-parent chromosomes The individual with the greatest fitness is selected as the direction of the crossover. The idea of these crossover operators is to crossover within the local range limited by the parent, and the evolution range is limited. In order to better reflect the evolutionary direction of the population as a whole during the crossover process, this paper introduces the idea of directional crossover and sorts the chromosomes in the population according to the fitness. The greater the fitness, the better the chromosomes. In each iteration, the optimal part of individuals is selected as the common parent of the offspring.

Assuming that, after the selection operation, the individuals of the a-th generation population are sorted as according to their fitness size. For the D-dimensional problem, a single chromosome , and the population size is . Let the number of selected excellent chromosomes be , and the remaining chromosomes of the population are crossed with them, respectively. The formula of the crossover operator is as follows:

In formula (3), represents the -th dimension chromosome generated by crossover, represents the less adaptive chromosome in the -th generation, represents the excellent chromosome in this generation, and represent the fitness of individuals and . In the crossover process, the traits inherited by the offspring are affected by the fitness of the two parents, that is, the outstanding ones in the parents can pass on more imprints to the next generation, which improves the convergence speed. The directional crossover process is shown in Figure 1.

3.2. Hierarchical Adaptive Mutation

In the binary coded traditional genetic algorithm, the mutation operator flips every gene in chromosome with the same mutation probability. In the literature [15], the authors have proved that traditional mutation methods cannot effectively maintain the diversity of alleles at the same locus. In order to solve the shortcomings of traditional mutation operators with single structure and small mutation range, this paper proposes a corresponding hierarchical adaptive mutation operator that adjusts the mutation range based on convergence conditions.

Literature [16] proposed the concept of hierarchical mutation and improved the variation operation of traditional genetic algorithms by introducing the concept of hierarchical variation. Literature [1719] shows that the convergence speed and accuracy of the algorithm can be well optimized by improving the variational operation. In this regard, this paper adopts hierarchical adaptive mutation and divides the population into four layers according to the size of fitness, and the number of chromosomes in each layer is recorded as A, B, C, D. For individuals with different fitness, different mutation methods are applied to achieve the diversification of population search functions. Among them, layer A stores the current optimal chromosomes and does not participate in mutation, which can protect excellent traits.

In layer B, individuals with similar fitness order between two generations are selected to represent the evolution direction of the population. Preliminary simulation shows that group B represents individuals with similar fitness to the optimal parent generation in the operation process. The convergence goal is clear, and the intergenerational difference can effectively increase the performance of fine search. The mutation operator is as follows:where C is the -th generation generated after mutation; are the same dimension of the current generation chromosome and the previous generation chromosome with the same population fitness order, respectively; represents the standard normal distribution with the mean value of 0 and variance of 1.

In layer C, adaptive mutation strategy was adopted according to the current search range of the population. Because the fitness of the C-layer chromosome occupies a medium position in the population, it has limited role in solving the current exact solution, so it undertakes a large range of search work. The search area adopts an adaptive strategy, adjusting itself according to the current population dispersion. The formulas are as follows:where represents a random number with a mean of 0 and a variance of 1. , respectively, represent the constraint range solved by the algorithm and the search range of the -th dimension of the current population. is the scaling factor. It can be seen from the formula that the variance is positively correlated with , and the variation effect of this grouping can be changed by adjusting . When is too large, the variation tends to be random, and the convergence rate slows down. If is too small, the search range is narrow, and the algorithm converges prematurely. Through experiments, the convergence speed and search performance can be balanced when is between . It can be seen that when the population convergence degree is high, the standard deviation becomes larger, and the search range after C-layer variation increases. When the population is dispersed, is smaller, resulting in rapid convergence of chromosomes. This mutation operator has a feedback control effect on the global convergence.

Layer D has the smallest fitness, so it has the largest range of variation and is responsible for completely random search tasks.

is random number. Large scale variation occurred in this group of individuals, and the individuals after variation were randomly distributed in half solution space, further expanding the search scope. For this reason, intergenerational detection is set. The algorithm detects the search results every generation. When the fitness increase of the current optimal solution is found to be small, random initialization is performed on the chromosomes of layers B, C, and D.

Input: :fitness function; :crossed population; :number of evolutions;
Output: mutated population
1:Initialize: the population is ranked according to fitness;
2:if then then
3: no mutation; return
4:else if then
5: do B-layer mutation operation; return
6:else if then
7:do C-layer mutation operation; return
8:elsedo D-layer mutation operation; return
9:end if
10:if can be divided by 5 then
11:if then
12:  initialize layer B,C and D; return
13:end if
14:end if
3.3. Algorithm Flow

The algorithm in this paper adopts the termination method of the specified evolutionary algebra, and the overall flow of the improved algorithm is shown in Figure 2. Algorithm 2 is the framework of the improved algorithm in this paper.

In addition to the crossover operator and mutation operator mentioned in the text, the selection operator is also used in the algorithm to simulate the phenomenon of survival of the fittest in nature. In the selection, this paper adopts the roulette algorithm [20]: assuming that the fitness of individual is , and the number of individuals contained in the population is , the probability of it being retained is expressed asand this selection method can ensure that all individuals have a certain probability of being retained, and the greater the fitness, the greater the probability of being retained.

4. Experiments and Results Analysis

In order to verify the effectiveness of the designed directional crossover genetic algorithm based on multilayer mutation, eight tested functions are selected and compared with the three genetic algorithms of IGA [21], IRCGA [22], and TAGA [23], and the accuracy and convergence speed of the search results are compared.

4.1. Comparing Examples and Test Functions

In tests, the population size of each algorithm is set to 100, the number of iterations is 100, each algorithm runs independently 20 times, and the search range of the population limit is . The four algorithms to be tested are as follows:

DCGA: the directional cross genetic algorithm is proposed in this paper; the algorithm parameter settings are introduced in Section 2: .

IGA is an improved genetic algorithm based on real number coding, which is a classic algorithm that achieves adaptive adjustment during operation by changing the crossover and mutation probability. Mutation parameters ; adaptive parameters .

IRCGA: the improved real-coded genetic algorithm adopts the strategy of adaptively changing and and performs multiparental crossover, which can theoretically increase the speed of convergence and increase the efficiency of evolution: .

TAGA: an optimized genetic algorithm proposes the idea of learning from the best individual: .

We choose the following eight test functions:

Bohachevsky function: it is a unimodal bowl function and slowly converges to the minimum value 0 at [0, 0].

Schaffer function: it is a multimodal function and gets the minimum value at [0, 0].

Griewank function: it is a multimodal function and gets the minimum value 0 at [0, 0].

DropWave function: it is a multimodal function and gets the minimum value at [0, 0].

Rastrigin function: it is a multimodal function which has multiple local extremum and gets the minimum value 0 at [0, 0].

Sum-squares function: it is a unimodal function and gets the minimum value 0 at [0, 0].

Booth function: the function is disc-shaped and converges more slowly and gets the minimum value 0 at [1, 3].

Levy-13 function: this function is a multimodal function with a lot of folds and gets the minimum value 0 at [1, 1].

4.2. Results of Algorithm Experiment and Analysis

This paper takes the error between the searched value and the theoretical maximum value as the main comparison data. For the same test function, each algorithm is run twenty times. The test results are shown in Table 1. The convergence of each algorithm under each test function is shown in Figure 3. The minimum mean and minimum standard deviation in each test function are bolded in the figure.

Since most of the test functions achieve the minimum value at [0, 0], in order to prevent the special value of 0 from interfering with the running effect of the algorithm, before running, all test functions are shifted by 2.5 unit lengths in each dimension to reflect the randomness of the solution.

The local extremum of the multimodal function Schaffer is ring-shaped, and there are continuity equivalent solutions at the folds, which can easily interfere with the algorithm and make the algorithm converge on the extremum ring. It can be seen from the experimental results that the IGA, IRCGA, and TAGA algorithms are all trapped at the extreme value solution of 0.99, while the DCGA algorithm in this article can further jump out of the extreme value and find the most value point.

For Griewank, DropWave, Rastrigin, and Levy-13, the extreme point of this kind of multimodal function presents a peak shape around the extreme point, and the genetic operator can jump out of the extreme point. This type of function tests the convergence performance of the algorithm’s crossover operator. It can be seen from the iterative error evolution curve that the new algorithm has the fastest convergence speed in the multimodal function, and the accuracy is much higher than other algorithms. Once a possible solution is found, the algorithm can lock until the mutation operator makes the population find a better target.

The unimodal functions Bohachevsky, sum-squares, and booth have a small slope at the peak and a gentle peak, which are suitable for the search accuracy of the detection algorithm. The new algorithm in this paper shows excellent performance for these problems, fast convergence, and small error. The other algorithms slow down their convergence under a flat objective function, resulting in greater error than the DCGA algorithm.

It can be seen from Table 1 that, for the eight test functions, the errors of the DCGA algorithm are much smaller than that of the control group, and the smaller standard deviation also indicates that the new algorithm is also very stable in multiple runs.

4.3. Algorithms Tested in Template Matching

Template matching is to search for the target image position in the original image. When searching, it is necessary to take a subimage from the original image and compare it with the template. If the similarity between the two reaches a certain level, it can be considered that the target position has been found, and the search is over.

Assuming that the template is and the size is pixels, we place the template on the original image and move it. The coordinate in the upper left corner represents the current position. When the template moves, the corresponding subimage of the same shape is captured in the original image, and the subimage is used. The Euclidean distance with the template is the basis for judging the similarity:

In formula (16), the smaller the is, the higher the similarity between and is. In order to facilitate comparison, formula (16) is normalized, and the following formula is obtained after processing:

In formula (17), the similarity represents the matching degree between the subgraph and the template under the corresponding coordinates, and the closer the is to 1, the higher the matching degree. Considering the similarity calculation formula as a fitness function, the template matching problem can be regarded as a two-dimensional function optimization problem.

The template used in the test and the original image are shown in Figure 4. The search template is in the white box, the size is 8898 pixels, and the size of the original image is 10241024 pixels.

In this paper, the coordinates of the upper left corner point are used as independent variables. The optimal solution for matching is the pixel point . We simulate matching algorithm based on DCGA on the MATLAB software platform and compare the results with the runs of SSDA, traditional genetic algorithm (GA), and adaptive genetic algorithm (AGA) [24]. The DCGA algorithm proposed in this paper uses an improved directed crossover operation compared to the AGA algorithm and a hierarchical adaptive variation operator compared to the traditional GA algorithm. The population size and the number of iterations were set to 100, each algorithm was run independently for 50 times, and the similarity between the average searched subgraph and the template and the average number of iterations when convergence was recorded was recorded. The experimental results are shown in Table 2.

It can be seen from Table 2 that compared with the SSDA algorithm, the genetic algorithm can reduce the image matching time to a greater extent, among which the DAGA algorithm proposed in this paper has the shortest time in image matching. To verify the excellent performance of the DAGA algorithm in terms of global convergence, DAGA is compared with the GA and AGA algorithms. In 50 matching tests, the DCGA-based image matching algorithm achieved 100 percent matching accuracy every time, while the average matching accuracy of the GA and AGA algorithms were 79.1 percent and 88.3 percent, respectively, indicating that the algorithm proposed in this paper has good global convergence.

5. Conclusions

Aiming at the defects of slow convergence speed and premature convergence of traditional genetic algorithm, this paper proposes a multilayer mutation directed crossover genetic algorithm. On the one hand, the algorithm combines the crossover algorithm to improve the directional crossover operator and takes the current optimal solution of the population as the evolutionary goal to better reflect the evolution direction of the population; on the other hand, the algorithm introduces a multilayer adaptive operator to improve the accuracy of the degree of adaptation of different populations. The new algorithm and other comparison algorithms are compared in different dimensions for typical test functions and then compared in the model matching task. The two test results show that the optimization effect, convergence speed, and search ability of the algorithm have been greatly improved.

Data Availability

The test data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest

The authors declare that there are no conflicts of interest.

Acknowledgments

This work was supported by the National Natural Science Foundation of China (62003122), Natural Science Foundation of Anhui Province of China (2008085UD03 and 1808085MF180), and the Fundamental Research Funds for the Central Universities of China (PA2020GDKC0016).