Project 2 Writeup, Poisson Blending

David Dufresne (ddufresn) January 29, 2010

I have implemented a poisson image blending algorithm. The algorithm first generates an array the same size as the image, wherein the value at cell (i,j,k) is the sum of the differences of pixel (i,j,k) from its neighbors in the source image. This is equivalent to the gradient at pixel (i,j,k). The number of neighbors at (i,j,k) is then computed. A sparse matrix A of size ((image width)*(image height)*3)^2 is constructed, such that each row R represents the constraints on the value of the pixel at linear index R. For pixels not in the mask, the row R contains 1 at column R. b(R) is set to the value of the pixel in the target image. For pixels in the mask, the value for the pixel in row R is set to the number of neighbors, and each neighbor is assigned a value of -1 in row R. b(R) is set to the gradient of the pixel with linear index R. The matrix A is constructed in one line, so as to avoid indexing into a large, sparse matrix. This sped up execution time considerably. Solving A*x=b for x gives the pixel values for the output image.

While I am extremely thankful for the support code provided in fix_images.m, by enclosing the source image inside a larger image, it became difficult to determine where the edges of the source image where. If the mask included an edge of the source image, then my calculations for gradient would include the difference between an edge pixel and the black space surrounding it. This gave some strange results. My "hacky" solution to this was to insert the source image into a copy of the source image that was one pixel larger in each dimension.

Without Hack With Hack