Final Project. Gradient Domain Fusion

Michael Wan, SID: 3034012128

Overview

In the semester, we've learned various styles of blending images together, such as alpha blending, using laplacian stacks, etc. This project explores a novel technique known as Poisson blending. Poisson blending focuses on minimizing changes to the gradient of the image. Specifically, this can be solved by setting up a sparse least squares equation that can be solved easily!

Given a target image object $T$ with pixel values $V_T$ to be blended onto a source image $S$ with pixel values $V_S$, we want to find new pixel values $V'_T$ for the target image. We want to minimize the gradients along the ridges of $T$ and $S$, and maintain the internal gradient within $T$. Let $N(p)$ denote the neighboring points of a point $p$. Thus, for points $p$ in $T$ with neighbors $N(p)$ in $S$, we want to minimize $$ \sum_{p \in T} \sum_{n \in N(p) \cap S} ((V'_T[p] - V_S[n]) - (V_T[p] - V_S[n]))^2$$ For points $p$ in $T$ with neighbors $N(p)$ in $T$, we want to minimize $$ \sum_{p \in T} \sum_{n \in N(p) \cap T} ((V'_T[p] - V'_T[n]) - (V_T[p] - V_T[n]))^2$$ We can solve both of these equations together using least squares. Thus, $$ V'^*_T = \text{argmin}_{\substack{V'_T}} \sum_{p \in T} \sum_{n \in N(p) \cap S} ((V'_T[p] - V_S[n]) - (V_T[p] - V_S[n]))^2 + \sum_{p \in T} \sum_{n \in N(p) \cap T} ((V'_T[p] - V'_T[n]) - (V_T[p] - V_T[n]))^2 $$ Additionally, we can add in another constraint, which is that $V'_T[0, 0] = S[0, 0]$, to set the color range correctly. The image region $T$ does not need to be rectangular, and this can simply be done with masking. Pixels that are outside the mask are automatically set to $V_S$, whereas the pixels inside are set to $V'^*_T$.

Part 1. Toy Problem

We can sanity check our solution to the objectives above by trying to recreate a picture. In this case, we have the source and target images essentially equal, with the mask being the entire image.

        
Original toy image and reconstructed toy image.

Part 2. Poisson Blending

We now implement the solution on a real source image, target image, and mask. We create the mask by using ginput.

Example 1

        
Source and target image.
Blended Output.

Example 2

        
Source and target image.
Blended Output.

Example 3

        
Source and target image.
Blended Output.

Through these examples, we notice that there are no seams in the picture whatsoever, the Poisson blending is a success!

Part 3. Bells & Whistles

I implemented mixed gradients, which worked well when the source image has a lot of white space that we'd want to transparently blend. It did not work well for when we want to blend solid, opaque objects.

Example 1

        
Source and target image.
Blended Output. (Notice that it doesn't blend as well)

Example 2

        
Source and target image.
Blended Output.