Skip to main content
Pre-release

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

PatchMatch based Inpainting

PyPI Python Downloads License: MIT

Tests Coverage Quality Gate

uv Ruff ponytail

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. This repository continues vacancy/PyPatchMatch by Jiayuan Mao, through the forks lkwq007/PyPatchMatch and invoke-ai/PyPatchMatch.

Birdhouses removed from a photo by patchmatch.inpaint

From left to right: the photo, the input of examples/py_example.py with the birdhouses painted out in white, and its result.

Installation

pip install PyPatchMatch

Wheels for Linux (glibc, x86_64 and aarch64), macOS 11+ (arm64 and x86_64) and Windows (x64 and ARM64) ship the compiled library with a statically linked OpenCV, so no compiler or OpenCV installation is needed. On other platforms, e.g. Alpine Linux, 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, and the colors under the holes have no influence on the fill. 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. Below 5, the coarsest level with a hole searches with a radius of 5, so that repeating patterns and lines continue across larger holes. Above 7, coarse levels narrower than six patches use the largest radius that fits, but at least 7: larger patches found no sources there and left the fill flat.

patchmatch.set_random_seed(seed) sets the seed of the randomized search, modulo 2**32, and patchmatch.set_verbose(True) prints the progress of the native code to stderr. The inpainting runs on all cores; patchmatch.set_num_threads(n) limits it to n threads (0 restores the default), and the fills do not depend on it. 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 between 0 and the largest float32, about 3.4e38.

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
uv run gui/app.py              # paint masks in a Tkinter window

The GUI tries new images quickly, without writing a script for each one, e.g. to pick new examples or to verify edge cases: load an image, paint the holes (every painted pixel is one) and compare the original with the fill. Scrolling and the zoom buttons zoom both views together; dragging the result, or the original with the right mouse button or with Shift, moves them. The toggle global_mask paints the global mask instead, drawn half transparent; a pixel belongs to the mask painted last. Clear, File > Save Mask… and File > Open Mask… act on the selected mask; the files look like examples/images/camera_damaged_mask.png (255 = set). Detect adds the pixels whose channels all reach the threshold next to it to the holes, outside the global mask: 255 takes the pure white pixels, as patchmatch.inpaint without a mask, and 200 exactly the damage of camera_damaged.png. It needs a Python with Tk, such as the Pythons that uv installs. Its test runs with uv run pytest gui --no-cov.

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.

@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.3.0rc3

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.3.0rc3
File Size Uploaded Provenance Actions
pypatchmatch-2.3.0rc3.tar.gz 2.2 MB With provenance Details for pypatchmatch-2.3.0rc3.tar.gz

Built distributions (wheels)

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

Total release size: 5.8 MB

Release files / pypatchmatch-2.3.0rc3.tar.gz

Download URL pypatchmatch-2.3.0rc3.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
3e92ec6fb00229ec82e0d82b3c9c4a7c00f82429c2d530e387a1d8dd8e11c2bd
BLAKE2b-256 checksum
How to use checksums
9e7e897f6f8ac8562b269a73ab2aa426f4a97828cb9f02fb7af0b1d7b77eae6b
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-win_arm64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-win_arm64.whl
Size 554.0 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
f850ddcae97c15ab9887ce2c43eff6d3218f9ad36a2215ba9bc6c4f3568a9e75
BLAKE2b-256 checksum
How to use checksums
7319b5f10543d6f487cb6705f98da461d46246543c4f9a5a1c8e7811a3426f59
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-win_amd64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-win_amd64.whl
Size 681.5 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
efb29eb0f3a9c6e82e98bc310d0a5a9ea1d84c90f3f92bbe87f74134b7c60b24
BLAKE2b-256 checksum
How to use checksums
90cb9c244be8dc9dc27db34bfb9d6df0d3fca946b07202c29ff515d70117faa6
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 722.4 kB
Tags Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
70c71dddf46e6934dc6bbe2f771b0dd5029701b84ccb472f213e7662b5a8c468
BLAKE2b-256 checksum
How to use checksums
a4c6cd479a37009ecc9489b1ba7172de6d6a1f106d151c250d4f42ec43df7955
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 547.2 kB
Tags Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
93e44ff524877c60c6ee9b9657e3b16a6f8030567cdbe38383d046d339af3abf
BLAKE2b-256 checksum
How to use checksums
91e7b8083db07d09803f0742412aa46f909a53453fdf3ad2a8264c44a9b4039d
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-macosx_11_0_x86_64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-macosx_11_0_x86_64.whl
Size 616.1 kB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
a0e2053840cc75215b54bd9eba9f55f61acbaa628c502bb8bf8df4766ebd7bd9
BLAKE2b-256 checksum
How to use checksums
6229637f2a3c92c0c10384768c92958e575e943f9e94f4ae42c7fe8dc67d3a69
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 Oct 27, 2026.

Transparency log

Release files / pypatchmatch-2.3.0rc3-py3-none-macosx_11_0_arm64.whl

Download URL pypatchmatch-2.3.0rc3-py3-none-macosx_11_0_arm64.whl
Size 435.2 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
64df1d64e783aa439fb7dff246f9937878dc1eeb42e7384b88a15c2a6b265a68
BLAKE2b-256 checksum
How to use checksums
3e4ec15ecf43f74f84b791794ee2dbf293e29cec2880e35eb3a26015561f2332
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 Oct 27, 2026.

Transparency log

Security for PyPatchMatch 2.3.0rc3

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 pypatchmatch-2.3.0rc3.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 Oct 27, 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.

Release history Release notifications | RSS feed

This release
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