Project __ Writeup
Rudy Sandoval (rudy)
February 17, 2010
My project involves the blending of two images using a poisson equation solver. Given you image or a section of an image you would like to insert into another, obvious edges appear between the two unless a lot of manual adjusting and trimming is done. This project allows for an automatic adjustment of the source image to match the target image as well as possible. This is done by assuming that for each pixel under the mask, it will be equal to a sum of its neighbor's values along with the summed gradient value of that pixel. For all pixels outside of the mask, we use the target image's value. Given these set of constraints, we can build matrices A and b in the equation Ax = b, and solve for x: the new pixel values for the entire image.
There are two parts of this project that required optimization, otherwise run time would go into the minutes for medium-sized images. Iterating through each pixel on the mask and building the constraint matrix both proved slow processes. In order to speed these up, all indices and values were precomputed and then passed to the sparse matrix during its creation, allowing matlab to construct the matrix much faster. Overall shifts in pixel indices were calculated for each pixel under the mask to determine neighbors in any given direction for all pixels. This left me needing only 4 iterations, being the 4 neighbors for each pixel. These shifts would cause problems if any neighbors were to lie outside of the image range. A simple test was used to determine if a neighbor was out-of-bounds, and those indices were removed from the neighbor list for that iteration. The results of the project, including the extra credit of mixing gradients, allowed for seamless blending of the source image and the target image. The results show that, while seamless, the overall color shifts may result in visually displeasing results.
- Extra Credit Extension #1 Mixing Gradients: Initial results left a blurry outline surrounding several source images. This was the result of a fairly loose mask surrounding the source, leaving background with low gradient values overlapping higher gradient pixels from the target image. An easy way to fix this is to take the stronger of the source and target gradients in each of the pixel-neighbor pairs, instead of just using the source gradients. The results of this allowed transparency within the source images, usually giving better output images than without it. An unfortunate side effect of ghosting can be seen in some images, where relevant source pixels have too small a gradient compared to high frequency target images. Seen below the results is buggy results that were the result of comparing overall gradient sums, as opposed to individual pixel-neighbor pair gradients.
Results Images
Broken Results