Skip to main content

Python package and CLI utility to create photo mosaics.

Prefer rust? Or a npm package? Check out loiccoyle/phomo-rs!

phomo lets you create photographic mosaics. 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 optimal master image region by solving the linear sum assignment problem.

📦 Installation

In a terminal:

pip install phomo

# or for GPU acceleration:

pip install 'phomo[cuda]'

As always, it is usually a good idea to use a virtual environment.

If you're just interested in command line usage, consider using pipx.

📋 Usage

Python package

Check out the docs and the examples.

CLI

Once it is installed, you can use the phomo command.

It would go something like:

phomo master.png tile_directory/ -S 20 20 -o mosaic.png

If in doubt see the help:

$ 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] [-b] [-g]
             [-d SUBDIVISIONS [SUBDIVISIONS ...]] [-G]
             [-m {greyscale,norm,luv_approx}] [-j WORKERS] [-e]
             [--match-master-to-tiles] [--match-tiles-to-master] [--greedy]
             [-v]
             master tile_dir

positional arguments:
  master                Master image path.
  tile_dir              Directory containing the tile images.

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Mosiac output path.
  -c MASTER_CROP_RATIO, --master-crop-ratio MASTER_CROP_RATIO
                        Crop the master image to width/height ratio.
  -s MASTER_SIZE [MASTER_SIZE ...], --master-size MASTER_SIZE [MASTER_SIZE ...]
                        Resize master image to width, height.
  -C TILE_CROP_RATIO, --tile-crop-ratio TILE_CROP_RATIO
                        Crop the tile images to width/height ratio.
  -S TILE_SIZE [TILE_SIZE ...], --tile-size TILE_SIZE [TILE_SIZE ...]
                        Resize tile images to width, height.
  -n N_APPEARANCES, --n-appearances N_APPEARANCES
                        The number of times a tile can appear in the mosaic.
  -b, --black-and-white
                        Convert master and tile images to black and white.
  -g, --show-grid       Show the tile grid, don't build the mosiac.
  -d SUBDIVISIONS [SUBDIVISIONS ...], --subdivisions SUBDIVISIONS [SUBDIVISIONS ...]
                        Grid subdivision thresholds.
  -G, --gpu             Use GPU for distance matrix computation. Requires
                        installing with `pip install 'phomo[cuda]'`.
  -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.
  -e, --equalize        Equalize the colour distributions to cover the full
                        colour space.
  --match-master-to-tiles
                        Match the master image's colour distribution with the
                        tile image colours.
  --match-tiles-to-master
                        Match the tile images' colour distribution with the
                        master image colours.
  --greedy              Use a greedy tile assignment algorithm. Should improve
                        performance at the expense of accuracy.
  -v, --verbose         Verbosity.

🤩 Credit

Release files for phomo 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phomo 1.2.0
File Size Uploaded
phomo-1.2.0.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phomo 1.2.0
File Interpreter ABI Platform
phomo-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.4 kB

Release files / phomo-1.2.0.tar.gz

Download URL phomo-1.2.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bbd01f534dabc189a649bad1543125f731c972fb62c03ac03074b8d63b4b1d73
BLAKE2b-256 checksum
How to use checksums
cf784b57d53ef2973f87ab0759851a1e50415c747d07130ce37e7fd88d1be32a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Linux/6.8.0-1017-azure

Release files / phomo-1.2.0-py3-none-any.whl

Download URL phomo-1.2.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62a366c2fbc7afef8619f3f289e6aa737d5bb4bd689a68ee3b40f8c98967d9e5
BLAKE2b-256 checksum
How to use checksums
3119f1647e97fd46a189504af385e57971cf39d9157082ce7883d0d502ef90a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Linux/6.8.0-1017-azure

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.5.1

2 release files

0.5.0

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page