Motivation
Placing a source object into a destination image can leave a visible brightness seam. Instead of copying every source intensity, one can seek an image whose local differences follow a chosen guidance field while its boundary agrees with the destination. The existing compositing unit explains alpha and alignment; this unit develops a different, gradient-domain model for a selected region. It does not guarantee a seamless result.
We begin with a scalar channel in linear intensity. Color channels can be treated separately under this model, but independent channel processing does not by itself ensure perceptually faithful color.
An anchored graph model
Definition 5.1.1
(Differences and boundary values)
Let a finite undirected pixel graph have an arbitrary orientation assigned to each edge once. For oriented edge , let the desired difference be and the reconstructed difference be . Divide vertices into unknown interior vertices and fixed boundary vertices with prescribed destination values . Minimize
over the interior values, holding all boundary values fixed.
The orientation is a bookkeeping choice: reversing an edge and replacing by leaves its squared term unchanged. A guidance field may be obtained from a source image, but the model also permits arbitrary, possibly inconsistent values. The graph and boundary convention determine what is optimized; omitting boundary edges or changing the selected region changes the problem.
Theorem 5.1.2
(Existence and uniqueness with anchors)
If every connected component of the graph contains at least one fixed boundary vertex, the quadratic energy has a unique minimizer over the interior vertices.
Proof
(Positive definite quadratic part)
Let be the vector of interior values, and let extend by zero at the boundary vertices. Writing , where equals at the boundary and zero in the interior, each term is . Expanding the squares gives
for a symmetric matrix , a vector and a constant . If , then is constant on each connected component. Every component has a boundary vertex where , so everywhere and . Hence is positive definite. Completing the square, , so is the unique minimizer.
Proof X-ray
Where the anchors act, and where they do not
The anchoring hypothesis is used exactly once, in the step from to : only there does a boundary vertex turn a constant into zero. The guidance values and the boundary values enter only through and , so they decide which minimizer is found but never whether it is unique. If one component has no fixed vertex, constant vectors on that component lie in the null space of and the argument stops; the conclusion then fails. The proof asserts existence and uniqueness of a minimum, not that the guidance can be matched with zero energy.
If a connected component has no fixed vertex, adding the same constant to every vertex in that component does not change its edge differences. It cannot have a unique solution without another constraint. This is an ambiguity in absolute intensity, not a numerical defect of one solver.
Worked example 5.1.3
(A component with no anchor)
Take two interior vertices joined by one edge, with no fixed vertex and guidance . The energy is , which is zero along the whole line : and are both minimizers. Fixing one value, say , makes the component anchored and leaves the unique minimizer . The ambiguity is exactly the freedom to add a constant to both vertices.
A complete three-edge example
Worked example 5.1.4
(Guidance that cannot match both endpoints)
Take a line of four vertices with fixed and . The unknowns are . Orient edges from left to right and request guidance . Then
Differentiating gives
whose solution is , . All three edge residuals equal , so the minimum energy is . The requested differences sum to zero but the fixed endpoints differ by one: they cannot all be met exactly. The unconstrained solution also exceeds ; valid display-range values require an additional, explicitly constrained optimization.
Counterexample mode
Matching every difference may be impossible
On the same line and endpoints, insisting on all three differences would imply , contradicting . A least-squares solution must distribute the inconsistency rather than claim zero residual. If guidance is instead, its sum is and , attain zero energy.
From local equations to a solver
For an interior vertex , orient every incident edge outward just for this local formula and denote the consistently signed desired difference by .
Proposition 5.1.5
(Interior equations)
Under the anchoring hypothesis, the unique minimizer satisfies, at every interior vertex ,
and any values satisfying these equations are that minimizer.
Proof
(Setting the partial derivative to zero)
Only the terms of edges at depend on , and for the outward edge the term is . The partial derivative with respect to is . Setting it to zero gives ; moving the boundary terms to the right-hand side gives the displayed equation. Under anchoring the energy is a strictly convex quadratic, so a point where all partial derivatives vanish is its unique minimizer.
Reversing an edge also reverses its guidance, so this local equation agrees with any global orientation. The coefficient matrix is an anchored graph Laplacian. Solving it separately per channel is one possible construction; a matrix inverse need not be formed explicitly. A residual check tests the linear solve, but a small residual cannot establish that the region, boundary, guidance or color model was appropriate.
Concept lensAnalytic
The discrete Poisson equation
Write for the graph Laplacian and for the outward guidance sum at . Because boundary vertices enter through , the interior equations say at every interior vertex, with at the boundary: a discrete Poisson equation with Dirichlet boundary values. When the guidance is zero, it reduces to , so every interior value is the average of its neighbors and the solution is the harmonic interpolation of the boundary values.
Worked example 5.1.6
(Zero guidance interpolates the boundary)
Take a path of five vertices with , fixed and all guidance zero. The interior equations are , and . From the first, ; the second gives ; the third gives . So , a straight line, and each value is the average of its two neighbors. Every edge has residual , so the minimum energy is .
Common mistake
(Reversing an edge without negating its guidance)
Let the edge have , with and ; its residual is . Describing the same edge as but keeping gives . The guidance is a signed difference, so it must change sign with the orientation.
Common mistake
(Expecting the source brightness to survive)
Suppose the source region is constant at , so all its differences are zero, and the destination boundary is constant at . The unique minimizer is the constant in the interior, with energy zero. Only the differences of the source are used; its absolute brightness is discarded, so the boundary values fix the overall level.
Strong boundary disagreement can shift colors or brightness throughout the region. Noise in the guidance is also propagated by the linear solve. The model does not resolve misalignment, occlusion or inconsistent illumination automatically. If intensities must stay in , solve the corresponding constrained problem or declare another postprocessing rule; simply clipping an unconstrained result generally changes its optimality.
Exercises
Quick check
(In the three-edge example, verify the two equations at and calculate the energy.)
Substitute into both equations, then into the three residuals.
Solution · Answer
and . Each residual is , so .
Quick check
(On the same line, set guidance to . Find an exact zero-energy reconstruction.)
Add the differences from the left endpoint.
Solution · Answer
The differences give and ; the last difference is . All three residuals vanish.
Quick check
(Suppose a graph has two disconnected components but only the first has a fixed vertex. Why can the full reconstruction not be unique?)
What happens to the second component if a constant is added?
Solution · Answer
Adding any constant to the unanchored component leaves every edge difference unchanged and does not affect the fixed component. Therefore uniqueness fails.
Quick check
(If one reverses the edge , what must happen to its guidance to leave the energy unchanged?)
Compare the reconstructed and target differences after reversal.
Solution · Answer
Use orientation and replace by . Both the reconstructed and target differences change sign, leaving the squared error unchanged.
Further study
Mixed guidance, robust losses, constrained intensity ranges, multiscale methods and color-space choices need additional analysis. This chapter does not implement a production blending system or prove perceptual quality for a particular image.