16-726 Learning-Based Image Synthesis

Assignment 2: Gradient Domain Fusion
Jun Luo
Mar. 2021

Overview

In this assignment, we use gradient-domain processing techniques for blending and color-to-grayscale (Bells and Whistles) applications. More specifically, for the primary part of this assignment, we focus on Poisson blending, which aims to seamlessly blend an object or texture from a source image into a target image.

Toy Problem

In this problem, we try to reconstruct the toy image by minimizing three kinds of objectives described below.

Below shows the result of the reconstruction.

Fig. 1 Input and reconstructed image


Poisson Blending

In this part, our goal is to seamlessly blend the masked source image to the target image using a gradient-based technique named Poisson blending. For this technique, we copy and past the pixel intensity values from the target image to the output blent image, if the pixel is not in the mask, and we minimize a gradient error with respect to the pixel that are inside the mask and the pixels that are in its four-neighbor. More specifically, we want to minimize the following objective: $$ \boldsymbol{v}=\operatorname{argmin}_{\boldsymbol{v}} \sum_{i \in S, j \in N_{i} \cap S}\left(\left(v_{i}-v_{j}\right)-\left(s_{i}-s_{j}\right)\right)^{2}+\sum_{i \in S, j \in N_{i} \cap \neg S}\left(\left(v_{i}-t_{j}\right)-\left(s_{i}-s_{j}\right)\right)^{2}, $$ where the first term correspond to the case where the neighboring pixel (indexed by \(j\)) is also inside the mask, and the second term correspond to the case where the neighboring pixel in not inside the mask. Results of the Poisson blending on the provided images and some other images are listed below.

Fig. 2 Bear
Fig. 3 Bear mask
Fig. 4 Pool
Fig. 5 Bear naive blending
Fig. 6 Bear Poisson blending

Fig. 7 Myself
Fig. 8 Mask
Fig. 9 Monalisa
Fig. 10 Monalisa with mask naive blending
Fig. 11 Monalisa with mask Poisson blending

Fig. 12 Lion (source)
Fig. 13 Lion mask
Fig. 14 Forest (source)
Fig. 15 Monalisa with mask naive blending
Fig. 16 Monalisa with mask Poisson blending

Fig. 17 Lizard (source)
Fig. 18 Lizard mask
Fig. 19 Woods (source)
Fig. 20 Lizard naive blending
Fig. 21 Lizard Poisson blending

From the results above we can see when the area between the border of the mask has similar color with the area of the object, Poisson blending often change the color of the object to the color of area along the mask in the background which is a failure case (lion in forest example). When the area between the border of the mask has different color with the area of the object, the Poisson blending tend to work well (Monalisa and lizard example).


Bells & Whistles: Mixed Gradients

In this section, we explore a mixed gradient method with the following objective: \( \boldsymbol{v}=\operatorname{argmin}_{\boldsymbol{v}} \sum_{i \in S, j \in N_{i} \cap S}\left(\left(v_{i}-v_{j}\right)-d_{i j}\right)^{2}+\sum_{i \in S, j \in N_{i} \cap \neg S}\left(\left(v_{i}-t_{j}\right)-d_{i j}\right)^{2} \) where \( d_{ij}\) represents the value of the gradient from the source or the target image with the larger magnitude. Results are shown below.

Fig. 22 Bear with different blending
Fig. 23 Monalisa with different blending
Fig. 24 Lions with different blending
Fig. 25 Lizard with different blending

From the results above, we can clearly see that the mixed gradient method can show the texture behind the object, which means that the mask area will not only covers the front ground texture and gradient but those of the background as well.


Bells & Whistles: Color2Gray

In this part, our goad is to convert the color image to grayscale image while keep the numbers (patterns) on color image. A naive open-cv color2gray method (cvtColor) will lose the pattern. Here we explore a method where we convert the color image into HSV color space, and use the gradient method by minimize the error between the gradient of output image and the mean gradient of S channel and V channel. More specifically, we aim to compute the \( \boldsymbol{v}=\operatorname{argmin}_{\boldsymbol{v}} \sum_{i \in S, j \in N_{i} \cap S}\left(\left(v_{i}-v_{j}\right)-d_{i j}\right)^{2} \), where \( d_{ij}\) represent the mean gradient of S channel and V channel. Results are shown below.

Fig. 26 35 color
Fig. 27 35 gray (naive)
Fig. 28 35 gray (Gradient based)
Fig. 29 42 color
Fig. 30 42 gray (naive)
Fig. 31 42 gray (Gradient based)
Fig. 32 2 color
Fig. 33 2 gray (naive)
Fig. 34 2 gray (Gradient based)
Fig. 35 9 color
Fig. 36 9 gray (naive)
Fig. 37 9 gray (Gradient based)