Project Title: Evolutionary Algorithm for Template Matching using Natural Selection Principles
This project implements image template matching using evolutionary algorithms inspired by Darwin's Theory of Natural Selection. Instead of traditional pattern matching, the algorithm simulates evolution via selection, crossover, and mutation to find image segments that match a given template.
- 👨💻 Group Leader: Zia Ur Rehman
- 🧑💻 Members: Noor Nabi, Shahrukh Khan
Instead of traditional programming techniques, this algorithm replicates Darwinian evolution by initializing a population and improving each generation based on fitness. The ultimate goal is to find a match between a template image and the best-fitting region in a larger image.
Darwin's theory revolves around survival of the fittest. Organisms evolve and adapt by selecting traits that maximize survival. This concept is used in this algorithm by generating, evaluating, and evolving image segments.
- Species evolve through small, beneficial adaptations.
- Favorable traits are preserved, unfavorable ones are eliminated.
- Populations diverge over time into new species (macroevolution).
- Overpopulation and competition drive evolution.
- Offspring with superior traits survive.
- Speciation can be allopatric (geographic) or sympatric (genetic drift).
- Population of image slices is initialized.
- Fitness is measured using correlation with the target template.
- Top individuals survive and generate the next generation using crossover and mutation.
Images are converted into 2D grayscale matrices using Python (matplotlib).
The large image is randomly sliced into smaller segments (same size as template) based on random coordinates.
Initial random population of image segments is generated. Fitness is calculated via Pearson correlation. NumPy is used for optimization.
Fitness values are sorted in descending order to select top candidates.
- Genetic operators applied to top individuals.
- Mutation done on significant bits or coordinates.
- Optimal parameters: 95% crossover, 0.5% mutation.
Process continues until a desired correlation threshold (e.g. 0.9) is reached.
- With larger populations (e.g. 1000), convergence to high correlation is faster.
- Randomization affects consistency of improvement.
- Best results require tuning mutation/crossover logic.
The algorithm demonstrates how biological logic can be adapted into computational models. While not always producing a steadily increasing fitness graph, evolutionary methods offer flexibility and resilience. Increasing initial population size significantly improves results.





