Poisson Blending

This project implements poisson blending to blend a masked foreground object into a background image. The method uses this formula $$\boldsymbol{v} = argmin_{\boldsymbol{v}} \sum_{i\in S, j\in N_i \cap S}((v_i - v_j) - (s_i - s_j))^2 + \sum_{i \in S, j \in N_i \cap\neg S}((v_i - t_j) - (s_i - s_j))^2$$ Apart from the required implementations, I have also implemented mixed blending for bells and whistles.

Below uses a simpler version of blending to reconstruct a small image.

Below is the implementation of full poisson blending.
The trick that i used to reduce variable number in least square solver is to only list the pixels inside the mask as variables. To achieve this, I used a dictionary to map its pixel location to its variable index.
Because the method and code of mixed blending is very similar to that of poisson blending, it is written in the same code block.

Below is the default demo of poisson blending.

Below is my favorite blending result, as the blending problem itself is not trivial and the blending result makes the lighting look natural.

Below are some more results of poisson blending, the first one produce very good result, however the problem itself is not very difficult.
The second one does not produce aesthetic results, as the grass in the foreground is too bright, when it is blended to the background, it changed the color tone of the robomower entirely, thus the result is not saticfactory.

Below is a demonstration of mixed blending.
The benefit of mixed blending is that it preserves some of the background texture while blending the image. The final result looks like some sort of mural painted on the wall.