All studies

Nearest-neighbor fields

PatchMatch completion

Remove a red bottle from a gravel photograph. Matching patches fill the marked area while the rest of the image stays in place.

JavaScript · Canvas · Web Workers · Nearest-neighbor fields

View source on GitHub

Try it

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

Image uploads are resized to a 256px preview.

The red bottle and its shadow are 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
Example · update to make your own

Ready when you are.

Worker processing · local inputs · downloadable output

How it works

The red bottle and its shadow are 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.

The bottle is replaced with gravel copied from unmasked parts of this same photograph. The canvas stays the same size, and known pixels are preserved. This is local completion; seam carving instead changes the image’s dimensions.

  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

The original, the removal mask, and the completed image. The image dimensions stay unchanged.

Original · red bottle on gravel
Removal mask · the bottle and its shadow
Completed region · reconstructed from nearby gravel patches

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.