In order to blend part of an image onto another, where a mask specified the area on the source to blend into the target, my project matched gradients from the source image. First, these are the results of just copying the source images's pixels over. The target, mask, source, and result images are shown in that order.
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
The edges clearly stand out,
To handle the edge cases, my project simply uses the gradients of the existing neighboring pixels. By not defaulting edge pixels to a value, it doesn't blend a constant color into the edges of the target image.
This is done by calculating the multiplier for each pixel (to subtract the neighbor values from), and then subtracting only existing neighbor values, rather than all 4 possible ones.
Most images blend very well, although there seems to be a blurry edge around each blended area. This is most likely from the forced blending between the two different image gradients, whereas the center of the blended area is mostly just the source image's gradients.
However, there is one case where it's fairly obvious the result was blended: when the target image's color does not match the source image's color, then the blended area's color looks unnatural. For example, in the image of a bear in a swimming pool, the bear is unnaturally blue. In the image of the tank on the beach, the target image's sky is somewhat visible through the top of the tank even though the sand color makes the bottom look more realistic.
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
I also tried blending a cartoon source image, and it turned out surprisingly well. Because it takes the source image's color, and not the target image's, my face blended well, despite the difference in realistic-ness.