CS129 / Project 2 / Image Blending

This project implements the seamless image composition algorithm from Pérez, et al. "Poisson Image Editing". The algorithm is written for Matlab. It uses sparse matrices as suggested in the handout. Prior calling the blending function, the image is cropped to the minimum rectangular region containing the mask to speed up the algorithm. Merging a patch of  400x300 pixels takes about 2 seconds in my laptop.  The resulting function can perform several of the applications mentioned in "Poisson Image Editing": seamless cloning, mixing gradients, inserting objects with holes, texture flattening, and local color changes.

Seamless cloning (click to zoom in)

Original Mask Source Result


Transparent cloning (click to zoom in)

Original Mask Source Result


Objects with holes (click to zoom in)

Original Mask Source Result


Texture flattening

The effect of texture flattening can be achieved by solving the Poisson equation using the gradients of the original image passed through a sieve function M. First, the edges are detected in the original image using the magnitude of the intensity gradient. I have used the Sobel operator to compute the intensity gradients. Then, the gradient magnitude image is thresholded to make a binary mask. The magnitude image is also used as a gradient sieve M that preserves the original image gradients at the edges and sets them to zero in the rest of the image. Finally, the same equations as before are solved to recompute the intensities in the flattened regions. Observe in the result column below how the image content is preserved but the small details were removed in the regions without edges.

Original Mask M Result


Local color change

Here we want to set to grayscale the original image except in the region covered by the mask. If we do it in the naive way, the final image will have a noticeable seam surrounding the mask. By using a procedure similar as for image cloning, the seam caused by the sudden change from color to grayscale is concealed.

Original Mask Result


Failure case

The method fails when the gradients close to the seam are too different. For example, when a constant region is merged with a non-constant one as in the images below. Even though both original images have similar colors, the result does not look as a true picture.

Original Mask Source Result