aiinpainting.app

How it works

The Inpainting Algorithm Behind This Tool

The tool on this site is not a neural network — it runs a patch-matching inpainting algorithm in your browser. Its lineage is two papers: Criminisi's 2003 exemplar-based method [1], and the 2016 feature-priority refinement by Li, Wang, Liu & Wang [2] that fixes the classic method's most damaging failure mode. This page traces that path, using figures from the 2016 paper (reproduced with translated sub-captions).

2003 — Criminisi's exemplar-based inpainting

Earlier diffusion-based methods smeared pixels inward like heat. Criminisi, Perez and Toyama instead treated the hole as a texture synthesis problem: fill it one patch at a time, copying real pixels from elsewhere in the image [1]. Each patch on the fill front gets a priority:

P(p) = C(p) × D(p)

where C(p) — the confidence term — measures how much reliable, already-known data surrounds the patch, and D(p) — the data term — rewards patches sitting on strong continuous structures (edges, contours). The highest-priority patch is filled first: the algorithm searches the known region for the most similar patch and copies its missing pixels. Confidence is updated, and the loop repeats until the hole is gone.

This one idea — fill in the right order, borrow real pixels — still powers classic inpainting today. But it has a flaw that gets worse as the hole grows.

The framework both versions share

Both papers describe the image the same way: Ω is the target (missing) region, Φ the known source region, δΩ the fill front, and Ψp the patch centered on a front pixel p, whose surface normal np meets the isophote (perpendicular to the gradient, ∇Ip⊥) in the data term:

Diagram of the target region Ω, source region Φ, fill front δΩ, target patch Ψp, normal np and isophote used to compute patch priority
Figure 1 from Li et al. [2] (sub-captions translated): notation used to compute the priority of a patch on the fill front — the same formulation Criminisi introduced in 2003.

Where the classic method breaks

Every filled pixel gets the confidence of the patch that filled it — always less than 1. So as filling progresses, confidence values on the front keep decaying toward zero, and since P(p) = C(p) × D(p), the priority formula eventually stops caring about the data term at all. The paper calls this the effect-loss problem [2]: the fill order degenerates, errors accumulate, and structures erode. In the worst case no suitable match is found at all and the result visibly distorts.

Experiment from the paper: a green ellipse over a black-and-gray boundary. Criminisi's method erodes the ground boundary into a mound, while the 2016 method fills it flat; accompanying curves show the confidence and priority values along a column
Figure 2 from Li et al. [2] (sub-captions translated). (a) Original image with a green ellipse over a straight black/gray boundary. (b) Criminisi's result: the boundary is eroded into a mound. (c) The 2016 feature-priority result: the boundary continues flat and clean. Curves (d)–(g) plot the confidence and priority values along one column — in the classic method confidence collapses toward −1 as filling proceeds, which is exactly the failure the new priority prevents.

2016 — the feature-priority fix

Li, Wang, Liu and Wang published the fix in the Journal of Computer-Aided Design & Computer Graphics [2]. The fill loop and the search stay the same; only the priority changes:

P(p) = (C(p) − λ + w·|∇I(p)|) × D(p)

  • C(p) − λ subtracts a constant (λ = 0.35 in our implementation) from the confidence term, so it no longer collapses toward zero — the priority formula keeps working deep into the hole.
  • w·|∇I(p)| adds the normalized gradient magnitude at the front pixel itself: patches sitting on a strong, identifiable feature (a wire, a roof line, a boundary) get filled earlier, while there is still reliable structure to match against. That cuts the error rate of the matching step.

The paper also analyzes how a wrong best-match patch triggers chains of consecutive wrong fills, and shows the mechanism for locating the best source patch Ψq in Φ — the step both versions share:

Diagram showing the best source patch Ψq found in the known region Φ for the best target patch ΨP2 on the fill front δΩ
Figure 3 from Li et al. [2] (sub-captions translated): the best target patch ΨP2 on the fill front δΩ, and the best-matching source patch Ψq searched in the known region Φ.

Real object removal, side by side

The paper's most convincing experiment removes a bungee jumper over water — one of the classic test images from the 2003 paper:

Five-panel comparison: the original bungee photo, the jumper marked in green, Criminisi's eroded result, a competing method, and the feature-priority result with a clean roofline
Figure 5 from Li et al. [2], panels relabelled in English. (c) Criminisi's method damages the roofline; (d) a competing method from the paper's comparison leaves artifacts around the roof; (e) the feature-priority method reconstructs the roof cleanly.

This is the exact method this site runs — ported line for line from the paper's formulation, with the Criminisi version kept as a baseline for verification. Watch it work on your own photo:

What neither version can do

Both algorithms are non-generative: they only ever borrow real pixels from your image. Repetitive texture (grass, walls, water) and thin structures fill cleanly; a hole over a face or a chaotic crowd has nothing to borrow from, and that is the job for generative AI models — at the cost of uploading your photo and a plausible-but-invented result. For where this branch sits in the wider field, see the complete map of inpainting techniques from 1999 to 2025.

Try the algorithm on your own photo

The tool below runs the 2016 feature-priority method entirely in your browser — no upload, no signup, no watermark.

References

  1. A. Criminisi, P. Perez, K. Toyama. Object Removal by Exemplar-Based Inpainting. In: IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR), 2003: 721–728.
  2. 李旭峰, 王静, 刘红敏, 王志衡. 特征优先块匹配图像修复算法. 计算机辅助设计与图形学学报 (Journal of Computer-Aided Design & Computer Graphics), 2016, 28(7): 1131–1137. Article page.

Figures 1–3 and 5 on this page are reproduced from reference [2] for scholarly illustration, with sub-captions translated from Chinese.

Keep going