![](https://csdnimg.cn/release/download_crawler_static/10179572/bg3.jpg)
end of this overlap region to the other. That is, the chosen path is
through those pixels where the old and new patch colors are similar
(Figure 2(left)). The path determines which patch contributes pixels
at different locations in the overlap region.
To see how this can be cast into a graph cut problem, we first
need to choose a matching quality measure for pixels from the old
and new patch. In the graph cut version of this problem, the selected
path will run between pairs of pixels. The simplest quality measure,
then, will be a measure of color difference between the pairs of
pixels. Let s and t be two adjacent pixel positions in the overlap
region. Also, let A(s) and B(s) be the pixel colors at the position
s in the old and new patches, respectively. We define the matching
quality cost M between the two adjacent pixels s and t that copy
from patches A and B respectively to be:
M(s, t, A, B) = kA(s) − B(s)k + kA(t) − B(t)k (1)
where k · k denotes an appropriate norm. We consider a more so-
phisticated cost function in a later section. For now, this match cost
is all we need to use graph cuts to solve the path finding problem.
Consider the graph shown in Figure 2(right) that has one node
per pixel in the overlap region between patches. We wish to find a
low-cost path through this region from top to bottom. This region is
shown as 3× 3 pixels in the figure, but it is usually more like 8 ×32
pixels in typical image quilting problems (the overlap between two
32 × 32 patches). The arcs connecting the adjacent pixel nodes s
and t are labelled with the matching quality cost M(s, t, A, B). Two
additional nodes are added, representing the old and new patches (A
and B). Finally, we add arcs that have infinitely high costs between
some of the pixels and the nodes A or B. These are constraint arcs,
and they indicate pixels that we insist will come from one particular
patch. In Figure 2, we have constrained pixels 1, 2, and 3 to come
from the old patch, and pixels 7, 8, and 9 must come from the new
patch. To find out which patch each of the pixels 4, 5, and 6 will
come from is determined by solving a graph cut problem. Specif-
ically, we seek the minimum cost cut of the graph, that separates
node A from node B. This is a classical graph problem called min-
cut or max-flow [Ford and Fulkerson 1962; Sedgewick 2001] and
algorithms for solving it are well understood and easy to code. In
the example of Figure 2, the red line shows the minimum cut, and
this means pixel 4 will be copied from patch B (since its portion of
the graph is still connected to node B), whereas pixels 5 and 6 will
be from the old patch A.
3.1 Accounting for Old Seams
The above example does not show the full power of using graph
cuts for texture synthesis. Suppose that several patches have already
been placed down in the output texture, and that we wish to lay
down a new patch in a region where multiple patches already meet.
There is a potential for visible seams along the border between old
patches, and we can measure this using the arc costs from the graph
cut problem that we solved when laying down these patches. We can
Patch
A
Patch
B
Overlap
cut
1
2
3
4
5
6
7
8
9
Patch
A
Patch
B
¥
¥
¥
¥
¥ ¥
cut
Figure 2: (Left) Schematic showing the overlapping region between
two patches. (Right) Graph formulation of the seam finding prob-
lem, with the red line showing the minimum cost cut.
incorporate these old seam costs into the new graph cut problem,
and thus we can determine which pixels (if any) from the new patch
should cover over some of these old seams. To our knowledge, this
cannot be done using dynamic programming – the old seam and
its cost at each pixel needs to be remembered; however, dynamic
programming is a memoryless optimization procedure in the sense
that it cannot keep track of old solutions.
Existing
Pixels
A
New
Patch
B
Overlap
1
2
3
4
5
6
7
8
9
¥
¥
¥
¥
¥ ¥
Existing
Pixels
A
old
cut
new
cut
S
1
S
2
S
3
S
4
old
cut
new
cut
New
Patch
B
Figure 3: (Left) Finding the best new cut (red) with an old seam
(green) already present. (Right) Graph formulation with old seams
present. Nodes s
1
to s
4
and their arcs to B encode the cost of the old
seam.
We illustrate this problem in Figure 3. In the graph formulation
of this problem, all of the old patches are represented by a single
node A, and the new patch is B. Since A now represents a collec-
tion of patches, we use A
s
to denote the particular patch that pixel
s copies from. For each seam between old pixels, we introduce a
seam node into the graph between the pair of pixel nodes. We con-
nect each seam node with an arc to the new patch node B, and the
cost of this arc is the old matching cost when we created this seam,
i.e., M(s, t, A
s
, A
t
) where s and t are the two pixels that straddle
the seam. In Figure 3, there is an old seam between pixels 1 and
4, so we insert a seam node s
1
between these two pixel nodes. We
also connect s
1
to the new patch node B, and label this arc with
the old matching cost M(1, 4, A
1
, A
4
). We label the arc from pixel
node 1 to s
1
with the cost M(1, 4, A
1
, B) (the matching cost when
only pixel 4 is assigned the new patch) and the arc from s
1
to pixel
node 4 with the cost M(1, 4, B, A
4
) (the matching cost when only
pixel 1 is assigned the new patch). If the arc between a seam node
and the new patch node B is cut, this means that the old seam re-
mains in the output image. If such an arc is not cut, this means that
the seam has been overwritten by new pixels, so the old seam cost
is not counted in the final cost. If one of the arcs between a seam
node and the pixels adjacent to it is cut, it means that a new seam
has been introduced at the same position and a new seam cost (de-
pending upon which arc has been cut) is added to the final cost. In
Figure 3, the red line shows the final graph cut: the old seam at s
3
has been replaced by a new seam, the seam at s
4
has disappeared,
and fresh seams have been introduced between nodes 3 and 6, 5 and
6, and 4 and 7.
This equivalence between seam cost and the min-cut of the graph
holds if and only if at most one of the three arcs meeting at the
seam nodes is included in the min-cut. The cost of this arc is the
new seam cost, and if no arc is cut, the seam is removed and the
cost goes to zero. This is true only if we ensure that M is a metric
(satisfies the triangle inequality) [Boykov et al. 1999], which is true
if the norm in Equation (1) is a metric. Satisfying the triangle in-
equality implies that picking two arcs originating from a seam node
is always costlier than picking just one of them, hence at most one
arc is picked in the min-cut, as desired. Our graph cut formulation
is equivalent to the one in [Boykov et al. 1999] and the addition
of patches corresponds to the α -expansion step in their work. In
fact, our implementation uses their code for computing the graph
min-cut. Whereas they made use of graph cuts for image noise re-
moval and image correspondence for stereo, our use of graph cuts
for texture synthesis is novel.