“Neighbouring pixels usually agree” is a statement about probability. This unit turns it into a model: an energy that counts disagreements, and a rule that turns energy into probability.
The Ising model: \pm 1 “spins” on a grid that want to agree with their neighbours.
The Gibbs distribution: low energy = likely; temperature says how strongly.
The partition functionZ: easy for 16 states, hopeless for an image, easy again for a chain.
The link back to graph cuts: the Ising energy is the segmentation energy.
Slides titled The math give the formulas and proofs; the ideas are complete without them.
Each pixel of the noisy image was flipped with probability 0.2. Looked at alone, a pixel cannot be trusted.
But true images are made of regions: a pixel usually has the same value as its neighbours. An isolated black pixel in a white area is unlikely to be real.
Wanted: a number for “how plausible is this whole image”, high for images with few disagreeing neighbours.
The Ising model
Each pixel p carries a spins_p = +1 or -1 (object / background, or “up” / “down”). Two numbers set the preferences:
Coupling J > 0: every pair of 4-neighbours that agrees lowers the energy by J; every pair that disagrees raises it by J.
Field h: every +1 lowers the energy by h (and every -1 raises it): a preference for one value.
The story it came from (Ising, 1925): a magnet. Each atom is a small arrow that wants to point like its neighbours; heat shakes them. Only the formulas matter here.
J < 0 (an antiferromagnet) rewards disagreement: the best states are checkerboards. Not useful for images, but a good check of understanding.
From energy to probability
The Gibbs distribution (also called Boltzmann distribution) turns every energy into a probability:
p(\mathbf s) = \frac{e^{-E(\mathbf s)/T}}{Z}, \qquad Z = \sum_{\text{all states } \mathbf s} e^{-E(\mathbf s)/T}
Low energy = high probability. The exponential makes a state with 4 units less energy e^{4/T} times more likely.
Z (the partition function) only makes the probabilities sum to 1.
Ratios need no Z:\dfrac{p(\mathbf a)}{p(\mathbf b)} = e^{-(E_a - E_b)/T}. Comparing two images only needs their energy difference. This sentence is the key to the next unit.
The math: why an exponential?
Two requirements fix the form p \propto e^{-E/T}:
Only energy differences matter. Adding a constant c to every energy must not change the probabilities: e^{-(E + c)/T} = e^{-c/T}e^{-E/T}, and the factor e^{-c/T} cancels against Z.
Independent parts multiply. Two separate lattices with E = E_1 + E_2 should be independent: p = p_1 p_2. Only the exponential turns sums into products: e^{-(E_1 + E_2)/T} = e^{-E_1/T}e^{-E_2/T}, and Z = Z_1 Z_2.
Equivalently, -T\log p(\mathbf s) = E(\mathbf s) + T\log Z: energy is negative log-probability, up to a constant. The literature often writes \beta = 1/T (and also \beta for J); we keep T and J, and later \lambda.
Temperature: how strongly energy matters
The temperature T (in energy units) is a knob:
T \to 0: e^{-E/T} is overwhelmingly largest for the lowest energy. All probability goes to the ground states (the energy minima).
T \to \infty: e^{-E/T} \to 1 for every state. All states are equally likely: the energy no longer matters.
In between: low energies are preferred, higher ones still happen.
Energy minimisation is the T \to 0 limit of probability. “Find the lowest energy” (graph cuts) and “describe the likely states” (this day) are the same model, read at different temperatures.
The 2 × 2 lattice of the next slide (J = 1): cold, the 2 ground states take everything; hot, the 12 states at E = 0 win because there are more of them.
The 2 \times 2 lattice by hand
J = 1, h = 0, free boundary: 4 neighbour pairs. Orange = +1, blue = -1.
2 aligned states: all 4 pairs agree, E = -4. 2 checkerboards: all disagree, E = +4. The other 12: two pairs agree, two disagree, E = 0.
Z = 2e^{4/T} + 12 + 2e^{-4/T}. At T = 1: 109.20 + 12 + 0.04 = 121.23.
p(\text{both aligned states}) = 109.20 / 121.23 = 0.90; each one 0.45. At T = 4: Z = 18.17 and only 0.30.
Try it: every state of a tiny lattice
The partition function is the hard part
Z sums over every state.
lattice
states 2^n
2 \times 2
16
3 \times 3
512
4 \times 4
65 536
256 \times 256
2^{65536} \approx 10^{19728}
All 512 states of the 3 \times 3 lattice, sorted by energy. The 4 \times 4 lattice would need 128 such pictures.
For an image, Z cannot be computed, and so neither can the probability of one particular image.
What still works without Z: ratios (next unit: sampling), and the lowest energy (graph cuts, unit 3).
A chain is easy: sum from left to right
For pixels on a line (or a ring) there is a shortcut, the same trick as dynamic programming on a chain (graph-cut day, segchain), with “minimum” replaced by “sum”:
Walk along the chain. Keep two numbers: the total weight of all partial chains ending in +1, and of those ending in -1.
Each new pixel updates both with a 2 \times 2 table of weights e^{-(\text{pair energy})/T}: the transfer matrix.
n pixels cost n small steps instead of 2^n terms.
In 2D, the rows interact with each other in every column; no such shortcut exists in general.
The chain sum as pseudocode
plus, minus = 1, 1 # first pixel: one partial chain ending in +1, one in −1
a = e^(J/T), d = e^(−J/T) # weight of an agreeing / disagreeing pair (h = 0)
for each next pixel:
plus, minus = plus·a + minus·d, plus·d + minus·a
Z = plus + minus
Each step needs only the two numbers of the previous pixel: n pixels, n steps.
With J = 1, T = 1 and four pixels: 1 o 3.09 o 9.52 o 29.39 in each row, Z = 58.79 (the figure).
The math: the transfer matrix
A ring of n spins, energy E = -J\sum_i s_i s_{i+1} - h\sum_i s_i (with s_{n+1} = s_1). Split the field evenly over the two pairs of each spin:
The constant does not depend on the state: same probabilities, same minimum. The graph-cut day’s “probabilistic view” slide read the same equation the other way: P(L \mid I) \propto e^{-E(L)}, i.e. T = 1.
Summary
The Ising model: spins \pm 1 on a grid; the coupling J rewards agreeing neighbours, the field h prefers one value.
The Gibbs distributionp(\mathbf s) \propto e^{-E(\mathbf s)/T}: low energy is likely; ratios of probabilities need only energy differences.
Temperature: T \to 0 keeps only the lowest energies (energy minimisation), T \to \infty makes everything equally likely.
The partition functionZ is easy for tiny lattices and for chains (transfer matrix), impossible for images.
The Ising energy is the binary segmentation energy, with \lambda = 2J and the field as data term.