CS129 / Project 2 / Image Blending

Example of an image mask. White
pixels are transplanted.

Source image that corresponds to
the above image mask.

The goal of this project was to write a program that would take an element of one "source" image and blend it into a second "target" image. We used a "mask" image to determine which pixels to transplant from our source image onto our target image. Examples of each are on the right.

The blending of these two images relies heavily on the concept of a gradient. A gradient is essentially the rate of change of some multi-dimensional function. In this case, we used two dimensional gradients for each of the 3 RGB color channels.

In order to blend the images together, we used only the gradients of the pixels being transplanted. The result is that each "transplanted" pixel on the target image has a gradient that is the same as the gradient of the corresponding pixel on the source image. This does not mean that the transplanted pixels have identical RGB values. This was done in order to make the image segment match the coloring of the target image, but still have all the features of the source image. The results are all below

Resulting transplant of the example source/mask.



Results Key

Original Target Image Final Image
Source Image Source Mask

Resulting Images

One interesting note about the resulting images is that if you look closely at PSY (the korean guy in the last picture), his coloring is heavily influenced by the color of the background to the extent that he looks completely unrealistic. A good way to avoid this would be to find a way to use gradient blending only on the borders of the source image.