Useless tools · §1.1

Erase With PDEs

Paint over part of an image and let a partial differential equation fill the painted region in.

Loading sample image...

Paint the region
PDE result / random-walk overlay

What is this doing?

The painted (red) region is filled in by solving a partial differential equation on it. Pixels outside the mask are treated as fixed boundary data; pixels inside the mask are the unknowns being solved for.

Three methods are offered. Harmonic inpainting solves the Dirichlet problem

The solution is the harmonic extension of the surrounding image into the masked region. Discretized on the pixel grid, each interior value becomes the average of its four neighbours, and the iterative solver (red–black Gauss–Seidel with successive over-relaxation) drives the residual down by repeated local averaging.

The heat equation mode evolves

from the same boundary data, with the same clamped exterior. This is explicit time-stepping with the four-neighbour Laplacian; the timestep is capped by the CFL bound for the 2D stencil. Run long enough, the heat equation relaxes to the same harmonic solution as the first method — diffusion is the gradient flow of the Dirichlet energy.

Poisson blending solves

where is a chosen source pattern. The solution copies the source's gradients into the masked region while matching the target image at the boundary. This is the core idea behind seamless cloning: what makes a paste look natural is local change, not absolute colour, so the right thing to copy from the source is its Laplacian rather than its raw values.

Harmonic inpainting has a probabilistic reading. By the mean-value property, the harmonic value at an interior point is the expected boundary value reached by a random walk starting there. The "random-walk interpretation" button samples a few hundred such walks from a chosen point and averages the boundary values they hit; the average approximates the harmonic solution at that point, and the drawn paths give a sense of why the solution is determined by the boundary alone.