Projects

Poisson Image Editing

Image Processing, UCL · 2024

Overview

Editing pixels directly leaves visible seams, because the eye notices the discontinuity at the boundary more than the absolute colours. So instead of choosing the pixel values inside a region Ω directly, we choose the values whose gradients best match a guidance field v, while keeping the boundary ∂Ω fixed to its original values. This is the Poisson equation with Dirichlet boundary conditions, ∇²f = ∇·v over Ω with f|∂Ω = f*|∂Ω.

Discretising this on the pixel grid with the 5-point Laplacian gives one linear equation per masked pixel, with the known boundary values moved to the right-hand side, which is what makes the system solvable. Each technique is simply a different choice of v, and colour images are solved one channel at a time.

I assemble and solve the system directly with SciPy, without using any of OpenCV's seamlessClone functions. OpenCV is only used to load images, pad arrays and run Canny.

Seamless cloning

Here, I transfer a page of Darwin's notebook onto a sheet of rusted, painted steel. Ω covers the whole patch rather than only the ink strokes, so every method edits exactly the same pixels and the only difference is the guidance field.

The naive copy places a rectangle of white paper on the plate, which clearly does not fit in. Importing gradients uses v = ∇g, the source image's own gradient. The paper disappears and the ink takes on the colour of the plate, but the plate's texture is lost as well. This is because the solve reproduces the gradients of the source, which is smooth paper, so the result is smooth too.

Mixing gradients, shown on the card above, uses whichever of the source and target gradients is stronger at each edge. This way, the rust and rivets are preserved inside the patch while the ink is still clearly visible.

A naive copy, showing a visible rectangle of white paper on the metal The same patch with imported gradients, seamless but with the plate's texture lost
Naive copy, and importing gradients.

Texture flattening

A face with texture flattened, retaining only edges found by Canny
Texture flattening, where the guidance field only keeps gradients on Canny edges.