I was able to reduce the execution time of this reconstruction significantly (from around 15 seconds to around 4 seconds) by building the sparse constraint matrices via vectorization.
One way to blend in image into another is with Poisson blending. There are two images: a source image, and a target image in which we want to place the source image. We create a mask that selects the portion of the source we want to blend into the target. Then, we set up the following constraints:
Here are some results of Poisson blending:
Mixed gradients is just like Poisson blending, except we constrain the gradients of the pixels in the masked area to be the gradient of those in the source image OR target image: whichever has a larger magnitude. Note that this gradient choice is made on a per-gradient basis.
Laplacian blending is another cool way to blend images. Here’s a case when Poisson blending is clearly the way to go:
Poisson blending was much better than Laplacian blending in this case. This is because Poisson blending was able to make the overall color palette of the baby match that of the sun, which is the intended effect. Laplacian blending can’t and doesn’t achieve that effect. Laplacian blending can be better when Poisson blending would cause an unwanted color shift.