Image inpainting is a technique of modifying an image in an undetectable form. It’s most often used to repair an image, although it can easily be used to remove unwanted objects. Artists have most likely been doing inpainting in one form or another since the dawn of time, although it has only recently been named “inpainting.” Artists fill gaps and blemishes by using information from other parts of the image (color, shape, and texture) to guess the contents.

For my final project in Math 440 Partial Differential Equations and Fourier Analysis, I decided to automate the process with a PDE. That just left choosing a PDE to use. We studied three major partial differential equations in class: Laplace’s Equation, heat equation, and the wave equation. Of the three, the heat equation was the natural choice to use for inpainting since it spreads information out. To gain some intuition about the problem, think about the one-dimensional problem: a strip of pixels with a region (called omega) missing from the center. We’ll fill in omega by using the information present on the left and the right of it. If the pixels were tending to get brighter as we approached omega from the left, then omega should get brighter on the left side. The same is true if we approach omega from the right. This tells us we should set a Neumann problem:

\mbox{The heat equation in one dimension} \\ u_{tt} = u_{xx} \\ u_t(0,t)=0 \\ u_t(L, t) = 0

It’s easy to imagine how this problem could be extended into two dimensions. However, it will be a little unruly because we will have a boundary condition for every pixel on the boundary. My PowerPoint shows what the inpainting heat equation would look like in two dimensions. Once the two-dimensional problem is set up, it’s time to solve. It can be done analytically (with software like Maple) or by a discrete approximation. Since images are already discrete, I chose to go the approximation route.

That’s where the method of finite differences steps in. It’s a relatively easy method for undergraduates to understand. The method relies on the fact that any function can be written as a Taylor series. If you cut off all but the first few terms of a Taylor series, you get an approximation. The attached powerpoint and handout explain the method of finite differences in detail.

I coded up the method of finite differences in Matlab, which has nice implements for dealing with images. I’ve included examples images from my program below.

Files

Image Inpainting

Demo output from my Matlab code.

21 Photos