Overview
This project aims to apply gradient-domain processing for image blending. The primary goal is to seamlessly blend an object or texture from a source image into a target image. We mainly use Poisson Blending to achieve this. The idea of Poisson blending is to solve a four-constrain problem: minimize x-direction gradient in the target area (left -> right and right -> left); minimize y-direction gradient in the target area (up -> down and down -> up).To warm up, we first enjoy gradient domain processing with a toy-problem: image reconstruction. Then we implemented the poisson blending and applied it to several images. Finally, to get a better result, I also tried mixed gradient blending with several images.
Run q11.py for the toy problem; run q12.py for the poisson blending; run q13.py for the mixed gradient blending.
How to run the code
1. Run Python3 q11.py for the toy problem;
2. Place the source image, mask, and target image in the "images" folder and change the corresponding names in q12.py and q13.py;
3. Run python3 q12.py or python3 q13.py for the results of the last two questions.
Part 1: Toy Problem
I follow the process provided by the introduction and get the following result. See q11.pt for details.
Results
Part 2: Poisson Blending
I also implemented the poisson blending following the provided description. See q12.py for details.
Results
Sample image
My favaroate image
Other Results (1)
Other Results (2)
Failure Case
We can see this blending result is not good regarding (1) the target image got dark when blending with the source object; (2) The color of the source image changed when blending to the target image. We think the reason is that the color difference of the source image and the target image is quite huge, so in order to minimize the constrain, all the background color of the target image got dark and some part of the source image got lighter. This is also a general shortcoming of Possion Blending: only paired of images whose color gradients are relatively small can get good results. This issue can be partly solve by the mixed gradient blending or HSV-based gradient blending.
Part 3: Mixed Blending
I also implemented the mixed gradient blending following the provided instructions. See q13.py for details.
Results
My favaroate result
Other results (1)
Other results (2)
We can see, compared with the Possion Blending, the mixed gradient blending can merge the source image and the target image more smoothly. Althourgh for some images (e.g. other reullts (2)), it seems less realistic. However, this blending technique has a wider application for other tasks such as style transfer.