Image Mosaic Generator using Voronoi Tesellation
This repository implements a method to create image mosaics using Voronoi tessellation proposed by Yoshinori Dobashi and Toshiyuki Haga, Henry Johan, and Tomoyuki Nishita (Eurographics Short Presentations, 2002, DOI: 10.2312/egs.20021036).
You can use it to create mosaics like this:
| Input Image | Voronoi Mosaic |
|---|---|
Installation
To install the package:
pip install .
Or to install it as a standalone command line tool:
uv tool install .
Usage
Once installed, the mosaic can be created with:
voronoi-mosaic example-images/butterfly.jpg --output-path example-images/butterfly-mosaic.jpg
The same command is available as a module entry point:
python -m voronoi_mosaic example-images/butterfly.jpg --output-path example-images/butterfly-mosaic.jpg
The example mosaic shown above was created with the default parameters.
To get help on the parameters:
voronoi-mosaic --help
Parameters
| Option | Default | Description |
|---|---|---|
--init-method |
hex-grid |
How the initial cell centers are placed, either hex-grid or random |
--cellsize |
15 |
Average diameter of a cell in pixels, hex-grid only |
--jitter |
5 |
Width of the random offset applied to the lattice, in pixels, hex-grid only |
--npoints |
1000 |
Number of cells, random only |
--niter |
10 |
Number of optimization steps |
--seed |
0 |
Random seed for reproducibility |
--outline-color |
black |
Any matplotlib color, or none to draw no outlines |
--background-color |
white |
Any matplotlib color, shown in the gaps between the cells |
--pad |
0.0 |
Distance in pixels each cell is shrunk by, which opens up a gap between neighboring cells |
--radius |
0.0 |
Corner radius in pixels used to round the cells |
--output-path |
mosaic.png |
Path to save the output image |
--dpi |
300 |
Resolution used to render the mosaic |
The hex-grid method places the cell centers on a hexagonal lattice with a spacing of cellsize, where each center is displaced by up to half the jitter value.
The random method instead samples npoints centers from the image, with a probability proportional to the brightness.
Each optimization step moves every cell center by at most one pixel, so larger cells need more steps to settle.
For cellsize values much above the default, niter should be increased accordingly.
The pad and radius options turn the sharp cells into rounded pebbles.
Each cell is first shrunk by pad towards its own center, which opens up a gap that shows the background-color, and its corners are then rounded with radius.
Both are given in pixels and are best chosen relative to cellsize, for example a pad of 1.5 and a radius of 4 for the default cellsize of 15.
The rounding is limited to half an edge length, so a large radius turns small cells into ellipses rather than distorting them.
The output image has the same pixel size as the input image, up to rounding, independent of dpi.
Since line widths are given in points, dpi controls how thick the cell outlines appear.
Development
To run the tests:
uv run pytest
Releasing
Publishing a release on GitHub builds the package and uploads it to PyPI.
The release tag has to match the version in pyproject.toml, written as v0.1.0 or 0.1.0, otherwise the workflow stops before the upload.
This requires a one time setup, as the workflow authenticates without a stored token:
- a trusted publisher for this repository on PyPI, with
publish.ymlas the workflow andpypias the environment - an environment named
pypiin the repository settings, which is also the place to require a manual approval before the upload
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file voronoi_mosaic-1.1.0.tar.gz.
File metadata
- Download URL: voronoi_mosaic-1.1.0.tar.gz
- Upload date:
- Size: 928.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1959842e0130ab070b25d0bf109d78c416669d998014c3df4d63d9152e84acfd
|
|
| MD5 |
0a0e93914c45197326a88a6754abefd5
|
|
| BLAKE2b-256 |
75cffbc8aebaedf4bf1fa9da0b5af6fc4142b2eeb77e27116db6056d25986aaa
|
Provenance
The following attestation bundles were made for voronoi_mosaic-1.1.0.tar.gz:
Publisher:
publish.yml on adonath/voronoi-mosaic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
voronoi_mosaic-1.1.0.tar.gz -
Subject digest:
1959842e0130ab070b25d0bf109d78c416669d998014c3df4d63d9152e84acfd - Sigstore transparency entry: 2366816935
- Sigstore integration time:
-
Permalink:
adonath/voronoi-mosaic@b7e4622363b65a9c041800a9757c677ad4286ffb -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/adonath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7e4622363b65a9c041800a9757c677ad4286ffb -
Trigger Event:
release
-
Statement type:
File details
Details for the file voronoi_mosaic-1.1.0-py3-none-any.whl.
File metadata
- Download URL: voronoi_mosaic-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f7fd9bb794a33dc39384295f02fd47f846f792d0d7479fe0489c1e2a2d7324a
|
|
| MD5 |
86751f5390831050e6e605926531b70e
|
|
| BLAKE2b-256 |
11ed1da513366a5a1053da93a5932b0e2b4a217c609e8cc65c03f80d0fece7a6
|
Provenance
The following attestation bundles were made for voronoi_mosaic-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on adonath/voronoi-mosaic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
voronoi_mosaic-1.1.0-py3-none-any.whl -
Subject digest:
6f7fd9bb794a33dc39384295f02fd47f846f792d0d7479fe0489c1e2a2d7324a - Sigstore transparency entry: 2366816993
- Sigstore integration time:
-
Permalink:
adonath/voronoi-mosaic@b7e4622363b65a9c041800a9757c677ad4286ffb -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/adonath
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b7e4622363b65a9c041800a9757c677ad4286ffb -
Trigger Event:
release
-
Statement type: