Skip to main content

pixelmap-python

PyPI Python versions License: MIT

Dense image correspondence: given two photographs of the same scene, work out where each pixel of the first one went in the second.

Python bindings for the pixelmap Rust crate, the reference implementation of the PIXELMAP framework (white paper). Every cell of an affine correspondence grid acts as an autonomous agent holding its own local affine transform; agents refine their transform against the image data and propagate what they find to their neighbours, and a forward/backward consistency check culls the ones that disagree. Repeating that coarse-to-fine yields a dense, geometrically consistent mapping.

Useful for optical flow, image registration and stitching, stereo matching, morphing, and as the front half of a 3D reconstruction.

PIXELMAP applied to two photos of a monkey statue

Install

pip install pixelmap-python

The package installs as pixelmap-python but imports as pixelmap — PyPI will not accept pixelmap as a distribution name, because it collides with the unrelated pixel-map project under PyPI's similarity rule.

Wheels are published for Linux (x86-64, aarch64, musl), macOS (Apple silicon and Intel) and Windows (x86-64), for CPython 3.9 and newer. NumPy is the only runtime dependency; no Rust toolchain is needed unless you build from source.

Quick start

import numpy as np
import pixelmap
from PIL import Image

a = np.asarray(Image.open("a.jpg").convert("RGB"))
b = np.asarray(Image.open("b.jpg").convert("RGB"))  # same dimensions as a

mapping = pixelmap.correspond(a, b, quality="low")

flow = mapping.flow()  # (H, W, 2) float32: how far each pixel moved
print(f"{mapping.coverage:.1%} of the image was mapped")

# Where did the pixel at (120, 84) end up?
print(mapping.lookup(120.0, 84.0))  # (114.2, 80.6), or None if unmapped

flow[y, x] is (dx, dy) in the source photos' own pixel coordinates. Regions the algorithm could not map — occlusions, featureless sky, anything the consistency check rejected — are NaN rather than a plausible-looking coordinate:

unmapped = np.isnan(flow[..., 0])

Coverage well below 1.0 is normal and not a failure. A very low value means the two photos had little in common, or are related by something an affine grid cannot express.

Warping one photo onto the other

flow(absolute=True) returns destination coordinates instead of displacements, which is what OpenCV's remap wants:

import cv2

dst = mapping.flow(absolute=True)
warped = cv2.remap(a, dst[..., 0], dst[..., 1], cv2.INTER_LINEAR)

There is also a built-in morph, which interpolates the first photo t of the way towards the second:

halfway = mapping.morph(0.5, detail=2)  # (h, w, 4) uint8, at working resolution

Watching a long run

mapping = pixelmap.correspond(
    a,
    b,
    quality=pixelmap.Quality.HIGH,
    progress=lambda step, total: print(f"{step}/{total}"),
)

The GIL is released while the solver runs, so correspond can be called from a worker thread without blocking the rest of your program.

API

correspond(photo1, photo2, *, quality, seed, max_round_trip_error, progress) Run the pipeline.
Correspondence.flow(*, backward=False, absolute=False) The dense field as (H, W, 2) float32.
Correspondence.lookup(x, y, *, backward=False) One point, or NumPy arrays of them.
Correspondence.morph(t, *, detail=1) The first photo warped towards the second.
Correspondence.coverage Fraction of the image that got a mapping.
Correspondence.comparisons Region comparisons performed.
Correspondence.source_dimensions / .working_dimensions / .working_scale Geometry.
Correspondence.to_bytes() / .from_bytes(data, photo1, photo2) Save and reload a mapping.
Quality.LOW / .MEDIUM / .HIGH Presets, or the equivalent strings.

Input. Photos are uint8 arrays of shape (H, W), (H, W, 1), (H, W, 3) or (H, W, 4) — Pillow images work directly. Both must have the same dimensions and be at least 32 pixels on each side. Violations raise SizeMismatchError, PhotoTooSmallError or ValueError, all of which are ValueError subclasses.

Quality. LOW, MEDIUM and HIGH run 4, 10 and 13 refinement steps and finish at a working width of 400, 800 and 1600 pixels respectively, so cost grows faster than the step count suggests. flow and lookup answer in your photos' coordinates regardless; use working_scale if you need to reason about the solver's effective resolution.

Determinism. The same photos, quality and seed give the same mapping — run to run, thread to thread, and machine to machine. Pass seed= to vary it.

Building from source

Requires Rust 1.83 or newer.

git clone https://github.com/d4per/pixelmap-python
cd pixelmap-python
pip install maturin
maturin develop --release
pytest

maturin develop without --release builds an unoptimised solver that is many times slower; use it only for iterating on the bindings themselves.

See also

License

MIT — see LICENSE.

Release files for pixelmap-python 0.2.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 pixelmap-python 0.2.0
File Size Uploaded
pixelmap_python-0.2.0.tar.gz 26.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pixelmap-python 0.2.0
File
pixelmap_python-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pixelmap_python-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
pixelmap_python-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
pixelmap_python-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.3 MB

Release files / pixelmap_python-0.2.0.tar.gz

Download URL pixelmap_python-0.2.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
910fd41e14947201419c432ef603f12202558b743dd78daee1515591a2bc86ef
BLAKE2b-256 checksum
How to use checksums
122d52329f50c3adec44c094f88a184bc328b538f5bb7c06b92db113997fee35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-win_amd64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-win_amd64.whl
Size 253.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6184e18372afc804a7c1ea864b7d8441bdd78a0d7efab2f3ce389e8d81f92e39
BLAKE2b-256 checksum
How to use checksums
a0830d685f9a8543c981362c29b49720f90277cec2076fffa1ea5bd37cb4486d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 586.8 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
31a0d713b9dfc9bc7bd2d16035c3d2e5b86b594d0372cae5c249604efa5ab20c
BLAKE2b-256 checksum
How to use checksums
ea1512f0887faf3647ecf3a5d447ebc6997e38cc2ffd8125de71a386bbfa5bbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 375.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
df4f11b3bf809781d9d851ac0576ab0d67ff6101a44eae02fb58bcccf316d379
BLAKE2b-256 checksum
How to use checksums
b5afd8efe66ffc561a127cac94cb3621b7d1e4b0bec612bf8bd8842e8ef12380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 369.3 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a2926283a39f48dcfd239c59b9c91447441b18c2faa63526159f43583d5d9b6d
BLAKE2b-256 checksum
How to use checksums
d0c44cdcc086176e918892f97990c3ef656b98a85b7b65995201d0af63fafda2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 334.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a2e707a98c6463bfe552b48b41d899b4d4d715e4ec3712d81d05c2810ef2b5fd
BLAKE2b-256 checksum
How to use checksums
6dacff85d5c2f7ea6d6b4c84c99451631c172afd737adbd749998817ddde4af4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release files / pixelmap_python-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL pixelmap_python-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 345.4 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
85a3a1640067dbd4046a7c85f98078d162c4389b7a4ff12a11339b6cb35df7c0
BLAKE2b-256 checksum
How to use checksums
045e264a142fd9422ebca502d7dfca7ccb75a0cc51a6d865caf6e56bab26f6e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

7 release files

This release

0.2.0 This release

7 release files

0.1.0

7 release files

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