Skip to content

Commit

Permalink
Add/Remove images
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanja-m committed Sep 12, 2017
1 parent d73a644 commit 70d0172
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ To create puzzle from image use `create_puzzle` script.
i.e.

```bash
$ create_puzzle images/butterfly.jpg --size=28 --destination=puzzle.jpg
```
$ create_puzzle images/pillars.jpg --size=48 --destination=puzzle.jpg

will create puzzle from `lena.jpg` where each puzzle piece is 28x28 pixels.
Run `create_puzzle --help` for detailed help.
[SUCCESS] Puzzle created with 420 pieces

```

Puzzle is created from input image by shuffling pieces.
will create puzzle with `420` pieces from `images/pillars.jpg` where each piece is 48x48 pixels.

<div align="center">
<img src="images/butterfly.jpg" alt="original" width="250" height="180" />
<img src="images/pillars.jpg" alt="original" width="250" height="180" />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<img src="images/demo_puzzle.jpg" alt="original" width="250" height="180" />
<img src="images/demo_puzzle.jpg" alt="puzzle" width="250" height="180" />
</div>

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

Expand All @@ -61,10 +63,10 @@ In order to solve puzzles, use `gaps` script.
i.e.

```bash
$ gaps --image=puzzle.jpg --size=28 --generations=20 --population=300
$ gaps --image=puzzle.jpg --size=48 --generations=20 --population=600
```

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

Following options are provided:

Expand Down
5 changes: 2 additions & 3 deletions gaps/genetic_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@


class GeneticAlgorithm(object):
ELITISM_FACTOR = 0.02

def __init__(self, image, piece_size, population_size, generations):
def __init__(self, image, piece_size, population_size, generations, elite_size=2):
self._image = image
self._piece_size = piece_size
self._generations = generations
self._elite_size = int(population_size * self.ELITISM_FACTOR)
self._elite_size = elite_size
pieces, rows, columns = image_helpers.flatten_image(image, piece_size, indexed=True)
self._population = [Individual(pieces, rows, columns) for _ in range(population_size)]
self._pieces = pieces
Expand Down
Binary file removed images/butterfly.jpg
Binary file not shown.
Binary file modified images/demo_puzzle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pillars.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/tulips.png
Binary file not shown.

0 comments on commit 70d0172

Please sign in to comment.