Gradient-domain processing is a classic technique in computational photography with varieties of applications including image blending, tone-mapping, and non-photorealistic rendering. In this project, the major task is to establish a seamless blending between two images with Possion Blending. Another variant that utilizes the mixed gradients is also implemented as a comparison.
The background image in Fig.3, Fig.4 and Fig.5 are all from my personal photo album!
In the toy problem, we are trying to restore an image from its gradient information. For the gradient calculation, we just take the forward difference for both axis.
The details of my implementation are:
lsqr
solver from scipy
package. It is a iterative solver for least square problems.csc_matrix
from scipy
. The comparison in terms of the runtime is shown in this table.Here are the test results of this algorithm:
![]() |
Given a source image and a target image , we want to blend the images within a predefined region and solve for the new image . Here, we are calculating the gradients for each pixel in all 4 directions. The objectives are minimized for each channel separately. The obtained new images are stitched together for the final RGB output.
The details of my implementation are:
lsqr
solver from scipy
package. It is a iterative solver for least square problems.csc_matrix
from scipy
. The comparison in terms of the runtime is shown in this table.Here are the test results of this algorithm for the given images:
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
|
We can acquire decent blending results from Fig.3 and Fig.4. However, the resulting images are not as good in Fig.5 and Fig.6. The background in region looks blurred. The major cause is that the gradients/textures in the target image are mostly larger than those in the source image. When blended, the gradients from the source images are preserved. This makes the resulting image blurred in . It can be concluded that the Poission blending is not suitable in cases where the gradients in the source image are smaller than those in the target image. One possible way to resolve this issue is shown in Bells & Whistles.
From the aforementioned test results, we found a limitation of the Poisson blending. An better option is to preserve the gradient information as the larger one between the source and target image. In this way, we can keep all the evident textures in both images and avoid the generation of the blurred results.
The details of my implementation are:
lsqr
solver from scipy
package. It is a iterative solver for least square problems.csc_matrix
from scipy
. The comparison in terms of the runtime is shown in this table.Here are the test results of this algorithm for some used images:
![]() |
![]() |
![]() |
It can be seen from all 3 comparisions that the blurred region in the Poisson blending results are greatly resolved. The resulting blending images are more natural because of the preserved textures. Although, there are still visual defects in Fig.9. The horizon line is hidden by the moon. A potential strategy to tackle this problem is that we can define a threshold value based on the intensity of the target region. If , we calculate the gradient as . I tested my hypothesis with the setup below:
The resulting blending image is shown below. We can tell that it is visually improved compared with the original mix gradients.
![]() |
When converting the color image to grayscale, we usually lose the important information from color contrast, which makes it difficult to understand the resulting image. In this part, we want to smartly generate a grayscale image based on the original grayscale image with the gradients information from certain channel preserved.
![]() |
![]() |
from cv2 package |
First of all, we need to choose which channel we should use to obtain the gradient information. Here, we convert the original RGB image to HSV and run the Sobel filter on each channel. The obtained gradient images are:
![]() |
![]() |
![]() |
Using the cv2 grayscale image as background, we choose each of the H,S and V channel as the foreground and generate the blending image with the mixed gradient method decribed above. Among the results, the one using V channel yields to the best performance. We can tell from the results below that "35" is still recognizable after my grayscale convertion.
![]() |
![]() |
Using the same strategy described above, some more test results are shown below:
![]() |
![]() |
![]() |
![]() |
Operations | Regular Storage(s) | Sparse Storage(s) |
---|---|---|
Toy problem | ||
Possion Blending | ||
Mixed Gradients | ||
Color2Gray | N/A |