Skip to main content

Strokemap - Paint by Numbers Generator

A Python package and CLI tool to convert any image into a high-quality, print-ready "Paint by Numbers" PDF template.

The generated PDF matches premium standards, split into four cleanly laid-out pages:

  1. Page 1 - Numbered Template: Light gray outlines with a small, centered index number in each region.
  2. Page 2 - Clean Outlines: Clean black outlines without any numbers, perfect for clean canvas painting.
  3. Page 3 - Colorized Preview: A color reference picture showing what the finished painting should look like.
  4. Page 4 - Color Palette Sheet: A beautifully aligned grid of color swatches showing index numbers, hex codes, paint color blocks, and step-by-step instructions.

Preview

Here is an example of the generator's output using the standard Lenna test image:

Original Image Numbered Template (Page 1) Clean Outlines (Page 2) Colorized Preview (Page 3)
Original Lenna Numbered Template Clean Outlines Colorized Preview

Installation

Create a virtual environment and install the package locally:

python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Dependencies

The package relies on the following standard python packages:

  • numpy
  • pillow
  • opencv-python
  • scikit-learn
  • reportlab
  • scikit-image

Usage

Command Line Interface

You can convert any image directly from your terminal:

strokemap input.jpg output.pdf --colors 20 --difficulty medium

CLI Options:

  • image_path (required): Path to the input image file.
  • output_pdf (required): Path where the final PDF should be saved.
  • -c, --colors (optional): Target number of colors (default: 20).
  • -d, --difficulty (optional): Level of region detail (easy, medium, hard) (default: medium).

Python API

You can also use the package programmatically:

from strokemap import PaintByNumbersGenerator, generate_pdf

# 1. Initialize generator with difficulty settings
generator = PaintByNumbersGenerator(difficulty="medium")

# 2. Process image to get templates and palette
numbered_img, clean_img, colorized_img, palette = generator.process("input.jpg", n_colors=20)

# 3. Compile everything into a 4-page A4 PDF
generate_pdf(
    output_pdf_path="output.pdf",
    numbered_img=numbered_img,
    clean_img=clean_img,
    colorized_img=colorized_img,
    palette=palette,
)

Algorithms Used

  1. Superpixel Segmentation (SLIC): Uses the Simple Linear Iterative Clustering (SLIC) algorithm to cluster pixels into contiguous, edge-conforming "superpixels". This ensures that the boundaries of regions natively stick to the actual physical boundaries and details in the image (such as eyes, text, and fine lines).
  2. Color Quantization: Performs K-Means clustering on the average colors of the superpixels in the CIELAB color space. Working in CIELAB space allows color distances to match human perception, resulting in a vibrant and accurate palette.
  3. Detail Reduction & Region Merging: Small, hard-to-paint micro-regions are intelligently merged into their dominant neighbor using connected components analysis, with thresholds dynamically adjusted by the selected difficulty level.
  4. Outline Extraction: Computes a pixel-wise transition grid to produce clean, single-pixel outlines.
  5. Optimal Label Placement: Uses a distance transform (cv2.distanceTransform) to find the center of the largest inscribed circle within each region, placing number labels at the most readable point.

Authors

  • Developer

For additional author and maintainer details, see AUTHORS.md.

Contributors

This project is maintained by the community. See CONTRIBUTORS.md for the current list of contributors and how to get involved.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md before opening an issue or pull request.

Security

If you discover a vulnerability, please do not publish it publicly. Refer to SECURITY.md for our security reporting policy.

Metadata

Release files for strokemap 0.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 strokemap 0.1.0
File Size Uploaded Provenance Actions
strokemap-0.1.0.tar.gz 14.6 kB With provenance Details for strokemap-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 27.2 kB

Release files / strokemap-0.1.0.tar.gz

Download URL strokemap-0.1.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bbac2ff5454df3dd30ee46f08bf7ed2b7b603384f1ea6ed3c750e433430b1bba
BLAKE2b-256 checksum
How to use checksums
c10c731d7bd69c2b5381692f9e938ed9bd822b33ee480a8841ec7d83a6221bec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Release files / strokemap-0.1.0-py3-none-any.whl

Download URL strokemap-0.1.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cf9e16cfc17f2c743abd5ab764b3758eafbbb41b8a1431e6e8643cab2b97014
BLAKE2b-256 checksum
How to use checksums
3e0ca020d03b201385e812d0ea017c7c4c490dc07b8af7fd996fc9e6be5b9241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 24, 2026.

Transparency log

Security for strokemap 0.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 strokemap-0.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 May 24, 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

0.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