This release is a pre-release and may not be stable for production use.
PatchMatch based Inpainting
This library implements the PatchMatch based inpainting algorithm. It provides both C++ and Python interfaces. This implementation is heavily based on the implementation by Younesse ANDAM: younesse-cv/PatchMatch, with some bug fixes, and updates.
Installation
pip install PyPatchMatch
Wheels for Linux (glibc, x86_64 and aarch64), macOS 11+ (arm64 and x86_64) and Windows
(x64) ship the compiled library with a statically linked OpenCV, so no compiler or
OpenCV installation is needed. On other platforms, e.g. Alpine Linux or Windows on ARM,
pip builds from the source distribution, which requires a C++17 compiler, CMake and the
OpenCV development files (e.g. apt install libopencv-dev or brew install opencv).
If that build fails, PyPatchMatch is installed without the native library instead of
blocking the installation: patchmatch.patchmatch_available is False and the
inpainting functions raise RuntimeError. After installing the missing tools, reinstall
it without the cached build:
pip install --force-reinstall --no-deps --no-cache-dir PyPatchMatch
Usage
Python (see examples/py_example.py):
import patchmatch
image = ... # HxWx3 uint8 numpy array or PIL image
mask = ... # HxW uint8 or bool numpy array or PIL image, non-zero marks the holes
result = patchmatch.inpaint(image, mask, patch_size=3)
The mask must have the same height and width as the image. If mask is omitted, all
pure white pixels are treated as holes. Only the holes are filled; all other pixels keep
their values. Holes need hard edges: an anti-aliased brush leaves light pixels along
the edge of its strokes that are not pure white, so they count as known and the fill
continues them. Paint without anti-aliasing or pass a mask that covers those pixels as
well. The optional keyword argument global_mask, in the same format, marks
pixels that are neither filled nor used as a source; they keep their values as well, and
their colors have no influence on the fill (see
examples/py_example_global_mask.py).
patchmatch.patchmatch_available tells whether the native library could be loaded.
The previous import path from patchmatch import patch_match keeps working.
patch_size is the radius of the compared patches, which span 2 * patch_size + 1
pixels in each direction. Larger patches follow larger structures but are much slower;
the default of 15 compares 31x31 patches, the examples use 3.
patchmatch.set_random_seed(seed) sets the seed of the randomized search and
patchmatch.set_verbose(True) prints the progress of the native code to stderr.
patchmatch.inpaint_regularity(image, mask, ijmap) additionally guides the search with
a regularity map, an HxWx3 float32 array with the regularity coordinates of each pixel
in its first two channels. Its guide_weight must be at least 0.
C++ (see examples/cpp_example.cpp, build and run it with examples/cpp_example_run.sh):
#include "inpaint.h"
int main() {
cv::Mat image = ...;
cv::Mat mask = ...;
auto metric = PatchSSDDistanceMetric(5);
cv::Mat result = Inpainting(image, mask, &metric).run();
}
The library is built with CMake; PATCHMATCH_BUILD_EXAMPLES builds the example.
Development
The project is managed with uv:
uv sync # create .venv, build the library, install dev deps
uv run pre-commit install # enable ruff and the other hooks on commit
uv run pytest # run the test suite
uv run pytest -m "not e2e" # only the fast unit tests
uv run python scripts/evaluate_inpainting.py # measure the fill quality
The evaluation cuts holes into the images of examples/images, compares the fills with
the original content and writes examples/images/evaluation.html, which shows them side
by side. --baseline evaluates another build of the library as well, e.g. of the main
branch; the docstring of the script explains the columns.
Pull requests that change the C++ code get this comparison with their base commit in the
summary of the workflow "Fill quality", and the HTML report as its artifact.
Releases are published to PyPI by creating a GitHub release; the version is taken from
its tag (e.g. v2.0.0). Every released wheel and sdist carries a build provenance
attestation: gh attestation verify <file> -R mauwii/PyPatchMatch.
License
PyPatchMatch is released under the
MIT License. The wheels
contain a statically linked build of OpenCV core (Apache-2.0) and its bundled
third-party code; their licenses are included in the licenses/opencv directory of the
wheel's .dist-info, and a CycloneDX SBOM of OpenCV (PEP 770) in
sboms/opencv.cdx.json, so that vulnerability scanners can find it.
README and COPYRIGHT by Younesse ANDAM
@Author: Younesse ANDAM
@Contact: younesse.andam@gmail.com
Description:
This project is a personal implementation of an algorithm called PATCHMATCH that restores missing areas in an image. The algorithm is presented in the following paper PatchMatch A Randomized Correspondence Algorithm for Structural Image Editing by C.Barnes, E.Shechtman, A.Finkelstein and Dan B.Goldman ACM Transactions on Graphics (Proc. SIGGRAPH), vol.28, aug-2009
For more information please refer to https://gfx.cs.princeton.edu/pubs/Barnes_2009_PAR/
Copyright (c) 2010-2011
Metadata
Release files for PyPatchMatch 2.0.0rc5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pypatchmatch-2.0.0rc5.tar.gz | 480.0 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pypatchmatch-2.0.0rc5-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 | Details |
| pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_x86_64.whl | Python 3 | none | macOS 11.0+ x86-64 | Details |
| pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
Total release size: 4.3 MB
Release files / pypatchmatch-2.0.0rc5.tar.gz
| Download URL | pypatchmatch-2.0.0rc5.tar.gz |
|---|---|
| Size | 480.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0566179b1734dd53654b9fbc8fc50d4ca166d0658476997864271683f8ef3d8
|
|
BLAKE2b-256 checksum How to use checksums |
a402e699291c88043fe309a68e3e639c96f35b8a9981ccb70a72b9a2889dad31
|
| 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 30, 2026.
Transparency logRelease files / pypatchmatch-2.0.0rc5-py3-none-win_amd64.whl
| Download URL | pypatchmatch-2.0.0rc5-py3-none-win_amd64.whl |
|---|---|
| Size | 381.9 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
574e8b50bf3eb78959ad0fb37ac84dd50b8847c811b1b8b58c6fcc5e83d380d6
|
|
BLAKE2b-256 checksum How to use checksums |
b32438fba727f672daf52a0c17829b9f74969ac0661b8c9e9701681b52d1f109
|
| 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 30, 2026.
Transparency logRelease files / pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
ef4d3825a24cb987a4dc821c8214d2fc864d1522ee349bb6318a0f698d19ccbc
|
|
BLAKE2b-256 checksum How to use checksums |
ad8ab98006c050ccd9186867b903d7dc0a37d0e05f912ecceecf820046d47e54
|
| 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 30, 2026.
Transparency logRelease files / pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | pypatchmatch-2.0.0rc5-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 744.8 kB |
| Tags | Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
d71b673f8825c0a127af1456eb4e7fec6367b7d88292e2fb6a2c374c12d21c75
|
|
BLAKE2b-256 checksum How to use checksums |
4e311e0d976649edec72b7bd3676e4b0d55b02b196a125669961ceecdebf7cb6
|
| 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 30, 2026.
Transparency logRelease files / pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_x86_64.whl
| Download URL | pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_x86_64.whl |
|---|---|
| Size | 948.2 kB |
| Tags | Python 3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
976a32c182daaf67638e4427351f6942956e5356f529bd3c44bb314708661985
|
|
BLAKE2b-256 checksum How to use checksums |
30278d555c851715ba0edeba1c20837bda88caefc2de6fa149c0cfe30c149a3c
|
| 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 30, 2026.
Transparency logRelease files / pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_arm64.whl
| Download URL | pypatchmatch-2.0.0rc5-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 622.4 kB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e54113b8b05cb8a4b59ae511064247efa3f0d289a0c675f7d78586aad75502ec
|
|
BLAKE2b-256 checksum How to use checksums |
22a347fe5427319b827dbf3d05e7268e01e8d17cd280c8268aa493ceac8903bc
|
| 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 30, 2026.
Transparency log