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.0.tar.gz (32.3 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.0-cp39-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

pixel_convert-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

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

pixel_convert-0.2.0-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.0.tar.gz.

File metadata

  • Download URL: pixel_convert-0.2.0.tar.gz
  • Upload date:
  • Size: 32.3 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.0.tar.gz
Algorithm Hash digest
SHA256 118e9832d3192992c5dbe0b6113277b996f1b57e169bbdb73f29fbc48edb85b8
MD5 136cee8c4e4edcd0c556ef56be36edfc
BLAKE2b-256 d43130e1e802cc67d34027cbc1156cca2d9e979a8d918f20a221a91139801187

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.0.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.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 778c8cad6575d3267cf9a70494b4c0f0448bd9bf02ab035fd96582294dabddae
MD5 cde23d7a7764e64a6ef035df747ca55f
BLAKE2b-256 8e1e6b5a6df852e947e220ce1d544c8b623aa65ea4ac1a6132dc28a029c91475

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.0-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.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5fdbf9ec1bec25cab5e98b8eabea0777f4dca334aaab010ebb698c8e6a9ab6ab
MD5 b999f6dea0d3ac35e970f03f512ddde9
BLAKE2b-256 5ef04e0721b03e0a4e7b6c644bb36bb5c3bb764a4cd6c0d76bdc6a6e54bb3411

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.0-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.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pixel_convert-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e1e99e093dd9903d7e8fb826ed899e0f616c10a990f4cd19710206cd3e9c681
MD5 f9b54e4bb1f0bc622a04dd4dae802439
BLAKE2b-256 ea7a67027d9265c887e14abf0dcdf499578ca2c7c7515a484dad4f780e26fba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixel_convert-0.2.0-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