Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PatchMatch based Inpainting

License: MIT PyPI Downloads Ruff

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. 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 (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 and PATCHMATCH_WITH_HIGHGUI enables the debug visualization of Inpainting::run.

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

Releases are published to PyPI by creating a GitHub release; the version is taken from its tag (e.g. v2.0.0).

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.

@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.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyPatchMatch 2.0.0rc2
File Size Uploaded
pypatchmatch-2.0.0rc2.tar.gz 455.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for PyPatchMatch 2.0.0rc2
File
pypatchmatch-2.0.0rc2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pypatchmatch-2.0.0rc2-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.0rc2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details
pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details
pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 4.2 MB

Release files / pypatchmatch-2.0.0rc2.tar.gz

Download URL pypatchmatch-2.0.0rc2.tar.gz
Size 455.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4a9476b252de6c5a5f493b81fc38d8a84e241bbd2b1632016f0e84f24a1bd1e1
BLAKE2b-256 checksum
How to use checksums
f829b514af6c2c66a51d6d2d407482067ea8ea0e2b05a2313c0e7bac10f638fd
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 28, 2026.

Transparency log

Release files / pypatchmatch-2.0.0rc2-py3-none-win_amd64.whl

Download URL pypatchmatch-2.0.0rc2-py3-none-win_amd64.whl
Size 380.2 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
6a66a24d6e27d60a1cba0c6b0be74307fbcf1cc9731e785db0b1459dd8967198
BLAKE2b-256 checksum
How to use checksums
f7fcaa34cbc3449b1a904ab25452ee91100663eeab99df2f6195c521f13d0f54
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 28, 2026.

Transparency log

Release files / pypatchmatch-2.0.0rc2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypatchmatch-2.0.0rc2-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
6462abb947ad57fd4170766e85fd49a353cc01c516d37185e929aca7be2c089a
BLAKE2b-256 checksum
How to use checksums
ba2bbb96213d81f9026f3484386d6696a0ea11bdb068f0c46063fb07be0a6829
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 28, 2026.

Transparency log

Release files / pypatchmatch-2.0.0rc2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL pypatchmatch-2.0.0rc2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 743.2 kB
Tags Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
856afe0368efd7064f89a879ebed01530320b059e2277574262e196b4ff8904e
BLAKE2b-256 checksum
How to use checksums
7d985143f287ae0f51119330ad04010004b7a973a6ef20f452c271432b7d23d0
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 28, 2026.

Transparency log

Release files / pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_x86_64.whl

Download URL pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_x86_64.whl
Size 947.2 kB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
2cbf696df5c6ff31b962bd86c83730f65d40eb7bd02b2012d9478ac62e5e4e87
BLAKE2b-256 checksum
How to use checksums
3b99f593d34d65551657d7b6ceba573eb7c28ea7ea69a21f7b40c00c196f44f8
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 28, 2026.

Transparency log

Release files / pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_arm64.whl

Download URL pypatchmatch-2.0.0rc2-py3-none-macosx_11_0_arm64.whl
Size 621.2 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f3f1da7275e57827e60f6e29c2cbc56aef3e676b5e1b5a85afc01e736d30a211
BLAKE2b-256 checksum
How to use checksums
9e6f457b0f707c2164b33919753a36ce2e7511ff06715106a7ea2650890720bd
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 28, 2026.

Transparency log
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