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).

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. 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 (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.

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.

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

Release files for PyPatchMatch 2.0.0b2

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.0b2
File Size Uploaded
pypatchmatch-2.0.0b2.tar.gz 452.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for PyPatchMatch 2.0.0b2
File
pypatchmatch-2.0.0b2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pypatchmatch-2.0.0b2-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.0b2-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.0b2-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details
pypatchmatch-2.0.0b2-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.0b2.tar.gz

Download URL pypatchmatch-2.0.0b2.tar.gz
Size 452.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a296c79f87fc206ac63ff641edc57843e2d04d94b27e5a5c5c4e243d3202e59c
BLAKE2b-256 checksum
How to use checksums
6de6b1812a6754b2d13a265f73c57b2049168644f7c6574af5e05297114f4394
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 25, 2026.

Transparency log

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

Download URL pypatchmatch-2.0.0b2-py3-none-win_amd64.whl
Size 378.4 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ef661da25eb3f574a3cbc8a487177fe70b7c23f006830aa0894b4f02c2631025
BLAKE2b-256 checksum
How to use checksums
f177c13646d1fcf5f0be613fdce410ccfb085c63210aa3fbe6ede126aefc8042
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 25, 2026.

Transparency log

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

Download URL pypatchmatch-2.0.0b2-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
cf4e60da64d433138ead92bce98db1ca6835685ccd5510297eca29dda27859f5
BLAKE2b-256 checksum
How to use checksums
519f3eaf9fe1b27f11c2c3c1f0d5514de2c6e8a5edd18a2de63b8bdc9a4682fb
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 25, 2026.

Transparency log

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

Download URL pypatchmatch-2.0.0b2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 741.7 kB
Tags Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2e22b7beabe49b333455f4b0b2bb2e3967edd3035eec2f0700e330d91dc40455
BLAKE2b-256 checksum
How to use checksums
2dd34c22a606f7b9c7f6dcdb8638c260a6d839970894c644e05bd3b9e9458818
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 25, 2026.

Transparency log

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

Download URL pypatchmatch-2.0.0b2-py3-none-macosx_11_0_x86_64.whl
Size 945.8 kB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
88eb97c4c9ed24b076c0faf38a5dc5efabbf0b5c9b61180d9c4824d35afcd092
BLAKE2b-256 checksum
How to use checksums
d82504d08f3e020c44a4b75f3cd257cc54eff29e9ae6021b86f68549f1fa02f4
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 25, 2026.

Transparency log

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

Download URL pypatchmatch-2.0.0b2-py3-none-macosx_11_0_arm64.whl
Size 620.0 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
177aaa3c3a1a615a69f79f57c72144c8b21c0e46538332e1e1069ac8f5a214fd
BLAKE2b-256 checksum
How to use checksums
62e5ce4faab340c395dd82dab141907116d9eaa9f55f9c22b9b3f81010a13364
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 25, 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