Skip to main content

Image Mosaic Generator using Voronoi Tesellation

CI

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
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.yml as the workflow and pypi as the environment
  • an environment named pypi in the repository settings, which is also the place to require a manual approval before the upload

Metadata

Release files for voronoi-mosaic 1.1.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 voronoi-mosaic 1.1.0
File Size Uploaded Provenance Actions
voronoi_mosaic-1.1.0.tar.gz 928.0 kB With provenance Details for voronoi_mosaic-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for voronoi-mosaic 1.1.0
File Interpreter ABI Platform Actions
voronoi_mosaic-1.1.0-py3-none-any.whl Python 3 none any Details for voronoi_mosaic-1.1.0-py3-none-any.whl

Total release size: 935.2 kB

Release files / voronoi_mosaic-1.1.0.tar.gz

Download URL voronoi_mosaic-1.1.0.tar.gz
Size 928.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1959842e0130ab070b25d0bf109d78c416669d998014c3df4d63d9152e84acfd
BLAKE2b-256 checksum
How to use checksums
75cffbc8aebaedf4bf1fa9da0b5af6fc4142b2eeb77e27116db6056d25986aaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / voronoi_mosaic-1.1.0-py3-none-any.whl

Download URL voronoi_mosaic-1.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f7fd9bb794a33dc39384295f02fd47f846f792d0d7479fe0489c1e2a2d7324a
BLAKE2b-256 checksum
How to use checksums
11ed1da513366a5a1053da93a5932b0e2b4a217c609e8cc65c03f80d0fece7a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Security for voronoi-mosaic 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for voronoi_mosaic-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

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