Git Product home page Git Product logo

gaps's Introduction

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

gaps

demo

Installation

Clone repo:

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

Install requirements:

poetry install

Install project locally:

pip install .

Creating puzzles from images

To create puzzle from image use gaps create

gaps create images/pillars.jpg puzzle.jpg --size=64

will create puzzle with 240 pieces from images/pillars.jpg where each piece is 64x64 pixels.

original             puzzle

Run gaps create --help for detailed help.

NOTE: Created puzzle image dimensions may be smaller then original image depending on the given puzzle piece size. Maximum possible rectangle is cropped from original image.

Solving puzzles

In order to solve puzzles, use gaps run:

gaps run puzzle.jpg solution.jpg --generations=20 --population=600

This will start genetic algorithm with initial population of 600 and 20 generations.

Following options are provided:

Option Description
--size Puzzle piece size in pixels
--generations Number of generations for genetic algorithm
--population Number of individuals in population
--debug Show the best solution after each generation

Run gaps run --help for detailed help.

Size detection

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

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

gaps run puzzle.jpg solution.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 reaches an absolute number of generations

References

BibTeX entry:

@article{Sholomon2016,
  doi = {10.1007/s10710-015-9258-0},
  url = {https://doi.org/10.1007/s10710-015-9258-0},
  year = {2016},
  month = feb,
  publisher = {Springer Science and Business Media {LLC}},
  volume = {17},
  number = {3},
  pages = {291--313},
  author = {Dror Sholomon and Omid E. David and Nathan S. Netanyahu},
  title = {An automatic solver for very large jigsaw puzzles using genetic algorithms},
  journal = {Genetic Programming and Evolvable Machines}
}

License

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

gaps's People

Contributors

dependabot[bot] avatar jorlogicus avatar nemanja-m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gaps's Issues

the opencv-python version??

when i want to install gaps................

Installed /usr/local/lib/python3.10/dist-packages/gaps-1.0-py3.10.egg
Processing dependencies for gaps==1.0
Searching for opencv-python
Reading https://pypi.org/simple/opencv-python/
error: The read operation timed out

I have installed this
opencv_python-4.5.4.60-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64
from https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/opencv-python/

numpy==1.21.5
opencv-python==4.5.4.60
matplotlib==3.5.1
pytest==6.2.5
pillow==9.0.1
python version is 3.10.4

kali-linux 2022.2

tks

Issue with black and white images

The colored images are working neatly, but the second you throw a black and white image it feels kind of scattered around and not accurate at all

Problem

Hello. Please tell me the version of Python
Thanks in advance

Name

Thanks so much for sharing this great code
But you didn't mention what is the name of the paper of this code?

Genetic algorithm implementation.

Hi, I just want to ask a quick question, why are you using your own implementation of GA? There are several libraries already implementing a plethora of GA algorithms, one being pymoo.

requirements 模块版本问题

└─# pip install -r requirements.txt
Collecting numpy==1.22.0
Using cached numpy-1.22.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.8 MB)
ERROR: Could not find a version that satisfies the requirement opencv-python==4.2.0.32 (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 3.4.17.63, 3.4.18.65, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62, 4.5.5.64, 4.6.0.66)
ERROR: No matching distribution found for opencv-python==4.2.0.32

Need it to work with random size jigsaw pieces

Need it to work with random size jigsaw pieces. When the image is broken down into square based jigsaw pieces it works wonderfully. Was wondering how to change the code to break an image into random jigsaw puzzle and how to run the code to automatically solve the jigsaw pieces.

Assertion Error

Traceback (most recent call last):
  File "./gaps", line 43, in <module>
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(3.4.2) /io/opencv/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'

I might try to see if I can solve this later.

Logo proposal

Hello @nemanja-m, today while exploring GitHub looking for interesting projects found yours and I would love to contribute by designing a logo for it. I'm a designer in development and an open source enthusiast. We would be working together to create the design that fits best. Of course it's totally free and you can quit whenever you want. In case you agree, please let me know any preferences you may have about colors, shapes, etc you may have.

Kind regards.

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.