Part 2

In this section, we are trying to paste an image into another image, and edit the pasted region into order to make the transplant more convincing. To do this, we need to solve an optimization problem:
not found
In detail, would like to ensure that

(i) The gradient between two neighboring pixels in the pasted region are as close as possible to the gradient between the corresponding pixels in the source image.
(ii) The gradient between a pixel in the pasted region and a neighboring pixel in the target region should be as close as possible to the gradient between the corresponding pixels in the source image.

Optimizing these two criteria will ensure that the pasted area looks like the original source image, but with a different intensity.

This is a least-squares problem, so we can write an equation for each constraint. Each equation is of the form

(i) v_i - v_j = s_i - s_j OR
(ii) v_i = s_i - s_j + t_j

Then, we can enter the equations into a matrix equation Av = b, and solve for the unknowns in vector v.