Skip to content

Commit

Permalink
Merge branch 'main' into feat/exact_solver
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Sep 22, 2023
2 parents 66663e6 + 494eeba commit c4ca3e4
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 570 deletions.
44 changes: 31 additions & 13 deletions .github/workflows/pytest.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tests
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
poetry-version: [1.1.8]
python-version: [3.8, 3.9, "3.10"]
poetry-version: [1.4.0]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v2.0.0
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: View poetry --help
run: poetry --help
- name: Configure poetry
shell: bash
run: poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v2
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- name: Install dependencies
shell: bash
run: |
poetry run pip install --upgrade pip
poetry install
- name: Run pytest
shell: bash
run: poetry run pytest -q tests

readme:
runs-on: ubuntu-latest
needs: ci
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: Insstall poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
- run: poetry install
- run: make readme
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "ci: Update readme"
branch: ${{ github.head_ref }}
commit_user_name: github-actions[bot]
commit_user_email: github-actions[bot]@users.noreply.github.com
commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021, Loic Coyle
Copyright (c) 2023, Loic Coyle

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: readme
readme:
@awk -i inplace -v q="\`\`\`" 'BEGIN {p=1} /^<!-- help start -->/{print;print "";print q;print "$$ phomo -h";system("poetry run phomo -h");print q;print "";p=0} /^<!-- help end -->/{p=1} p' README.md
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
It arranges the tile images to best recreate a master image. To achieve this, `phomo` computes a distance matrix between all the tiles and the master image regions, looking not just at the average colour but the norm of the colour distributions differences.
Once this distance matrix is computed, each tile is assigned to the region of the master with the smallest distance between the colour distributions.

## Installation
## 📦 Installation

Requires python 3

Expand All @@ -26,7 +26,7 @@ As always, it is usually a good idea to use a [virtual environment](https://docs

If you're just interested in command line usage, consider using [pipx](https://pypa.github.io/pipx/).

## Usage
## 📋 Usage

### Python package

Expand All @@ -44,17 +44,22 @@ $ phomo master.png tile_directory -S 20 20 -o mosaic.png

If in doubt see the help:

<!-- help start -->

```
usage: phomo [-h] [-o OUTPUT] [-c MASTER_CROP_RATIO] [-s MASTER_SIZE [MASTER_SIZE ...]] [-C TILE_CROP_RATIO]
[-S TILE_SIZE [TILE_SIZE ...]] [-n N_APPEARANCES] [-v] [-b] [-g] [-d SUBDIVISIONS [SUBDIVISIONS ...]]
$ phomo -h
usage: phomo [-h] [-o OUTPUT] [-c MASTER_CROP_RATIO]
[-s MASTER_SIZE [MASTER_SIZE ...]] [-C TILE_CROP_RATIO]
[-S TILE_SIZE [TILE_SIZE ...]] [-n N_APPEARANCES] [-v] [-b] [-g]
[-d SUBDIVISIONS [SUBDIVISIONS ...]]
[-m {greyscale,norm,luv_approx}] [-j WORKERS]
master tile_dir
positional arguments:
master Master image path.
tile_dir Directory containing the tile images.
optional arguments:
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Mosiac output path.
Expand All @@ -77,14 +82,17 @@ optional arguments:
-m {greyscale,norm,luv_approx}, --metric {greyscale,norm,luv_approx}
Distance metric.
-j WORKERS, --workers WORKERS
Number of workers use to run when computing the distance matrix.
Number of workers use to run when computing the
distance matrix.
```

## Note
<!-- help end -->

## 🤩 Credit

The grid subdivision feature was inspired by [photomosaic](https://pypi.org/project/photomosaic/).
- [photomosaic](https://pypi.org/project/photomosaic/) for the grid subdivision feature.

## TODO
## ✔️ TODO

- [x] look into parallelizing/multithreading
- [ ] look into non greedy tile assignments
Expand Down
329 changes: 138 additions & 191 deletions examples/performance.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit c4ca3e4

Please sign in to comment.