A Genetic Algorithm-Based Solver for Jigsaw Puzzles :cyclone:
Genetic Algorithm based solver for jigsaw puzzles with piece size auto-detection.
$ git clone https://github.com/nemanja-m/gaps.git $ cd gaps
$ pip install -r requirements.txt $ sudo apt-get install python-tk
Install project in editable mode:
$ pip install -e .
To create puzzle from image use
$ create_puzzle images/pillars.jpg --size=48 --destination=puzzle.jpg
[SUCCESS] Puzzle created with 420 pieces
will create puzzle with
images/pillars.jpgwhere each piece is 48x48 pixels.
create_puzzle --helpfor detailed help.
NOTE Created puzzle dimensions may be smaller then original image depending on given puzzle piece size. Maximum possible rectangle is cropped from original image.
In order to solve puzzles, use
$ gaps --image=puzzle.jpg --generations=20 --population=600
This will start genetic algorithm with initial population of 600 and 20 generations.
Following options are provided:
--image| Path to puzzle
--size| Puzzle piece size in pixels
--generations| Number of generations for genetic algorithm
--population| Number of individuals in population
--verbose| Show best solution after each generation
--save| Save puzzle solution as image
gaps --helpfor detailed help.
If you don't explicitly provide
gaps, piece size will be detected automatically.
However, you can always provide
$ gaps --image=puzzle.jpg --generations=20 --population=600 --size=48
NOTE Size detection feature works for the most images but there are some edge cases where size detection fails and detects incorrect piece size. In that case you can explicitly set piece size.
The termination condition of a Genetic Algorithm is important in determining when a GA run will end. It has been observed that initially, the GA progresses very fast with better solutions coming in every few iterations, but this tends to saturate in the later stages where the improvements are very small.
This project as available as open source under the terms of the MIT License