Duotonics
Duotonics is a Python application for reproducible two-color imaging. It blends random or explicit color pairs over a source image's tonal key in gamma-encoded sRGB (legacy), linear sRGB, or Oklab (Ottosson, 2020). It accepts JPEG, PNG, and BMP input and writes a batch of lossless PNGs (100 by default) plus colors.csv and metrics.csv sidecars. The application is usable through file dialogs, a command-line interface, or as a Python library.
Features
- Image selection via a file dialog
- Generates 100 duotone variations as lossless PNG files (count configurable)
- Filenames use hex color codes in RGB order (e.g.
083_2CD2B4_DC1E5A.png), ready to paste into Figma, Illustrator, or your design system - Duotone, tritone, and quadtone output: two to four anchor colors interpolated over equally spaced tonal positions (tritone filenames add a third hex group, e.g.
000_000000_808080_FFFFFF.png) - Produces a
colors.csvsidecar listing every variation's anchor colors and tone curve for easy reference and sharing - Produces a
metrics.csvsidecar reporting mean, median, and 95th-percentile CIEDE2000 (Sharma, Wu & Dalal, 2005) for every variation against its Oklab-rendered perceptual reference - Tone curves (
linear,gamma,sigmoid,spline) that reshape how source tones move through the duotone (--curve) - Command-line mode with reproducible batches (
--seed), configurable variation count (--count), explicit color groups of two to four colors (--colors), blend space (--space srgb|linear|oklab), and tone curve (--curve) - Uses OpenCV for efficient image processing
Example batch
One source photograph, 100 duotone variations generated with --count 100 --seed 42 --space oklab:
Source: NASA's photograph of astronaut Eileen Collins, public domain, from the scikit-image astronaut dataset.
Installation
Duotonics requires Python 3.9 or higher. Install it from PyPI:
python -m pip install duotonics
Or install from a source checkout:
git clone https://github.com/MichailSemoglou/duotonics.git
cd duotonics
python -m pip install .
Either way, this installs the duotonics command and the duotone_generator Python module.
Usage
Interactive mode
Run the command without arguments:
duotonics
Direct script execution remains available from a source checkout:
python3 duotone_generator.py
-
A file dialog will open. Select the image you want to process, then choose an output directory.
-
The script will generate 100 duotone variations in a new folder named
[original_filename]_duotone_variations. Each variation is a lossless PNG file named after its hex color values (e.g.083_2CD2B4_DC1E5A.png). Acolors.csvfile is also written to the same folder, listing every variation's anchor colors and tone curve. -
A message box will appear when the process is complete, indicating the location of the output folder.
Command-line mode
Pass the image path as an argument to run without any dialogs, suitable for scripting and headless environments:
duotonics path/to/image.png [--output-dir DIR] [--count N] [--seed S] [--colors "HEX1,HEX2[,HEX3[,HEX4]]"] [--space {srgb,linear,oklab}] [--curve {linear,gamma,sigmoid,spline}]
-o, --output-dir DIR: place the output folder under DIR instead of alongside the source image.--count N: number of random variations (default: 100).--seed S: reproduce a batch exactly by reusing its seed.--colors "#2CD2B4,#DC1E5A": apply explicit color specifications instead of random ones; each holds two to four colors in tonal order (a tritone example:--colors "#000000,#808080,#FFFFFF"). Repeatable; one variation per specification. Cannot be combined with--countor--seed.--space {srgb,linear,oklab}: where the blend runs.srgb(default) is the legacy gamma-space blend.linearblends linear light (IEC 61966-2-1; Poynton, 2003) andoklabblends in Oklab (Ottosson, 2020); both derive the key from ITU-R BT.709 relative luminance instead of grayscale luma.--curve {linear,gamma,sigmoid,spline}: tone curve applied to the normalized tonal key before blending (default:linear, the identity). The selected curve is recorded in thecurvecolumn ofcolors.csv.
The location of the output folder is printed on completion.
Tone curves
A tone curve remaps the source's normalized tonal key before the two colors are blended, so it controls which source tones land near the shadow color, the midpoint, and the highlight color. Every curve is a closed, named family with fixed parameters, keeps exact black and white endpoints, and serializes by name alone, so a recorded curve value always reproduces the same mapping.
linear: the identity ramp. Source tones pass through unchanged; this is the default and matches earlier releases byte for byte.gamma(x^2.2, the classic display gamma of Poynton, 2003): darkens midtones toward the shadow color, so highlights stay clean while shadows gain depth.sigmoid(a renormalized logistic S-curve): steepest at the midpoint, so it raises midtone contrast while compressing both ends, protecting clipped highlights and crushed shadows.spline(the cubic smoothstep3x^2 - 2x^3of Perlin, 1985): a gentle S-curve with zero slope at both endpoints; it adds contrast around the midpoint without moving pure black or white.
Curves compose with any blend space and are independent of the color pair: duotonics photo.png --space oklab --curve sigmoid --seed 42 blends in Oklab over a sigmoid-remapped key.
Tritone and quadtone
With three or four anchor colors, the anchors sit at equally spaced tonal positions in [0, 1] (for a tritone, 0, 0.5, and 1) and each channel is interpolated with np.interp in the selected blend space, so the endpoints stay exact and the middle anchor lands exactly on a mid-key. Tone curves apply to the key first and compose unchanged with any anchor count: duotonics photo.png --colors "#000000,#808080,#FFFFFF" --curve gamma. In colors.csv and metrics.csv, the color_3_hex and color_4_hex columns appear only when a batch uses three or four anchors; pure two-color batches keep their two color columns and, on the default linear curve, byte-identical output (the only schema addition is the new curve column), and sidecars written by earlier releases remain readable.
Example batches of 100 tritone and quadtone variations (seed 42, --space oklab, same astronaut source as the example batch above):
Library use
The module can be imported and used as a library, without tkinter installed:
from duotone_generator import convert_to_duotone
folder, records = convert_to_duotone("photo.png", count=25, seed=42, space="oklab", curve="sigmoid")
It returns the output folder path and a list of [index, color_1_hex, ..., color_N_hex] records (two to four hex colors per variation), one per record. Each batch also writes metrics.csv, whose rows report the mean, median, and 95th-percentile CIEDE2000 (Sharma, Wu & Dalal, 2005) between that variation and its perceptual reference, defined as the same anchors blended in Oklab over the same key. See the convert_to_duotone docstring for all parameters, including colors, space, and curve.
Dependencies
- OpenCV (cv2)
- NumPy
- Tkinter (usually comes pre-installed with Python; only needed for interactive mode)
Requirements
- Python 3.9 or higher
Development
Install the package in editable mode with its development dependencies, then run the test suite with coverage:
python -m pip install -e . -r requirements-dev.txt
pytest --cov --cov-report=term-missing
Build and check the wheel and source distribution with:
python -m build
python -m twine check dist/*
Community
License
MIT. See the LICENSE file for details.
Metadata
Release files for duotonics 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| duotonics-1.1.0.tar.gz | 24.9 kB | With provenance | Details for duotonics-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| duotonics-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for duotonics-1.1.0-py3-none-any.whl |
Total release size: 46.8 kB
Release files / duotonics-1.1.0.tar.gz
| Download URL | duotonics-1.1.0.tar.gz |
|---|---|
| Size | 24.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b2384bb3ed25c04a3de2bd239eda741f99a4e78e9c3a84b723e76849ac87774
|
|
BLAKE2b-256 checksum How to use checksums |
1a82527842e381deb9815b655cf1a164eb580966123fe4950207cefa638cc61c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / duotonics-1.1.0-py3-none-any.whl
| Download URL | duotonics-1.1.0-py3-none-any.whl |
|---|---|
| Size | 21.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6419415687451a323376db3102567491cddc1414eb9e17b97aced869b04290da
|
|
BLAKE2b-256 checksum How to use checksums |
96bb0b01f41bc6bdaa82596922c39f8b4b1d0b62f84bceecc71ee0a95533cf92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logSecurity for duotonics 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.
Attestation for duotonics-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 Nov 30, 2026.
Transparency logA 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.