How a Thermal Solver Repairs a Scratched Photograph
The healing brush is secretly a heat problem
Almost everyone has used the “healing brush” or “spot heal” in a photo app to wipe a scratch, a dust speck, or a stray hair off a picture. Almost no one knows that, in its simplest form, that tool is literally solving a heat-conduction problem. Steady-state heat conduction with no heat source is Laplace’s equation, ∇²T = 0, and a photo editor fills a damaged patch by demanding exactly that of the missing pixels: let them settle to the smoothest values consistent with the healthy pixels around the edge, the same way temperature settles across a metal plate once the rim is held fixed.
So we did the honest thing. We took a scratched photograph, called the damage a hole in a plate, pinned every healthy pixel around it as a fixed temperature, and handed the whole thing to a real Ansys thermal solver. We did not write the physics in Python and dress it up as a solve — the Ansys Mechanical solver assembled and solved the same Laplace operator it would for a heat-transfer job. The steady-state temperature field it returned is the repaired image.
One thing has to be said before the pretty picture, because it is the honest heart of the study: this equivalence is exact only for the diffusion family of healing — the classical kind that smooths a repair across a gap. It is not the “content-aware fill” in modern editors, which uses a completely different algorithm (PatchMatch texture synthesis) to copy real texture into the hole. Diffusion cannot invent texture. So a thermal solver erases a scratch across a cheek or a clear background beautifully, and it blurs a scratch that crosses hair or an edge. We show both, and we measure both.
Why heat conduction is the same math as inpainting
Steady-state heat conduction in a uniform plate with no internal heating obeys Laplace’s equation, ∇²T = 0. A function that satisfies it is called harmonic, and there is exactly one harmonic function that matches a set of values prescribed around the boundary of a region — its harmonic extension. Diffusion-based image inpainting is precisely that: fill the damaged region with the harmonic extension of the surrounding known pixels. Each filled pixel becomes a conduction-weighted blend of its neighbors, propagated inward from the healthy ring, with no bumps or kinks of its own. That is why a diffusion heal always looks smooth — smoothness is the equation’s only instruction.

There is a subtlety worth naming rather than hiding. A photo editor’s diffusion fill uses the 5-point pixel Laplacian — each pixel is nudged toward the average of its four orthogonal neighbors. Our finite-element plate uses PLANE55 bilinear quadrilateral thermal elements, whose consistent stiffness matrix is a slightly different (nine-point-class) discrete Laplacian. Both are legitimate discretizations of the same continuous operator, and both converge to the same harmonic answer as the grid gets finer; they agree closely but not bit-for-bit. Rather than paper over that, we measured it.
Handing the photo to Ansys Mechanical
The image is a public-domain NASA portrait of astronaut Eileen Collins, chosen because a lay reader recognizes it instantly and because it carries both kinds of region we need: smooth expanses (skin, the orange launch suit, the studio background) and textured detail (the US flag stripes, hair, the Space Shuttle model). We worked at 256 × 256, which maps to a plate of 65,536 nodes and 65,025 PLANE55 elements — one node per pixel, numbered so that pixel k is node k is export row k. We synthesized the damage ourselves — a pair of wavy scratches, two elliptical blotches, and a torn corner, 2,689 pixels in all (4.1% of the image) — so that we retain the true original and can score the repair honestly instead of guessing.
Every undamaged pixel becomes a fixed-temperature boundary condition set to that pixel’s intensity (62,847 fixed nodes per channel); the damaged pixels are left free. Color is handled by solving the three RGB channels independently on the same mesh and the same free/fixed pattern — one stiffness matrix, three right-hand sides — because the damage mask is identical across channels and only the boundary values change. The solve took 38 seconds on eight cores.
Before trusting a single healed pixel, we ran a control, because a converged solve that is quietly wrong is the failure mode that costs you. We pinned a known harmonic field on the boundary of a small test patch, left the interior free, and required the solver to reproduce that closed-form field in the interior. It did — to 7×10−15, machine precision. Only then did the image itself get solved. And the reconstruction has its own built-in check: because every healthy pixel is pinned to the true value, the reconstructed image reproduces the original exactly everywhere outside the damage, which confirms the pixel-to-node mapping is right and that the healed pixels really are the solver’s output.


Does it actually heal?
Because we kept the true original, we can put a number on the repair instead of eyeballing it. Overall, across all 2,689 damaged pixels, the Ansys reconstruction scores 19.2 dB PSNR (a root-mean-square error of about 28 gray levels on a 0–255 scale). That single number hides the real story, which is the split by region: 26.3 dB where the damage crosses a smooth area and only 18.0 dB where it crosses texture. The physics heals a scratch on the suit or the background so well you have to hunt for where it was, and it leaves a soft smear where a scratch crossed the flag or the hair. That is not a defect in the solve; it is the equation being honest about what diffusion can and cannot do.
The “same equation” claim gets its receipt here. We also solved the identical problem with the exact 5-point global harmonic solve — the discrete operator a diffusion healing brush relaxes to — and compared it to the Ansys PLANE55 result pixel by pixel. They agree to a mean of 1.16 gray levels (RMSE 2.0), with the largest single-pixel difference, about 19 levels, sitting on a hard edge where the two stencils weight neighbors differently. Same equation, two standard discretizations, a measured one-gray-level gap. That is what the equivalence between heat conduction and inpainting looks like when you actually check it.


Where the physics wins, and where it can’t
Line the two cases up and the boundary of the analogy is obvious. A blotch on the smooth orange suit heals to 16.8 dB and reads as clean at normal viewing size — the diffusion fill has nothing to reconstruct but a gentle gradient, and a gradient is exactly what harmonic functions are made of. A blotch of the same size over the textured, high-frequency background heals to only 14.8 dB and comes out as a soft, obvious smear, because there is no way for a smoothness-only rule to reinvent the fine structure that was there. The solver did not fail; it did precisely what ∇²T = 0 tells it to do.

Against a real photo editor
To make sure the physics equivalence is real and not a story we told ourselves, we healed the identical damage with a real editor’s diffusion tools: OpenCV’s inpaint, in both its Navier–Stokes and Fast-Marching modes — the diffusion algorithms that consumer healing brushes are built on. They scored 19.0 and 18.4 dB, the same ballpark as the Ansys solve, and they blur the texture in the same places. We also ran biharmonic inpainting (which solves ∇&sup4;u = 0, a higher-order cousin that continues gradients across the hole rather than just flattening them); it reached 21.1 dB overall and 32.1 dB on smooth regions, the best of the diffusion family and a fair picture of the ceiling this class of method can reach.
Two honest qualifications go with that comparison. OpenCV is a computer-vision library rather than a consumer app, but it runs the same diffusion mathematics a photo editor’s healing brush runs, so the comparison is like-for-like on the physics. And the consumer tools that clearly beat all of this on textured damage — content-aware fill and its kin — win not with better diffusion but with a different idea entirely: they synthesize texture by copying patches from elsewhere in the image. That is a genuinely separate algorithm, and it is exactly the part a heat solver was never going to do.
Have a field problem hiding inside something that doesn’t look like one? The same honest, end-to-end approach that turned a scratched photograph into a heat-conduction problem — recognizing the governing equation, building the right finite-element model, validating it against a known answer, and reporting exactly where it holds and where it doesn’t — is how we put real numbers on the physics your product actually runs on. That is innovation through insight.



