All studies

Nearest-neighbor fields

PatchMatch completion

Paint out an object and let matching patches from elsewhere in the image fill the gap.

JavaScript · Canvas · Web Workers · Nearest-neighbor fields

View source on GitHub

Try it

Runs locally in your browser. Uploaded images stay on your device.

All processing stays in your browser. Image uploads are resized to a 256px preview.

The sample cone is masked already. Add to the coral mask, or clear it and paint another region. Keyboard: focus the source and use arrows to move and paint.

Source image
Source image
Precomputed PatchMatch completion example
Computed example · run to make your own

Ready when you are.

Worker processing · local inputs · downloadable output

How it works

The sample cone is masked already. Add to the coral mask, or clear it and paint another region. Keyboard: focus the source and use arrows to move and paint.

  1. Initialize a random field of candidate patches outside the hole.
  2. Alternate neighbor propagation with progressively smaller random searches.
  3. Reconstruct missing pixels from the matched patches and refine, while keeping known pixels unchanged.

Read the original research
Barnes, Shechtman, Finkelstein & Goldman · 2009

Computed examples

Outputs from the same implementation used in the playground.

Original landscape photograph used by the algorithm
Landscape photograph · generated input
A landscape photograph with a masked object filled using neighboring image patches
PatchMatch reconstruction · surrounding patches fill the masked area

Source photographs were generated for these studies. The displayed results were computed by the algorithms; they are not generated illustrations of an expected result. Published previews are compressed for the web.

Implementation and limits

A single-image completion loop built around PatchMatch. It can copy texture and nearby structure; it cannot invent a missing object or reconstruct a large unknown scene.

Interactive settings are bounded to keep the experiment practical in a browser. Higher detail can cost more processing time without guaranteeing a better result. The implementation and its tests are available in the source repository.