In this project, I use Poisson Blending to blend one image seemlessly into another image. I also compare the results of Poisson Blending with naive blending and mixed gradient blending. This is a a simple technique with a broad set of applications including blending, tone-mapping, and non-photorealistic rendering
This part seeks to give conceptual intuition for the implementation in other parts. Here, I take the provided Toy Story image as well as an image of the tennis player Roger Federer. For each of them, I compute x and y gradients and one pixel intensity and reconstruct the images.
Poisson blending is a gradient-domain technique used to seamlessly blend a source region from one image into a target image. The core idea is to preserve the gradients of the source region while ensuring a smooth transition with the target background. To achieve this, the pixel intensities within the blending region are solved for by minimizing a least-squares energy function:
\[ v = \arg\min_{v} \sum_{i \in S} \sum_{j \in \mathcal{N}(i)} \left( (v_i - v_j) - (s_i - s_j) \right)^2 \]
Here, \(v\) represents the pixel intensities of the blended image, \(s\) is the source image, and \(\mathcal{N}(i)\) denotes the 4-connected neighbors of pixel \(i\). For pixels on the boundary of the source region, we use the intensities from the target image \(t\) as fixed values to ensure a seamless boundary transition:
\[ v = \arg\min_{v} \sum_{i \in S} \sum_{j \in \mathcal{N}(i) \cap \bar{S}} \left( (v_i - t_j) - (s_i - s_j) \right)^2 \]
To solve this optimization problem, we represent it as a sparse linear system in the form: \[ A \cdot v = b \] where \(A\) is a sparse matrix encoding the gradient constraints, \(v\) is the vector of unknown pixel intensities, and \(b\) contains the fixed target values and source gradients. The system is solved for each color channel independently using a sparse least-squares solver.
This method ensures that the gradients of the source region dominate within the blended region while maintaining smooth transitions with the surrounding target image.
Minor Failure Case: If you look very closely at the bottom-left of the first penguin, you see a bright white spot that wasn't present in any of the original source or target images.
The Mixed Gradients method extends Poisson blending by combining the gradients of both the source and target images. Instead of relying solely on the source gradients, it dynamically selects the stronger gradient (i.e., the one with the larger magnitude) between the source and the target for each pixel. The optimization problem is formulated as:
\[ v = \arg\min_{v} \sum_{i \in S, j \in \mathcal{N}(i) \cap S} \left( (v_i - v_j) - d_{ij} \right)^2 + \sum_{i \in S, j \in \mathcal{N}(i) \cap \bar{S}} \left( (v_i - t_j) - d_{ij} \right)^2 \]
Here, \(d_{ij}\) represents the mixed gradient, which is determined as follows:
\[ d_{ij} = \begin{cases} s_i - s_j & \text{if } |s_i - s_j| > |t_i - t_j|, \\ t_i - t_j & \text{otherwise}. \end{cases} \]
In this formulation, \(v\) represents the pixel intensities of the blended image, \(s\) is the source image, \(t\) is the target image, and \(\mathcal{N}(i)\) denotes the 4-connected neighbors of pixel \(i\). The first term ensures gradient preservation within the source region, while the second term enforces a smooth transition at the boundary by incorporating gradients from both the source and target.
Similar to Poisson blending, this problem is solved as a sparse linear system: \[ A \cdot v = b, \] where \(A\) encodes the gradient constraints, \(v\) is the vector of unknown pixel intensities, and \(b\) incorporates the mixed gradients and boundary conditions. This approach ensures that sharp features from the source and target are preserved, resulting in a visually seamless blend.