Energy minimisation
A large part of this course solves problems in the same two steps. First, write down a number, the energy, that says how bad any candidate answer is. Then find the answer with the smallest energy. The candidate may be a labelling of the pixels, a denoised image, a curve, a path, a flow field or a depth map, and the search method changes with it. This page puts the methods side by side: what each one scores, how it finds the minimum, whether that minimum is the best one, and when the best one is still wrong. Each method is taught in its own unit; follow the links.
The page is in two layers, like the units: ideas and pictures first, then one short collapsed callout, The math, that writes the shared recipe as formulas. You can skip it.
The question
Thresholding decides every pixel on its own. Noise makes single pixels jump to the wrong side, and the threshold cannot know that a lone object pixel in the middle of background is unlikely.
Energy minimisation adds that knowledge as a cost. Each candidate answer pays for two things:
- disagreeing with the data (a sample far from the level of its label), and
- being implausible (here: every boundary between object and background costs λ).
The best answer balances the two. In the figure, a lone wrong sample saves a little data cost but creates two boundaries; once λ is large enough (from 0.08 here) the specks are gone. But the thin structure is short too, and from λ = 0.16 it also costs more than it saves. That one figure already contains the whole topic: the recipe, the knob λ, an exact way to find the minimum (dynamic programming), and the way it fails.
The recipe: data + λ · prior
The same two-part energy appears all over the course. Only the unknown and the two terms change.
| Problem (unit) | The unknown | Data term: disagreeing with… | Prior term: penalises… |
|---|---|---|---|
| Deconvolution, regularisation | the sharp image | the measured image, after blurring | roughness or large values (Tikhonov) |
| Quadratic smoothing, TV, TV flow | the clean image | the noisy image | differences between neighbours (squared or absolute) |
| Sparsity, ISTA | coefficients in a basis | the image | the number or the sum of non-zero coefficients (ℓ1) |
| Smoothing splines | a curve | the data points | bending |
| Segmentation energy, graph cuts | a label per pixel | an intensity model per label | neighbours with different labels (boundary length) |
| Ising denoising | a binary image | the noisy binary image | the same |
| Random walker | a number per pixel | the seeds (fixed values) | differences across strong links |
| Snakes, geodesic contours | a closed curve | weak edges under the curve | stretching and bending |
| Chan–Vese | a region (level set) | grey levels far from the region’s mean | boundary length |
| Minimal paths, live-wire | a path | pixels that are not on an edge | (the path length itself) |
| Horn–Schunck flow | a vector per pixel | the brightness constancy constraint | differences between neighbouring vectors |
| Stereo | a disparity per pixel | the matching cost | jumps in disparity |
| Neural networks | the weights | the training labels (the loss) | large weights (weight decay), if any |
Two things are worth noticing. The data term is a model of the measurement (blur, noise, an intensity per class), and the prior term is a belief about the answer (smooth, piecewise constant, sparse, short-boundaried). Choosing the energy is choosing those two beliefs, and the rest of the method only finds the minimum.
λ: the one knob
Every energy on this page has a weight λ between the two terms, and λ decides the answer more than any other choice:
- λ too small: the data win; the noise stays (top left: the quadratic smoother with λ = 2 still wiggles).
- λ too large: the prior wins; real detail goes. The narrow peak, 2 units high, is 0.30 high with the quadratic prior at λ = 200 and 0.28 with TV at λ = 8.
- In between there is a best λ, but it depends on the image, the noise and what you want to measure. Here the best quadratic smoother reaches RMSE 0.18; the best TV, 0.11. The difference is the prior, not the optimiser.
How to choose λ without knowing the truth (the discrepancy principle, the L-curve, cross-validation) is the subject of regularisation and smoothing splines. Iterative methods add a second knob that acts like λ: the number of iterations. Stopping early is a form of regularisation (regularisation, Richardson–Lucy, TV flow, where flow time plays the role of λ).
Finding the minimum
There are far too many candidates to try them all: a 100 × 100 binary image has 2^{10000} labellings. Every method uses the structure of its energy to search cleverly. The course meets five families of search:
| Search (units) | Works on | Finds | Cost | Needs | Fails when |
|---|---|---|---|---|---|
| Solve a linear system (deconvolution, quadratic smoothing, random walker, splines, the semi-implicit snake step) | numbers, quadratic energy | the global minimum | one sparse solve, or one FFT for shift-invariant problems | squared terms only | edges get blurred: a squared penalty punishes big jumps too much |
| Dynamic programming (DP on paths, polar boundaries, segmentation of a chain, scanline stereo) | labels on a chain or a tree | the global minimum | labels² × length | a chain or tree: each step talks only to the next | the problem has loops (a 2D grid); then rows are solved alone and disagree (streaks) |
| Shortest paths (live-wire, fast marching) | paths between two points | the global minimum | about one visit per pixel (with a priority queue) | non-negative costs | short-cuts through weak edges; the user must place the end points |
| Minimum cut (max-flow, graph cuts, exact MAP) | two labels per pixel, any grid | the global minimum | a max-flow, roughly linear in practice | pairwise terms that favour equal labels (“submodular”) | more than two labels (then only approximate, by repeated cuts); the shrinking bias |
| Go downhill (snakes, level sets, Chan–Vese, TV flow, ISTA, Horn–Schunck, backpropagation) | anything with a slope | the nearest minimum; global only if the energy is convex | many small steps; step size limited by stability | a gradient (or a sub-gradient) | non-convex energies: the start decides; stiff problems need tiny steps |
| Pixel by pixel, or random (ICM, annealing, MCMC) | labels, any energy | ICM: a nearby minimum; annealing: close to the global one if cooled slowly | ICM: a few sweeps; annealing: thousands | only local energy differences | ICM stops early; annealing is slow |
Read the “Finds” column against “Needs”: the methods that guarantee the global minimum all demand a special structure (squares only, a chain, two labels with submodular terms). The method that accepts any energy, going downhill, guarantees only a local minimum. Much of the course’s modelling is about bending a problem into a shape that an exact method can solve.
Convex, or not
An energy is convex if it has the shape of a bowl: no dents, no second valley. Then any downhill method reaches the global minimum, and the start does not matter. Quadratic smoothing, Tikhonov deconvolution, total variation, the ℓ1 penalty and the random walker are convex: their answers are unique and reproducible (random walker, ISTA).
Snakes, geodesic active contours and Chan–Vese are not convex. Their energy has a valley at every edge the contour could settle on, and the contour rolls into the nearest one: a snake started inside the nucleus finds the nucleus, one started outside the cell finds the cell (snakes, capture range, Chan–Vese: holes and bad starts). Balloon forces, gradient vector flow and coarse-to-fine schemes are all ways of getting a better start or a wider valley.
Non-convex is not always bad: a graph cut solves a non-convex labelling problem exactly, because labels on a grid have a structure (submodularity) that a cut can exploit. Convexity matters for going downhill, not for every method.
Exact or greedy: the same energy, two searches

The same energy, two search methods. ICM (Bayesian denoising) is greedy: each pixel takes the label that is best given its neighbours as they are now, and it stops as soon as no single change helps. That is a local minimum: a group of wrong pixels that would only be worth changing together stays wrong. The minimum cut (max-flow, graph cuts) considers all labellings at once and returns the lowest energy there is.
In the figure the exact answer has the lower energy (1365 against 1407), and here also fewer wrong pixels. But the true image has energy 1413: higher than both. The model’s best answer is not the truth, only the best compromise the model can express. A better optimiser cannot fix that; only a better energy can (next section).
The same choice between exact and greedy appears on every day of Part VI: dynamic programming against a snake for a boundary (polar boundaries), a cut against a level set for the Chan–Vese energy (Chan–Vese), scanline DP against winner-take-all in stereo.
Energy and probability
Every energy here can be read as a probability, and the reading explains where the terms come from.
- Energy = −log probability. Low energy means probable. A sum of energies is a product of probabilities: the data term is the probability of the measurement given the answer (the noise model), and the prior term is the probability of the answer before measuring.
- So the minimum of the energy is the most probable answer given the data, the MAP estimate (Ising model, Bayesian denoising, regularisation: a probabilistic reading).
- Each prior term is a belief about images. Squared differences say “neighbours differ by Gaussian amounts”; absolute differences (TV) say “mostly equal, sometimes a jump”; the ℓ1 penalty says “most coefficients are zero” (quadratic smoothing and TV, sparsity). Drawing samples from the prior shows what it believes (MCMC).
- λ is then not arbitrary: it is the ratio of the noise level to the spread the prior allows. In the binary example, a flip probability of 20 % gives the data cost ln(0.8/0.2) = ln 4 ≈ 1.39.
The probabilistic reading also shows what the minimum leaves out: it is one answer, with no error bars. Sampling (MCMC) and, much later, diffusion priors give a whole distribution of answers instead.
When the minimum is the wrong answer

Finding the exact minimum does not guarantee a good answer. The energy itself can be wrong:
- Shrinking bias. A boundary term pays for length. Thin and small objects have a lot of boundary for their area, so a larger λ removes them first, and rounds corners (graph cuts: failure modes). The figure shows the same pattern as the 1D profile at the top of the page.
- The prior’s own artefacts. Squared penalties blur edges; TV turns ramps into stairs and lowers the contrast of small features (quadratic smoothing and TV, TV flow); ℓ1 shrinks every coefficient that it keeps (sparsity).
- A wrong data model. If object and background have the same grey levels, no λ helps: only seeds or a better model do (graph cuts, Chan–Vese).
- Grid artefacts. With 4 neighbours a boundary is measured in city-block length, so cuts prefer blocky shapes (graph cuts); level sets measure true length but find only a local minimum (Chan–Vese).
- λ is a choice, and a measurement made on the result depends on it. Report it, and check that your conclusion holds over a range of λ (denoising and what you may measure).
Try it
A labelling on a line (from segmentation as energy minimisation). The exact minimum, by dynamic programming, for any λ. Move λ up from 0 and find where the specks go and where the thin structure is lost; the table shows how the data term and the boundary term trade.
Quadratic, Huber and TV priors (from quadratic smoothing and total variation). Choose a prior and λ; the readout splits the energy into its data and prior parts. Try the presets TV staircases the ramp and TV shrinks the narrow peak, then find the λ with the smallest error for each prior.
More demos on the same theme: the regularisation path, interactive graph cut, denoising a binary image (ICM, annealing and the exact cut), the random walker, a snake on an image, Chan–Vese, the DP table step by step, live-wire, Horn–Schunck, stereo: the cost slice and gradient descent on a landscape.
The math
The recipe. For an unknown \mathbf x and data \mathbf y, E(\mathbf x) = D(\mathbf x; \mathbf y) + \lambda\,R(\mathbf x), \qquad \hat{\mathbf x} = \arg\min_{\mathbf x} E(\mathbf x). With p(\mathbf y \mid \mathbf x) \propto e^{-D} and p(\mathbf x) \propto e^{-\lambda R}, Bayes’ rule gives p(\mathbf x \mid \mathbf y) \propto e^{-E(\mathbf x)}: the minimiser is the MAP estimate.
Pairwise energies. Most energies here are sums over pixels and neighbouring pairs, E(\mathbf x) = \sum_p D_p(x_p) + \lambda \sum_{p \sim q} V(x_p, x_q), with V(a, b) = (a - b)^2 (quadratic), |a - b| (TV) or [a \neq b] (Potts/Ising, labels).
- Quadratic D and V: \nabla E = 0 is linear, (A^\top A + \lambda L)\,\mathbf x = A^\top\mathbf y, with L the graph Laplacian. Convex, unique, one solve.
- Chain or tree: the Bellman recursion C_i(\ell) = D_i(\ell) + \min_{\ell'}\big[C_{i-1}(\ell') + \lambda V(\ell', \ell)\big] is exact, cost O(nK^2) for n nodes and K labels.
- Two labels on any graph: exact by a minimum s–t cut when every pair term is submodular, V(0,0) + V(1,1) \le V(0,1) + V(1,0).
- Continuous, differentiable: gradient descent \mathbf x \leftarrow \mathbf x - \tau\nabla E; for a curve, the Euler–Lagrange equation turns \nabla E into a force, and the evolution \partial_t \mathbf x = -\nabla E is a PDE (snakes, level sets, TV flow).
- Non-smooth convex (\ell_1, TV): proximal steps, e.g. ISTA, \mathbf x \leftarrow \operatorname{soft}_{\tau\lambda}\big(\mathbf x - \tau\nabla D(\mathbf x)\big).
Convexity. If E is convex, every local minimum is global, and for strictly convex E it is unique. Quadratic, TV and \ell_1 energies with a convex data term are convex; snake, geodesic and Chan–Vese energies (as functions of the curve) are not.
Where to read more
In course order, the units where an energy is minimised:
- Day 5: linear deconvolution, regularisation, Richardson–Lucy; day 6: smoothing splines
- Day 10: total variation flow, inpainting; day 11: sparsity and ℓ1, ISTA, compressed sensing
- Day 25: Horn–Schunck, non-rigid registration
- Day 27: segmentation as energy minimisation, maximum flow, graph-cut segmentation
- Day 28: the Ising model, sampling and annealing, Bayesian denoising, quadratic smoothing and TV
- Day 29: the random walker
- Day 30: snakes, the snake as a linear system, active shape models
- Day 31: the level set equation, geodesic active contours, Chan–Vese
- Day 32: minimal paths by DP, polar boundaries, live-wire, fast marching
- Day 36: loss, gradient descent and backpropagation
- Day 53: stereo, bundle adjustment
See also the other topic pages, in particular removing noise and segmentation, which use many of these energies, and eigenvectors in image analysis: normalized cuts minimise a cut energy by an eigenvector.