Image Blending Writeup

Lyn Fong (lfong)
February 16th, 2010

Algorithm

My implementation of Image Blending follows the standard poisson image blending algorithm. After acquiring a target image and a source image, a mask was made by hand for the source. Poisson image blending involves solving a system of equations, in which the hard constraints are the known pixel values.

The system of equations we are trying to solve states that for every unknown pixel, the unknown pixel's value is the average of its neighbors, however we would also like the result to have the same features as the target image, so the difference between each pixel and its neighbors should be equal to the difference between the source pixel in that location and the source pixel's neighbors. Since we are solving a system of equations, we are trying to create a matrix A, and a vector b, such that solving for Ax= b will yield the image in x.

The known values are the values in the target image in the location specified by the strip just around the edge of the mask. Since unknown pixel values take on the value of the average of their neighbors, this allows the edge of the masked source to blend in smoothly. This is entered into the matrix A such that for pixel i, where i is that pixel's linear index into the image, A(i,i)= 1, and in the vector b, the ith value is the value of the pixel in the target image.

The unknown values are an average of the neighbors and the gradient in the source at that point. Thus for unknown pixel i, A(i,i)= the number of neighbors that pixel has. In addition, for every unknown value neighbor n, A(i,n)= -1. This is simply the matrix representation of the left hand side of the equation above. In the corresponding position in vector b, b(i)= the sum of the pixel values of the known pixels and the gradient at that point. This the the right hand side of the above equation.

Finally, the system of equations is solved for x, the image. x is them reshaped into the image and pasted into the target.

No extra credit was done.

Results

Below are the results. For the first five images, the image in the left column is the result of a simple cut and paste, the image in the right column is the result of the image blending algorithm. The first one is an interesting example of a fail case. Since the algorithm's notion of preserving the source is dependent on gradient, source images that are too smooth to start with end up having the target object being blended with the background too, which is unfortunate.

Results Images