Segmentation Using Graph Cuts
Segmentation Using Graph Cuts
in Eq. (10-91), where the l’s are intensity levels of the points for which the distance
is being computed.
In 3-D, superpixels become supervoxels, which are handled by defining
12
ds = ⎡⎣( x j − xi )2 + ( y j − yi )2 + (zj − zi )2 ⎤⎦ (10-93)
where the z’s are the coordinates of the third spatial dimension. We must also add
the third spatial variable, z, to the vector in Eq. (10-86).
Because no provision is made in the algorithm to enforce connectivity, it is pos-
sible for isolated pixels to remain after convergence. These are assigned the label
of the nearest cluster using a connected components algorithm (see Section 9.6).
Although we explained the algorithm in the context of RGB color components, the
method is equally applicable to other colors systems. In fact, other components of
vector z in Eq. (10-86) (with the exception of the spatial variables) could be other
real-valued feature values, provided that a meaningful distance measure can be
defined for them.
[Link]
a b
c d e
FIGURE 10.52 (a) Image of size 533 × 566 (301,678) pixels. (b) Image segmented using the k-means algorithm.
(c) 100-element superpixel image showing boundaries for reference. (d) Same image without boundaries. (e) Super-
pixel image (d) segmented using the k-means algorithm. (Original image courtesy of NOAA.)
IMAGES AS GRAPHS
[Link]
The types of graphs in which we are interested are undirected graphs whose
edges are further characterized by a matrix, W, whose element w(i, j ) is a weight
associated with the edge that connects nodes i and j. Because the graph is undirected,
w(i, j ) = w( j, i), which means that W is a symmetric matrix. The weights are selected
to be proportional to one or more similarity measures between all pairs of nodes. A
graph whose edges are associated with weights is called a weighted graph.
The essence of the material in this section is to represent an image to be seg-
Superpixels are also well
mented as a weighted, undirected graph, where the nodes of the graph are the pixels
suited for use as graph in the image, and an edge is formed between every pair of nodes. The weight, w(i, j ),
nodes. Thus, when we of each edge is a function of the similarity between nodes i and j. We then seek to
refer in this section to
“pixels” in an image, we partition the nodes of the graph into disjoint subsets V1 , V2 ,…, VK where, by some
are, by implication, measure, the similarity among the nodes within a subset is high, and the similarity
also referring to super-
pixels. across the nodes of different subsets is low. The nodes of the partitioned subsets
correspond to the regions in the segmented image.
Set V is partitioned into subsets by cutting the graph. A cut of a graph is a parti-
tion of V into two subsets A and B such that
A ´ B = V and A ¨ B = ∅ (10-96)
where the cut is implemented by removing the edges connecting subgraphs A and B.
There are two key aspects of using graph cuts for image segmentation: (1) how to
associate a graph with an image; and (2) how to cut the graph in a way that makes
sense in terms of partitioning the image into background and foreground (object)
pixels. We address these two questions next.
Figure 10.53 shows a simplified approach for generating a graph from an image.
The nodes of the graph correspond to the pixels in the image and, to keep the expla-
nation simple, we allow edges only between adjacent pixels using 4-connectivity,
which means that there are no diagonal edges linking the pixels. But, keep in mind
that, in general, edges are specified between every pair of pixels. The weights for the
edges typically are formed from spatial relationships (for example, distance from the
vertex pixel) and intensity measures (for example, texture and color), consistent with
exhibiting similarity between pixels. In this simple example, we define the degree
of similarity between two pixels as the inverse of the difference in their intensities.
That is, for two nodes (pixels) ni and n j , the weight of the edge between them is
w(i, j ) = 1冫A 冷 I (ni ) − I (n j ) 冷 + cB, where I (ni ) and I (n j ), are the intensities of the two
nodes (pixels) and c is a constant included to prevent division by 0. Thus, the closer
the values of intensity between adjacent pixels is, the larger the value of w will be.
For illustrative purposes, the thickness of each edge in Fig. 10.53 is shown propor-
tional to the degree of similarity between the pixels that it connects (see Problem
10.44). As you can see in the figure, the edges between the dark pixels are stronger
than the edges between dark and light pixels, and vice versa. Conceptually, segmen-
tation is achieved by cutting the graph along its weak edges, as illustrated by the
dashed line in Fig. 10.53(d). Figure 10.53(c) shows the segmented image.
Although the basic structure in Fig. 10.53 is the focus of the discussion in this
section, we mention for completeness another common approach for constructing
[Link]
a b
c d
FIGURE 10.53
(a) A 3 × 3 image.
(c) A corresponding
graph.
(d) Graph cut.
(c) Segmented
image.
Image Segmentation
⇓
⇓ Node
Edge
⇓
Graph Cut
image graphs. Figure 10.54 shows the same graph as the one we just discussed, but
here you see two additional nodes called the source and sink terminal nodes, respec-
tively, each connected to all nodes in the graph via unidirectional links called t-links.
The terminal nodes are not part of the image; their role, for example, is to associate
with each pixel a probability that it is a background or foreground (object) pixel.
The probabilities are the weights of the t-links. In Figs. 10.54(c) and (d), the thickness
of each t-link is proportional to the value of the probability that the graph node to
which it is connected is a foreground or background pixel (the thicknesses shown
are so that the segmentation result would be the same as in Fig. 10.53). Which of the
two nodes we call background or foreground is arbitrary.
cut( A, B) = ∑
u ∈A,v∈B
w(u, v) (10-97)
[Link]
a b
c d
FIGURE 10.54
(a) Same image
as in Fig. 10.53(a).
(c) Corresponding
graph and terminal
nodes. (d) Graph
cut. (b) Segmented
image.
Image ⇓ Segmentation
⇓
Source Terminal Source Terminal
(Background) (Background)
Graph
⇓ Cut
where A and B satisfy Eq. (10-96). The optimum partition of a graph is the one that
minimizes this cut value. There is an exponential number of such partitions, which
would present us with an intractable computational problem. However, efficient
algorithms that run in polynomial time have been developed for solving max-flow
problems. Therefore, based on the Max-Flow, Min-Cut Theorem, we can apply these
algorithms to image segmentation, provided that we cast segmentation as a flow
problem and select the weights for the edges and t-links such that minimum graph
cuts will result in meaningful segmentations.
Although the min-cut approach offers an elegant solution, it can result in group-
ings that favor cutting small sets of isolated nodes in a graph, leading to improper
segmentations. Figure 10.55 shows an example, in which the two regions of interest
are characterized by the tightness of the pixel groupings. Meaningful edge weights
that reflect this property would be inversely proportional to the distance between
pairs of points. But this would lead to weights that would be smaller for isolated
points, resulting in min cuts such as the example in Fig. 10.55. In fact, any cut that
partitions out individual points on the left of the figure will have a smaller cut value
in Eq. (10-4) than a cut that properly partitions the points into two groups based on
[Link]
their proximity, such as the partition shown in Fig. 10.55. The approach presented in
this section, proposed by Shi and Malik [2000] (see also Hochbaum [2010]), is aimed
at avoiding this type of behavior by redefining the concept of a cut.
Instead of looking at the total weight value of the edges that connect two parti-
tions, the idea is to work with a measure of “disassociation” that computes the cost
as a fraction of the total edge connections to all nodes in the graph. This measure,
called the normalized cut (Ncut), is defined as
cut( A, B) cut( A, B)
Ncut ( A, B) = + (10-98)
assoc( A, V ) assoc(B, V )
where cut( A, B) is given by Eq. (10-97) and
assoc( A, V ) = ∑
u ∈A, z ∈V
w(u, z) (10-99)
is the sum of the weights of all the edges from the nodes of subgraph A to the nodes
of the entire graph. Similarly,
assoc(B, V ) = ∑
v ∈B, z ∈V
w(v, z) (10-100)
is the sum of the weights of the edges from all the edges in B to the entire graph. As
you can see, assoc( A, V ) is simply the cut of A from the rest of the graph, and simi-
larly for assoc(B, V ).
By using Ncut ( A, B) instead of cut( A, B), the cut that partitions isolated points
will no longer have small values. You can see this, for example, by noting in Fig. 10.55
that if A is the single node shown, cut( A, B) and assoc( A, V ) will have the same val-
ue. Thus, independently of how small cut( A, B) is, Ncut ( A, B) will always be greater
than or equal to 1, thus providing normalization for “pathological” cases such as this.
Based on similar concepts, we can define a measure for total normalized associa-
tion within graph partitions as
[Link]
assoc( A, A) assoc(B, B)
Nassoc( A, B) = + (10-101)
assoc( A, V ) assoc(B, V )
where assoc( A, A) and assoc(B, B) are the total weights connecting the nodes within
A and within B, respectively. It is not difficult to show (see Problem 10.46) that
di = ∑ w(i, j )
columns in the image.
(10-103)
j
be the sum of the weights from node ni to all other nodes in V. Using these defini-
tions, we can write Eq. (10-98) as
cut( A, B) cut( A, B)
Ncut ( A, B) = +
cut( A, V ) cut(B, V )
∑
xi > 0, x j < 0
− w(i, j )xi x j ∑
xi < 0 , x j > 0
−w(i, j )xi x j (10-104)
= +
∑ di
x >0
∑ di
xi < 0
i
The objective is to find a vector, x, that minimizes Ncut ( A, B). A closed-form solu-
tion that minimizes Eq. (10-104) can be found, but only if the elements of x are
allowed to be real, continuous numbers instead of being constrained to be ±1. The
solution derived by Shi and Malik [2000] is given by solving the generalized eigen-
system expression
(D − W)y = lDy (10-105)
[Link]
Az = l z (10-106)
where
−1 − 12
A = D 2 (D − W)D (10-107)
and
1
z = D2 y (10-108)
[Link]
Note that the algorithm works by recursively generating two-way cuts. The number of
groups (e.g., regions) in the segmented image is controlled by K. Other criteria, such
as the maximum size allowed for each cut, can further refine the final segmentation.
For example, when using pixels and their intensities as the basis for constructing the
graph, we can specify the maximum and/or minimum size allowed for each region.
[Link]
⎧ − [ I ( ni )− I ( nj )]2 − dist ( ni , nj )
⎪ s I2 sd2
if dist(ni , n j ) < r
w(i, j ) = ⎨ e e
⎪0 otherwise
⎩
where I (ni ) is the intensity of node ni , s I2 and sd2 are constants determining the spread of the two
Gaussian-like functions, dist(ni , n j ) is the distance (e.g., the Euclidean distance) between the two nodes,
and r is a radial constant that establishes how far away we are willing to consider similarity. The expo-
nential terms decrease as a function of dissimilarity in intensity and as function of distance between the
nodes, as required of our measure of similarity in this case.
Thus far, we have discussed segmentation based on three principal concepts: edge
detection, thresholding, and region extraction. Each of these approaches was found
to have advantages (for example, speed in the case of global thresholding) and dis-
advantages (for example, the need for post-processing, such as edge linking, in edge-
based segmentation). In this section, we discuss an approach based on the concept of
so-called morphological watersheds. Segmentation by watersheds embodies many of
the concepts of the other three approaches and, as such, often produces more stable
segmentation results, including connected segmentation boundaries. This approach
also provides a simple framework for incorporating knowledge-based constraints
(see Fig. 1.23) in the segmentation process, as we discuss at the end of this section.
BACKGROUND
The concept of a watershed is based on visualizing an image in three dimensions,
two spatial coordinates versus intensity, as in Fig. 2.18(a). In such a “topographic”
interpretation, we consider three types of points: (1) points belonging to a regional
minimum; (2) points at which a drop of water, if placed at the location of any of those
[Link]