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.

To stop a run early, raise from the callback: the solver stops at the end of that step and your exception comes out of correspond. Ctrl-C stops it the same way, callback or not.

API

correspond(photo1, photo2, *, quality, seed, max_round_trip_error, fill_mode, neighborhood_radius, init_neighborhood_radius, 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 / .ULTRA 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, HIGH and ULTRA run 4, 10, 13 and 15 refinement steps and finish at a working width of 400, 800, 1600 and 3200 pixels respectively, so cost grows faster than the step count suggests. Above LOW, no step works wider than your photos, so ULTRA is the same as HIGH on photos up to 1600 pixels wide. Those presets also fill the cells the final step left unmapped from earlier, coarser steps: more pixels get an answer, but the filled ones are less precise than the rest. flow and lookup answer in your photos' coordinates regardless; use working_scale if you need to reason about the solver's effective resolution.

Neighbourhood radius. neighborhood_radius sets the radius of the disc the solver compares the photos over, in working pixels; init_neighborhood_radius sets it for the initial solve alone, the one that grows the mapping out from the feature matches. Both default to 5 and accept 1 to MAX_NEIGHBORHOOD_RADIUS (51). A larger disc matches weakly textured or strongly warped regions more reliably, but blurs the mapping across motion and depth edges, and the time grows with its area. init_neighborhood_radius=9 is the cheap gain: on HPatches it mapped 76% of pixels within 3 px of the truth instead of 73%, for 20–30% more time. neighborhood_radius=9 roughly doubles the time.

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.

Metadata

Release files for pixelmap-python 0.4.1

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.4.1
File Size Uploaded Provenance Actions
pixelmap_python-0.4.1.tar.gz 28.9 kB With provenance Details for pixelmap_python-0.4.1.tar.gz

Built distributions (wheels)

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

Total release size: 2.6 MB

Release files / pixelmap_python-0.4.1.tar.gz

Download URL pixelmap_python-0.4.1.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4dbc7f4b6643706cdd47f7408360cfbce1b1503f816d3dab72e3d4a36251ff21
BLAKE2b-256 checksum
How to use checksums
edba499c6ef6bb340adc2999c8a1bdc0f0991497aeab86ced5f781e410d9e40b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-win_amd64.whl
Size 310.9 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
cf1dd907f63ec74c1e3b8a6878613a8881b2dbff6ef158ecbda3d03273ecfbfa
BLAKE2b-256 checksum
How to use checksums
f5f05bba4c92de3ce3ed7ec5c10fa8b29f6cc59a90043cdc68bee6eb1e4ea932
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-musllinux_1_2_x86_64.whl
Size 636.2 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
9a668c46efa6dcf1e8b1c98e201106cd196fcfa58fd6fac5f882c2d71e4b0330
BLAKE2b-256 checksum
How to use checksums
9c6d69cb4dfd2bbcb6f5c284050b57322a9477553ae685f8ccb4cbde2372c0cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 425.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
761573ca1820b397185bc76f40487aff58d87774118e40507d4629a4be5ff54a
BLAKE2b-256 checksum
How to use checksums
6dd66eddd564ab033506e8132b633cd682da2dc1fc02a0b7fb04f66bc8ccc11e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 416.9 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
72b73ece9adab301faf332862711131797f7877ae2320cee090376ad94ccf440
BLAKE2b-256 checksum
How to use checksums
3f2a415aa0d011679e688a6fbcb14c228532bfb3c151620a15bfec7aa9bf45f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-macosx_11_0_arm64.whl
Size 381.3 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cdeb5df64f6d415dc10647feb76070b3d3736157b73b12d613db3448c116ec77
BLAKE2b-256 checksum
How to use checksums
3d85959510fc09cae123e52a55e9b72f4090bc8393f57723646329bf5abbc5f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

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

Download URL pixelmap_python-0.4.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 391.8 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
38fedda1050e92f79a53fffc81aa3ef4e4cb6c6b87eefae4a4f0d7e83073fc81
BLAKE2b-256 checksum
How to use checksums
fd912eee48bf518475491e4cb005fb7cd75f4eb65e71ee05cfe0d8d5053e9602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for pixelmap-python 0.4.1

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

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for pixelmap_python-0.4.1.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 Nov 22, 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.

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