Skip to main content

Bridge labeled pixel masks and compact Bezier-style polygon curves

Project description

pixcurve

High-performance C++ conversion from labeled pixel masks to compact Bezier-style polygons.

Input is a single-channel uint8 label mask where background is 0. Output is JSON-compatible polygons keyed by label value.

Install

python -m pip install pixcurve

For local development from source:

python -m pip install -e .

If a prebuilt wheel is not available for your platform, installation from source requires:

  • CMake
  • a C++20 compiler
  • OpenCV development libraries available to CMake

Python API

import numpy as np
from PIL import Image

from pixcurve import mask_to_bezier

mask = np.asarray(Image.open("mask.png").convert("L"), dtype=np.uint8)
polygons = mask_to_bezier(mask)

Output shape:

{"11":[[[x,y],[x,y]]],"16":[[[x,y],[x,y]]]}

CLI

pixcurve path/to/mask.png > polygons.json

Example

python examples/convert_mask.py path/to/mask.png > polygons.json

Native C++ Binary

cmake -S src_cpp -B src_cpp/build -DCMAKE_BUILD_TYPE=Release
cmake --build src_cpp/build -j
./src_cpp/build/mask_to_bezier_cpp path/to/mask.png

Tests

python -m unittest discover -s tests
cmake -S src_cpp -B src_cpp/build -DCMAKE_BUILD_TYPE=Release
cmake --build src_cpp/build -j
ctest --test-dir src_cpp/build --output-on-failure

Publishing checklist

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*

Then upload to TestPyPI first:

python -m twine upload --repository testpypi dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixcurve-0.1.0.tar.gz (16.7 kB view details)

Uploaded Source

File details

Details for the file pixcurve-0.1.0.tar.gz.

File metadata

  • Download URL: pixcurve-0.1.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for pixcurve-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec5800e81c6e8b80fc3a442e13b6efb45f03021f0d936295adcc33c1f31633cb
MD5 6479bf53b1cc8a8700f4db0903b9e550
BLAKE2b-256 d469a7b02252c1a4eaf77142cbf47a33ba8c830181e893824a475f91383afac1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page