Git Product home page Git Product logo

gaps's Introduction

Genetic Algorithm based solver for jigsaw puzzles with piece size auto-detection.

Build Status

demo

Installation

Clone repo:

$ git clone https://github.com/nemanja-m/gaps.git
$ cd gaps

Install requirements:

$ pip install -r requirements.txt
$ sudo apt-get install python-tk

Install project in editable mode:

$ pip install -e .

Creating puzzles from images

To create puzzle from image use create_puzzle script.

i.e.

$ create_puzzle images/pillars.jpg --size=48 --destination=puzzle.jpg

[SUCCESS] Puzzle created with 420 pieces

will create puzzle with 420 pieces from images/pillars.jpg where each piece is 48x48 pixels.

original             puzzle

Run create_puzzle --help for 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.

Solving puzzles

In order to solve puzzles, use gaps script.

i.e.

$ 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:

Option Description
--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

Run gaps --help for detailed help.

Size detection

If you don't explicitly provide --size argument to gaps, piece size will be detected automatically.

However, you can always provide gaps with --size argument explicitly:

$ 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.

Termination condition

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.

gaps will terminate:

  • when there has been no improvement in the population for X iterations, or
  • when it reachs an absolute number of generations

License

This project as available as open source under the terms of the MIT License

gaps's People

Contributors

nemanja-m avatar jorlogicus avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.