Introduction

Every smartphone photo editor has a button that lets you lift an object from one photo and drop it into another. When the result looks fake, the reason is almost always the same: the colors at the boundary of the pasted region clash with the background.

The naive fix — blending a few pixels at the edge — blurs fine detail and rarely looks convincing. The elegant fix, published by Patrick Pérez, Michel Gangnet, and Andrew Blake at SIGGRAPH 2003, replaces the question entirely: instead of asking what color should each pixel be, it asks what gradient should each pixel have.

A gradient is simply the rate and direction of color change — the texture information humans actually see. Preserve the source gradient everywhere inside the pasted region, match the destination colors exactly on the boundary, and the result is a unique solution that blends naturally by design.

Finding that solution requires solving Poisson's equation — the same equation used in electrostatics, heat flow, and fluid simulation — but applied pixel by pixel over the pasted region.

Try It

The canvas below shows a background gradient (simulating a real photo) and a circular patch from a different "source" image (a brighter radial gradient). Press Hard paste to copy the patch with no blending — the hard ring is the seam. Press Poisson blend to solve the discrete Poisson equation over the patch pixels: the interior colors shift so that gradients match the source while boundary values match the destination.

<!-- {{c_layout_comment}} -->
<p class="hint">{{hint_para}}</p>
<canvas id="canvas" width="340" height="260" title="{{canvas_title}}"></canvas>
<div class="status" id="status">{{status_ready}}</div>
<div class="btns">
  <button id="btn-hard" type="button">{{btn_hard}}</button>
  <button id="btn-poisson" type="button">{{btn_poisson}}</button>
  <button id="btn-reset" type="button" class="ghost">{{btn_reset}}</button>
</div>
/* {{c_css_comment}} */
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; color: #222; margin: 0; }
.hint { font-size: .9rem; color: #444; margin: 0 0 .7rem; line-height: 1.45; }
canvas { display: block; border: 1px solid #cdd9e3; border-radius: 8px; max-width: 100%; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.bad { color: #c92f3c; }
.status.info { color: #1d3557; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; }
button { font: 600 14px system-ui, sans-serif; padding: .45rem .9rem; border: 1px solid #1d3557;
         background: #1d3557; color: #fff; border-radius: 8px; cursor: pointer; }
button.ghost { background: #fff; color: #1d3557; }
// Code not found

Notice that Poisson blending does not simply average the two images. The interior can end up darker or lighter than either source or destination, because the solver is imposing gradient constraints, not color averages. The seam disappears because the rate of change is continuous, even though the colors are not copied literally.

The Real Complexity

The formal problem is elegant. Let Ω\Omega be the interior of the pasted region and Ω\partial\Omega its boundary. Given the gradient field v\mathbf{v} of the source image and the colors ff^* of the destination image on Ω\partial\Omega, find ff inside Ω\Omega such that:

Δf=divvinside Ω,f=fon Ω\Delta f = \text{div}\,\mathbf{v} \quad \text{inside } \Omega, \qquad f = f^* \quad \text{on } \partial\Omega

Here Δ\Delta is the Laplacian operator (sum of second partial derivatives) and divv\text{div}\,\mathbf{v} is the divergence of the source gradient. This is a classic Poisson boundary-value problem.

In a discrete pixel grid the Laplacian of ff at pixel pp is:

Δhf(p)=qp(f(q)f(p))\Delta_h f(p) = \sum_{q \sim p} \bigl(f(q) - f(p)\bigr)

where the sum runs over the (up to four) neighbors qq of pp. Each interior pixel gives one linear equation; boundary pixels are fixed. The result is a sparse symmetric positive-definite system — one unknown per pixel, each connected to at most four neighbors.

  • Size: a 100×100100 \times 100 patch produces 10 000 equations; a megapixel region produces 10610^{6} equations.
  • Sparsity: each row has at most five non-zero entries, so the matrix is manageable despite its size.
  • Solvers: Gauss-Seidel iteration converges reliably; conjugate gradients (preconditioned with an incomplete Cholesky factor) solve million-pixel regions in under a second on modern hardware.

The technique extends naturally to mixed gradients (picking the stronger gradient at each pixel from source or destination), texture flattening, and local color changes — all by modifying the right-hand side while keeping the same sparse structure.

Where It Matters

Solving a Poisson equation over pixels turns out to be useful far beyond photo compositing:

  • Photo and video editing: the "healing brush" and "content-aware fill" tools in professional software use Poisson or closely related formulations. Every seamless object removal or sky replacement you have ever seen likely solved a linear system behind the scenes.
  • Medical imaging: surgeons overlay CT scans of different body regions or different patients to plan procedures; Poisson blending keeps diagnostic gradients intact while matching the global intensity of the target scan.
  • 3-D texture transfer: the same idea applies on curved surfaces — instead of a 2-D pixel grid you discretize the surface mesh and solve the same sparse system in the parametric domain.
  • Scientific visualization: stitching satellite images, panoramic photographs, or microscopy tiles without visible seams is a direct application of the boundary-value approach.
  • Gradient-domain editing: tone mapping for HDR images, detail enhancement, and shadow removal all manipulate the Laplacian of the image before reconstructing it with Poisson solvers.

The unifying thread is that humans perceive gradients more than absolute colors. Any manipulation that respects the gradient field while satisfying boundary conditions will look natural — and that is exactly what the Poisson equation guarantees.

For a deeper look at the discrete mathematics behind linear systems like these, see matrix exponentiation or how dynamic programming avoids recomputing overlapping subproblems.

Conclusion

Poisson image editing is one of those rare ideas that feels obvious in hindsight: humans see changes in color, not absolute color values, so preserve the changes from the source and solve for the colors that satisfy the boundary. The mathematics is a standard partial differential equation; the insight is realizing it is exactly the right tool for the job.

The sparse linear system it produces is large but tractable, and decades of numerical methods mean it can be solved interactively on consumer hardware. That is why the technique, introduced at SIGGRAPH 2003 by Pérez, Gangnet, and Blake, still underlies the clone and healing tools you use today.

Next time your photo editor makes an awkward splice disappear, remember: it solved thousands of linear equations, one per pixel, to hide the seam — and it did it by asking what the gradient should be, not what the color should be.

Share this article

Pick a channel — or use your device's native share sheet.

Comments

Loading comments...

https://www.kipuhub.com/en/article/poisson-image-editing/Content licensed under CC BY-NC 4.0.