Skip to main content

PyO3-powered image transform for Pixel-convert (Rust core)

Project description

pixel_convert (Python package)

This package exposes a Python API backed by the Rust pixel_convert_rust core via PyO3.

API

  • pixel_convert.transform(image: PIL.Image.Image, width: int, height: int, kmax: int, *, fast=False, stride=None, stride_x=None, stride_y=None, alpha=None, epsilon_palette=None, t_final=None, stag_eps=None, stag_limit=None, threads=None, iter_timings=False) -> PIL.Image.Image
  • pixel_convert.transform_file(input_path: str, output_path: str, width: int, height: int, kmax: int, *, fast=False, stride=None, stride_x=None, stride_y=None, alpha=None, epsilon_palette=None, t_final=None, stag_eps=None, stag_limit=None, threads=None, iter_timings=False) -> None
  • pixel_convert.map_to_colors_image(image: PIL.Image.Image, colors: list[tuple[int,int,int]], algorithm: str = "rgb") -> PIL.Image.Image
  • pixel_convert.map_to_colors_file(input_path: str, output_path: str, colors: list[tuple[int,int,int]], algorithm: str = "rgb") -> None
  • pixel_convert.map_to_named_palette_image(image: PIL.Image.Image, palette_name: str, algorithm: str = "rgb") -> PIL.Image.Image
  • pixel_convert.map_to_named_palette_file(input_path: str, output_path: str, palette_name: str, algorithm: str = "rgb") -> None

Color mapping algorithms

  • "rgb" / "rgb_euclidean": Euclidean distance in RGB.
  • "lab" / "deltae76" / "lab_euclidean": Euclidean distance in CIE Lab (D65).
  • "ciede2000" / "de2000" / "deltae2000" / "de00": CIEDE2000 perceptual distance.

Build from source

  • pip install maturin
  • maturin build -m pixel_convert/Cargo.toml --release
  • pip install target/wheels/*.whl

Develop install for local testing

  • maturin develop -m pixel_convert/Cargo.toml

Example

from PIL import Image
import pixel_convert as rx

img = Image.open("examples/input_images/dog3.jpg")
out = rx.transform(img, 128, 128, 30, fast=True)
out.save("examples/output_images/dog3_py_128x128_30.png")

Palette mapping (PIL image)

from PIL import Image
import pixel_convert as rx

img = Image.open("examples/input_images/dog3.jpg")
palette = [(0,0,0), (255,255,255), (220,20,60)]
for algo in ["rgb", "lab", "ciede2000"]:
    out = rx.map_to_colors_image(img, palette, algorithm=algo)
    out.save(f"examples/output_images/dog3_map_{algo}.png")

Palette mapping with named palette (DMC)

from PIL import Image
import pixel_convert as rx

img = Image.open("examples/input_images/dog3.jpg")
for algo in ["rgb", "lab", "ciede2000"]:
    out = rx.map_to_named_palette_image(img, "dmc", algorithm=algo)
    out.save(f"examples/output_images/dog3_map_dmc_{algo}.png")

File-to-file example (faster, Rust handles I/O)

import pixel_convert as rx

rx.transform_file(
    "examples/input_images/dog3.jpg",
    "examples/output_images/dog3_py_128x128_30.png",
    128,
    128,
    30,
    fast=True,
    threads=4,
)

Palette mapping (file-to-file)

import pixel_convert as rx
palette = [(0,0,0), (255,255,255), (220,20,60)]
rx.map_to_colors_file(
    "examples/input_images/dog3.jpg",
    "examples/output_images/dog3_map_ciede.png",
    palette,
    algorithm="ciede2000",
)

Palette mapping (file-to-file) with named palette

import pixel_convert as rx
rx.map_to_named_palette_file(
    "examples/input_images/dog3.jpg",
    "examples/output_images/dog3_map_dmc_lab.png",
    "dmc",
    algorithm="lab",
)

Timing per iteration (logs)

import pixel_convert as rx, os
os.environ["RUST_LOG"] = "info"
rx.transform_file("examples/input_images/dog3.jpg", "examples/output_images/dog3_py_128x128_30.png", 128, 128, 30, iter_timings=True)

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

pixel_convert-0.2.3.tar.gz (51.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pixel_convert-0.2.3-cp39-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

pixel_convert-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

pixel_convert-0.2.3-cp39-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file pixel_convert-0.2.3.tar.gz.

File metadata

  • Download URL: pixel_convert-0.2.3.tar.gz
  • Upload date:
  • Size: 51.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pixel_convert-0.2.3.tar.gz
Algorithm Hash digest
SHA256 19fb7a26dc071b542dbeff74925c21afcbba3c699455cec822e3ed2783a436aa
MD5 8425ae70e2f2ea0cf65200275cf130d2
BLAKE2b-256 22e02bde3b79c9b0576075b5b37c8c785f46415a541c0b8367f45cd452bcd06e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.3.tar.gz:

Publisher: wheels.yml on QAM/pixel-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixel_convert-0.2.3-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 75c3fe47b18ecc21ab2cbb1198c039709ef08f09a32282b555c111c9be12cc41
MD5 a39cf50036fe6d6d4bbeea2adcde9d6f
BLAKE2b-256 f7889106da9c25ba843214513c2d1504e2bbb3971ae0cb70819653f24c8b4380

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.3-cp39-abi3-win_amd64.whl:

Publisher: wheels.yml on QAM/pixel-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixel_convert-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0be12be11b598102efe4cecd161f8bd87ec85ea9fe4379d81753ae3ca8e8b1a6
MD5 73d72eb988f802d45fc70e93b2017fd4
BLAKE2b-256 b41f42bfafbda0b5903fedfd30ce54a1f7bcd9089142e05360ca8761d7839db7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on QAM/pixel-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixel_convert-0.2.3-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 796f3eafddbc4b31c734fb1b697ac2096d427099b9106874b9beccd8a73188e7
MD5 bda692fb411287faeab35b754d5d0033
BLAKE2b-256 08680ebd3fe230a489bfd76da5dcb404e15a88f6e97b6d4f8284f33e38bb37d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.3-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on QAM/pixel-convert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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