scs logo Programming Project #2 (proj2)
15-463: Computational Photography
Natasha Kholgade

Gradient Domain Image processing

Toy Problem

For all examples, a large sparse matrix of dimensions number of constraints by number of variables was set up. In the case of the toy problem, the number of variables was set to be equivalent to all the pixels in the image, hence for the toy image of size 110x119, this turned out to be 13090 variables. The top part of the sparse matrix consisted of constraints pertaining to setting the horizontal gradients equal, while the bottom part consisted of setting the vertical gradients to be equal. A final constraint was included that forced the top left pixel in the output image to be the same as that of the input image. The reconstructed image is shown below to the right of the original image.

As an alternative, the final constraint was set such that the top left pixel of the reconstructed image was 20/255 more in intensity than that of the original image. Since the entire image gets reconstructed up to a constant, the whole image brightens up by that constant.

The function reconstructimage() performs the reconstruction

Poisson Blending

To perform Poisson blending, the mask pertaining to the source object in an image was used to determine the corresponding X and Y coordinates (with the help of the meshgrid() and sub2ind() functions). In addition to pixel values at these coordinates, the blending mechanism also required pixel values to the top, left, right and bottom, which were extracted by specifying the required regions through these coordinates. The mask limits what pixels are observed by the object and the surrounding targets, hence it was used to determine the neighboring pixels for pixels within the source and for pixels in the target region. These constraints were used to set up a large sparse matrix to solve for the region within the source mask, and the resulting least-squares system was solved to get the correct intensities within the source.
The following image shows a penguin placed next to the skiers.


Below is an image I took when I visited California, and after it is an image of a parasailer that I obtained from the Internet. Poisson blending allowed me to place the parasailer in a region where technically parasailing (or any human presence for that matter) is actually not permitted (plus I don't think parasailing too close to the rocks is such a super idea -- I wouldn't try it; if you did want to, then Poisson blending would be the way to go).





The function blendimages() performs the Poisson blending

Poisson Blending

For Poisson blending with mixed gradients, the differences between pixels for the source image were simply replaced with the larger of the source pixel differences and target pixel differences magnitude-wise. Notice the difference in result when Poisson blending with mixed gradients is used in an attempt to 'tattoo' a rose on a zebra as opposed to regular Possion blending. The gradients are correctly matched to the target object, so that it appears seamless, while the regular blending looks terrible.
 
The function blendimageslargermag() performs blending with mixed gradients