Two units ago: segmentation = minimise E(L) = \sum_p D_p(L_p) + \lambda \sum_{(p,q)} w_{pq}[L_p \ne L_q]. Last unit: minimum cuts by max-flow. Today we connect them (Boykov & Jolly, 2001).
Build a graph from an image so that cut cost = energy.
One max-flow gives the exact best segmentation.
Contrast-sensitive weights: boundaries are cheap at image edges.
Seeds: the user marks some object and background pixels.
What goes wrong: shrinking, blocky boundaries, a bad intensity model.
Slides titled The math give the formulas and proofs; the ideas are complete without them.
Every labelling is a cut and every cut a labelling, at the same cost: minimum cut = minimum energy.
Graph-cut segmentation as pseudocode
nodes: one per pixel, plus s (object) and t (background)
for every pixel p:
edge s → p with capacity D_p(0); edge p → t with capacity D_p(1)
for every neighbour q: edge p → q with capacity λ · w_pq
flow = maximum flow from s to t # = the smallest energy
for every pixel p:
L_p = 1 if p can still be reached from s, else 0
One maximum flow gives the exact minimum: no starting guess, no local minima.
Seeds and contrast weights only change capacities (later in this lecture).
With \lambda = 2: 101 costs 1 + 4 = 5, 111 still 4: the dark pixel is filled.
The graph for λ = 1 with its minimum cut (red, dashed). Blue nodes: source side, labelled object.
The math: which energies can be cut?
Capacities must be \ge 0. If D_p(0) or D_p(1) is negative, add the same constant to both: every labelling changes by the same amount.
The pairwise term must be submodular (Kolmogorov & Zabih, 2004): V(0,1) + V(1,0) \ge V(0,0) + V(1,1). The boundary term \lambda w_{pq}[L_p \ne L_q] is \lambda w_{pq} + \lambda w_{pq} \ge 0 + 0: fine.
Then the minimum is exact, global, in polynomial time.
Not covered: more than two labels. The Potts energy with 3 or more labels is NP-hard; α-expansion solves a sequence of two-label cuts and gets within a factor 2.
The 1\times 3 example with \sigma = 1: |I_1 - I_2| = 2, so w = e^{-2} = 0.135. Now 101 costs 1 + 2\lambda \cdot 0.135: thresholding wins up to \lambda = 11.1.
Right: for each pixel the smaller of its weights to the right and down neighbour. Dark = cheap to cut: along the nuclear envelope and the texture. Micrograph: Robert M. Hunt, CC BY 3.0, via Wikimedia Commons.
Try it: the graph of a small image
Seeds
The user paints a few object and background pixels (Boykov & Jolly, 2001):
Hard constraints: an object seed gets s \to p with capacity “\infty” (larger than any possible cut), so it can never be on the background side. Background seeds likewise with p \to t.
Intensity model from the seeds: fit a Gaussian, or take a histogram, of the seed pixels of each label; D_p(\ell) = -\log P(I_p \mid \ell).
Interactive: look at the result, add a seed where it is wrong, cut again. A new max-flow takes milliseconds at this size.
Thresholding with the same model (\lambda = 0) is the baseline to beat. A third way to use the same seeds, the random walker, and all three side by side (watershed as a spanning forest): the graph-based segmentation day.
The demo’s “nucleus” preset: one object stroke (red), five background strokes (blue), histogram model from the seed pixels, σ = 25. Right: the same model without smoothness. Micrograph: Robert M. Hunt, CC BY 3.0, via Wikimedia Commons.
Try it: interactive graph cut
Try it: graph cut on a micrograph
Failure modes
Shrinking bias: the boundary term grows with length. A thin structure has a long boundary for its area: its data gain \propto area, its boundary cost \propto length. A strip of width k survives only if its data gain per pixel exceeds about 2\lambda/k.
Metrication: with 4 neighbours a boundary costs its length in the “city-block” metric: a diagonal boundary costs \sqrt2 = 1.41 per unit length, a horizontal one 1. The cut prefers axis-aligned, blocky shapes. With 8 neighbours and weights \tfrac12 (sides) and \tfrac{1}{2\sqrt2} (diagonals), both cost \tfrac12 + \tfrac{1}{\sqrt2} = 1.21 per unit length.
Overlapping intensities: if object and background have the same grey levels, no data term can separate them; only seeds and image edges can.
The demo presets “thin arm lost”, “blocky” (4 and 8 neighbours) and “overlapping intensities” (background seeds only on white areas).
Beyond: GrabCut and more labels
GrabCut (Rother, Kolmogorov & Blake, 2004): colour images, the user draws only a box. Alternate: fit colour models (mixtures of Gaussians) to the current labelling, cut again, until it settles.
More than two labels (several tissues, several cells): α-expansion repeats binary cuts, “label \alpha or keep your label”, over all labels.
The same graph construction appears in stereo matching, image stitching and denoising: any energy with unary and submodular pairwise terms.
Summary
Graph: pixels + s (object) + t (background); t-links = data term, n-links = \lambda w_{pq}.
Cut cost = energy, so one max-flow gives the exact minimum of a submodular binary energy.