Skip to content
A fully-automated greedy square jigsaw puzzle solver based on the paper of the same name by Pomeranz et al.
Jupyter Notebook Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
notebooks
.gitignore
README.md
main.py
rearrange_image.py
requirements.txt

README.md

shuffled-images

Square jigsaw puzzle solver based on [1]. Generates solutions for the Huawei Honorcup Marathon 2

Prerequisites

  • Python 3.6+

Quickstart

  1. Create a new virtual environment and install dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Dataset can be downloaded from https://yadi.sk/d/BmnFhkaD1Vy4vA
  2. Extract the data into data/ in the project root
  3. To run the solver on an image cut into 8x8 parts and scrambled:
$ python main.py data/data_train/64/1623.png 8 8
1623.png
50 8 43 45 25 57 52 35 11 36 56 63 40 41 5 12 0 21 1 27 13 46 33 17 31 34 58 60 15 59 14 38 54 23 26 49 18 37 55 16 32 42 47 6 3 53 7 2 62 61 30 39 29 44 48 24 22 9 10 28 20 51 19 4
1623.png,5.762885261,0.9553571428571429,1

The first two lines of the output are printed to stdout and are in the contest submission format, while the 3rd line was actually printed to stderr and contains some statistics about the solving process in the format basename,time taken,score,iterations.

  1. To view the unscrambled image, you can pass the tile indices (second line of the output above) to rearrange_image.py via standard input. The rest of the arguments are the input image, number of rows and columns and output file.
$ pbpaste | python rearrange_image.py data/data_train/64/1623.png 8 8 out.png

Running in parallel entire dataset

I used GNU Parallel to run the solver on the 300-600 images in each group. For example, to generate solutions for all the images in the data/data_test2_blank/64 folder:

mkdir -p results/A3
ls data/data_test2_blank/64 | parallel "python main.py data/data_test2_blank/64/{} 8 8 > results/A3/{}.txt"

lhis writes the solutions for each image into the results/A3 folder while printing statistics to the terminal through standard error.

To generate the final submission, just concatenate all the results together:

cat results/A3/* > results/A3.txt

[1]: D. Pomeranz, M. Shemesh, and O. Ben-Shahar, A fully automated greedy square jigsaw puzzle solver, In the Proceedings of the IEEE International Conference on Computer Vision and Pattern Recognition (CVPR), Colorado Springs, USA, June, pp. 9-16, 2011. See also the project page for more demos, info, and code

You can’t perform that action at this time.