Algorithmadvanced
Graph cut stereo
Also called Kolmogorov-Zabih stereo.
Solve stereo by minimizing an energy with data, smoothness, occlusion and uniqueness terms over sets of pixel matches, by expansion moves that are each one minimum cut.
- Solves
- Stereo matching
- Time
- O(k D (F + n)) worst · averageO(D (F + n)) best
- Space
- O(n) extra
- Where
- D = the number of disparities; F = the time of one max flow on O(n) nodes and O(n) edges; k = the number of cycles over the disparities; n = the number of pixels W H
- Model
- Real RAM
- Properties
- deterministicnot exactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Vladimir Kolmogorov, Ramin Zabih, 2001
Graph cut stereo treats stereo matching as the minimization of one energy over the whole image, and minimizes it by minimum cuts. The simplest form gives each pixel a disparity label, with a data cost for the label and a Potts cost for neighbors with different labels, and runs alpha-expansion. The form of Kolmogorov and Zabih (2001), which this page implements, goes further. Its variables are not labels but assignments, possible matches between a left pixel and a right pixel, each active or not. The energy has four parts: a data cost for each active match, a cost for each pixel of either image that is matched to nothing (an occluded pixel), a smoothness cost when one of two neighboring matches with the same disparity is active and the other is not, and an infinite cost if a pixel takes part in two matches. The last term enforces uniqueness in both images, so occlusions are found by the energy itself and treat both images alike. An expansion move on a disparity may drop old matches and switch matches of disparity on or off. The best such move is a regular binary energy, so one minimum cut finds it, by the Kolmogorov-Zabih theorem. The method stops at a configuration that no expansion move improves. It costs one maximum flow per disparity and cycle, which is much more than semi-global matching.
In plain words
We want to match pixels of the left image with pixels of the right image in the same row. Each match costs the difference of the two colors. A pixel that stays unmatched pays a fixed price, because it might be hidden in the other view. Neighboring pixels like to move together, so we pay a little when one neighbor uses a certain shift and the other does not. No pixel may be in two matches. Start with nothing matched. Then, for one shift at a time, ask which old matches to drop and which new matches with this shift to add, all at once. A minimum cut in a graph answers this question exactly. Repeat for all shifts until nothing improves.
The problem
Input. A rectified pair of images and , disparities , an occlusion cost , a smoothness weight , and a data cost cap.
An assignment matches left pixel with right pixel . A configuration is a set of active assignments. Two assignments are neighbors if they have the same disparity and their left pixels are 4-neighbors. The energy is
Here , and if both the left and the right intensity differences of the two pixel pairs are below 8, and otherwise, as in the IPOL version of the method.
Output. A unique configuration that no expansion move improves, and from it a disparity for each left pixel, or "occluded".
The algorithm
For a disparity , an -expansion of is any configuration that keeps a subset of the active assignments with disparity other than and adds any set of assignments with disparity .
KZ-STEREO(I_L, I_R, D, K, λ)- 1
A ← ∅ (every pixel occluded) - 2
repeat - 3
success ← false - 4
for each disparity α do - 5
build the binary energy of the α-expansion: a variable per active assignment with d ≠ α (keep or drop) and per assignment with d = α (on or off) - 6
A' ← the configuration of a minimizer, found by one minimum cut - 7
if E(A') < E(A) then A ← A'; success ← true - 8
until success = false - 9
return the disparity of the active assignment of each left pixel, or occluded
For line L5, a kept old assignment has and an active new one has . With this choice every term is regular. A pixel covered by an old assignment and by the new assignment gets the term with (both off: occluded), (both on: uniqueness fails) and 0 otherwise. A neighbor pair with the same disparity gets . The data costs and the pixels with only one candidate give unary terms. The code uses a number larger than the current energy in place of .
Example
One row, , , , , . The right row is the left row moved by one pixel, with a new value at the end.
| step | active assignments (left pixel, ) | |
|---|---|---|
| start | none: 8 pixels occluded | 80 |
| (1, 0) | 64 | |
| (1, 1), (2, 1), (3, 1) | 20 | |
| second cycle | no move lowers | 20 |
In the move on , only left pixel 1 and right pixel 1 have equal values, so one match is added. It costs 0 for the data, saves of occlusion cost, and pays twice, for its two neighbors at disparity 0 that stay off: . In the move on , the cut drops , because it shares left pixel 1 with , and switches on three exact matches. Left pixel 0 and right pixel 3 stay occluded, for . All 128 configurations of this row give at least 20, so here the result is the global minimum.
Correctness
The full proof is in proofs/correctness.md. The variables of a move are in one-to-one correspondence with its move space. Each part of the energy is written as a term of at most two variables: two assignments with disparity never share a pixel, and two old assignments do not either, so a pixel can only be claimed by one old and one new assignment. Every pair term is regular, so one minimum cut gives a minimizer. The current configuration is in the move space and has finite energy, so the minimizer never pays the stand-in for and is unique, and its energy is the least in the move space. The energy falls with each accepted move, so the method stops, at a configuration that no expansion move improves.
Proof: Correctness of graph cut stereo with expansion movesfull
We use the notation of the page. An assignment pairs left pixel with right pixel . A configuration is a set of active assignments, and
with all costs . is unique if no pixel is covered twice; only unique configurations have finite energy. We prove that each expansion move returns the configuration of least energy in its move space, that the algorithm stops, and that it returns a unique configuration that no expansion move improves.
The move space and its variables
Fix a unique and a disparity . Let and let be the set of all assignments of disparity . The -expansions of are the sets with and : old assignments can only be dropped, and assignments of disparity can be switched on or off freely. itself is one of them.
Give each a variable , with meaning , and each a variable , with meaning . This is a bijection between and the move space. Write for the configuration of , and for the vector of itself.
The binary energy
Build as the sum of the following terms.
- Data. For , the unary term at ; for , at .
- Pixels. Each pixel of either image is covered in only by the assignment of that covers it in (at most one, since is unique), call it , or by the one assignment of disparity that contains it, call it , if that assignment lies inside the image. Two assignments of disparity never share a pixel, because the left pixel and fix the right pixel and the other way round. Every other assignment that contains is not in . So:
- if both and exist, add the pair term with , , and . Here means both cover , and means neither does. is a number larger than , used in place of ;
- if only exists, add at ; if only exists, add at ; if neither exists, add the constant .
- Smoothness. A neighbor pair has one disparity . If , both are variables with the same meaning of , so add . If and both are in , the same term works, because both use for active. If exactly one, say , is in , then has and stays inactive, so add at . If neither is in , both stay inactive and the term is 0.
Claim 1. If is unique, . If not, .
Proof. The data, occlusion and smoothness parts of are split above by assignment, by pixel and by neighbor pair, and each part is written as a term of that takes the same value for every , except for the value in item 2. A pixel is covered twice in only if it is covered by both and : two assignments of cannot share a pixel because is unique, and two of disparity cannot either. That is exactly the case of item 2, which adds , while all other terms are nonnegative. If is unique, that case never happens and all terms equal those of .
Claim 2. Every pair term of is regular: .
Proof. Item 2 gives , and item 3 gives .
Each move is optimal
By Claim 2 and the Kolmogorov-Zabih construction (see graph-representable energies), one minimum cut on a graph with a node per variable gives a minimizer of . By Claim 1, , so is unique, and for every unique we have . Non-unique configurations have infinite energy. So has the least energy in the move space, and .
Termination and the final state
The algorithm starts from , which is unique, and replaces only by a move result of strictly lower energy, which is unique by the last section. There are finitely many configurations and the energy drops strictly at each change, so no configuration repeats and the loop stops. With integer costs it stops after at most changes. It stops after a cycle over all in which no move lowered the energy. In that cycle did not change, and each move returned the best configuration in its move space, which contains ; so no -expansion of the final has lower energy, for any .
What is not claimed
The result is a local minimum for expansion moves, not a global minimum. The factor of alpha-expansion is proved for energies with one label per site and a metric pairwise term; this energy has binary variables per assignment and a uniqueness constraint, so that bound does not apply to it as stated.
Complexity
The model is the real RAM. Let .
- One move. There are at most old assignments, one per left pixel, and at most assignments of disparity . The graph has nodes and edges, and building it costs . Then one max flow costs ; with the Boykov-Kolmogorov algorithm this is fast in practice on such grids, although its worst case bound is not polynomial in alone.
- All moves. A cycle has moves, so the total is . With integer costs, , because and each cycle except the last lowers by at least 1. In practice a few cycles suffice; this is an observation.
- Space. for the configuration and the graph of one move.
The reference code builds each move over all assignments, which costs per move, and uses Edmonds-Karp for the cut.
Properties
- Symmetric occlusions. Both images are treated alike: uniqueness holds in both, and occluded pixels in either image are part of the result.
- No ordering constraint. Unlike dynamic programming stereo, matches need not keep their order, so thin objects can be matched.
- Local minimum. The result is optimal only for single expansion moves, and the factor of alpha-expansion does not apply to this energy as it stands.
- Depends on the order. The order of the disparities and the start can change the result.
- Edges follow intensity. The smoothness weight is larger where the image is uniform, so depth edges tend to line up with intensity edges.
Variants and improvements
- Labels instead of assignments. Give each pixel a disparity, use a Potts or truncated linear smoothness term and run alpha-expansion or alpha-beta swap, as in Boykov, Veksler and Zabih (2001). This is simpler but has no symmetric occlusion model.
- Exact convex models. For a convex smoothness term on ordered disparities, Ishikawa (2003) finds the global minimum with one minimum cut on a graph with a layer per disparity; Roy and Cox (1998) gave an earlier max-flow formulation of stereo of this kind. Convex terms smooth depth edges too much.
- Choice of and . The IPOL version sets by default and chooses by a heuristic from the data costs (its Section 4.2).
- Several cameras. The same idea extends to more than two views, with visibility terms.
When to use it
Use it when accuracy at occlusion boundaries matters more than speed, for example for offline reconstruction or to produce reference results. For real time use, take semi-global matching. When you only need disparity labels with a smoothness term and no occlusion model, plain alpha-expansion on labels is simpler.
Pitfalls
- Wrong encoding of a move. If old and new assignments use the same meaning of , the uniqueness and occlusion terms are not regular and the cut is wrong. Old assignments must use for "kept", new ones for "on".
- Infinite capacities. Use a finite number larger than any finite energy for , and make sure the current configuration is a valid point of the move, so the minimum is finite.
- Accepting worse moves. Accept a move only if the energy drops; with ties the method may cycle.
- Balance of and . A small gives large occluded areas; a large forces matches in true occlusions. Scale both with the data cost and its cap.
- Large disparity ranges. Each cycle costs one cut per disparity, so the time grows with ; restrict the range or work coarse to fine.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/graph-cut-stereo/. The authors are listed in prov/A0NX9X.jsonl.
"""Graph cut stereo with occlusions, after Kolmogorov and Zabih (2001).
The pair is rectified; left pixel (u, v) may match right pixel (u - d, v)
with d in [0, D). An assignment is a = (v, u, d) with u - d >= 0, and a
configuration is the set A of active assignments. Its energy is
E(A) = sum_{a in A} Dcost(a) data
+ K * (pixels of either image covered by no a) occlusion
+ sum over neighbor pairs {a1, a2} of V(a1, a2) [exactly one active]
+ infinity if a pixel is covered twice uniqueness
Two assignments are neighbors when they have the same d and their left
pixels are 4-neighbors. Dcost(a) = min(|IL - IR|, cutoff), and V is
3 * lam when both the left and the right intensity differences of the
pair are below 8, and lam otherwise (the choice of the IPOL version).
An alpha-expansion move may drop any active assignment whose disparity is
not alpha and may switch any assignment of disparity alpha on or off. The
best move is a regular binary energy and is found by one minimum cut.
"""
from __future__ import annotations
from collections import deque
from typing import Dict, List, Optional, Sequence, Set, Tuple
Assignment = Tuple[int, int, int] # (v, u, d)
INF = float("inf")
class Problem:
def __init__(self, left, right, D: int, K: float, lam: float,
cutoff: float = 30):
self.left, self.right, self.D = left, right, D
self.H, self.W = len(left), len(left[0])
self.K, self.lam, self.cutoff = K, lam, cutoff
def valid(self, v: int, u: int, d: int) -> bool:
return 0 <= v < self.H and 0 <= u < self.W and 0 <= u - d < self.W and 0 <= d < self.D
def data(self, a: Assignment) -> float:
v, u, d = a
return min(abs(self.left[v][u] - self.right[v][u - d]), self.cutoff)
def smooth(self, a1: Assignment, a2: Assignment) -> float:
(v1, u1, d), (v2, u2, _) = a1, a2
dl = abs(self.left[v1][u1] - self.left[v2][u2])
dr = abs(self.right[v1][u1 - d] - self.right[v2][u2 - d])
return 3 * self.lam if max(dl, dr) < 8 else self.lam
def assignments(self) -> List[Assignment]:
return [(v, u, d) for v in range(self.H) for u in range(self.W)
for d in range(self.D) if u - d >= 0]
def neighbor_pairs(self) -> List[Tuple[Assignment, Assignment]]:
out = []
for (v, u, d) in self.assignments():
for (v2, u2) in ((v, u + 1), (v + 1, u)):
if self.valid(v2, u2, d):
out.append(((v, u, d), (v2, u2, d)))
return out
def energy(P: Problem, A: Set[Assignment]) -> float:
left_cov: Dict[Tuple[int, int], int] = {}
right_cov: Dict[Tuple[int, int], int] = {}
e = 0.0
for a in A:
v, u, d = a
left_cov[(v, u)] = left_cov.get((v, u), 0) + 1
right_cov[(v, u - d)] = right_cov.get((v, u - d), 0) + 1
e += P.data(a)
if any(c > 1 for c in left_cov.values()) or any(c > 1 for c in right_cov.values()):
return INF
e += P.K * (2 * P.H * P.W - len(left_cov) - len(right_cov))
for (a1, a2) in P.neighbor_pairs():
if (a1 in A) != (a2 in A):
e += P.smooth(a1, a2)
return e
def _min_cut_source_side(nn: int, edges, s: int, t: int) -> List[bool]:
"""Edmonds-Karp max flow; return the nodes that s reaches at the end."""
adj: List[List[int]] = [[] for _ in range(nn)]
to: List[int] = []
cap: List[float] = []
for (u, v, c) in edges:
adj[u].append(len(to))
to.append(v)
cap.append(c)
adj[v].append(len(to))
to.append(u)
cap.append(0)
while True:
prev = [-1] * nn
seen = [False] * nn
seen[s] = True
queue = deque([s])
while queue and not seen[t]:
u = queue.popleft()
for e in adj[u]:
if cap[e] > 0 and not seen[to[e]]:
seen[to[e]] = True
prev[to[e]] = e
queue.append(to[e])
if not seen[t]:
return seen
path = []
v = t
while v != s:
path.append(prev[v])
v = to[prev[v] ^ 1]
delta = min(cap[e] for e in path)
for e in path:
cap[e] -= delta
cap[e ^ 1] += delta
def minimize_regular_binary(n: int, unary, terms) -> List[int]:
"""Minimize sum_p unary[p][x_p] + sum of terms (p, q, A, B, C, D), with
A = theta(0,0), B = theta(0,1), C = theta(1,0), D = theta(1,1) and
A + D <= B + C, over x in {0,1}^n, by one minimum cut (x_p = 0 is the
source side)."""
s, t = n, n + 1
lin = [u1 - u0 for (u0, u1) in unary]
edges = []
for (p, q, A, B, C, Dd) in terms:
k = B + C - A - Dd
if k < 0:
raise ValueError("nonregular term")
lin[p] += C - A
lin[q] += Dd - C
if k > 0:
edges.append((p, q, k))
for p in range(n):
if lin[p] > 0:
edges.append((s, p, lin[p]))
elif lin[p] < 0:
edges.append((p, t, -lin[p]))
side = _min_cut_source_side(n + 2, edges, s, t)
return [0 if side[p] else 1 for p in range(n)]
def move_energy(P: Problem, A: Set[Assignment], alpha: int):
"""The binary energy of the alpha-expansion of A.
Returns (variables, n_old, unary, terms, constant, big). Variable i is
an assignment. The first n_old are the active ones with d != alpha:
x = 0 keeps one and x = 1 drops it. The others are all assignments
with d == alpha: x = 1 makes one active. The finite
part of the binary energy plus the constant equals E of the result;
`big` stands in for infinity."""
old = sorted(a for a in A if a[2] != alpha)
new = [a for a in P.assignments() if a[2] == alpha]
var = old + new
index = {a: i for i, a in enumerate(var)}
n_old = len(old)
big = 1 + P.K * 2 * P.H * P.W + sum(P.data(a) for a in var) \
+ sum(P.smooth(a1, a2) for (a1, a2) in P.neighbor_pairs())
unary = [[0.0, 0.0] for _ in var]
terms = []
const = 0.0
for i, a in enumerate(var): # data
if i < n_old:
unary[i][0] += P.data(a)
else:
unary[i][1] += P.data(a)
# each pixel: the old assignment and the alpha assignment covering it
cover_old: Dict[Tuple[str, int, int], int] = {}
for i, (v, u, d) in enumerate(old):
cover_old[("L", v, u)] = i
cover_old[("R", v, u - d)] = i
for v in range(P.H):
for u in range(P.W):
for side in ("L", "R"):
i = cover_old.get((side, v, u))
a_new = (v, u, alpha) if side == "L" else (v, u + alpha, alpha)
j = index.get(a_new) if P.valid(*a_new) else None
if i is not None and j is not None:
# occluded if dropped and not switched on; both: forbidden
terms.append((i, j, 0.0, big, P.K, 0.0))
elif i is not None:
unary[i][1] += P.K
elif j is not None:
unary[j][0] += P.K
else:
const += P.K
for (a1, a2) in P.neighbor_pairs(): # smoothness
w = P.smooth(a1, a2)
i, j = index.get(a1), index.get(a2)
if i is not None and j is not None:
terms.append((i, j, 0.0, w, w, 0.0))
elif i is not None: # a2 stays inactive; pay w if a1 is active
unary[i][0 if i < n_old else 1] += w
elif j is not None:
unary[j][0 if j < n_old else 1] += w
return var, n_old, unary, terms, const, big
def result_of(var, n_old, x) -> Set[Assignment]:
return {a for i, a in enumerate(var) if (x[i] == 0) == (i < n_old)}
def expansion_move(P: Problem, A: Set[Assignment], alpha: int) -> Set[Assignment]:
var, n_old, unary, terms, _, _ = move_energy(P, A, alpha) # @line L5
x = minimize_regular_binary(len(var), unary, terms) # @line L6
return result_of(var, n_old, x) # @line L6
def graph_cut_stereo(P: Problem, A: Optional[Set[Assignment]] = None,
order: Optional[Sequence[int]] = None
) -> Tuple[Set[Assignment], int]:
"""Expansion moves over all disparities until none lowers E.
Returns (active assignments, number of cycles)."""
A = set() if A is None else set(A) # @line L1
e = energy(P, A)
order = list(range(P.D)) if order is None else list(order)
cycles = 0
while True: # @line L2
cycles += 1
success = False # @line L3
for alpha in order: # @line L4
A2 = expansion_move(P, A, alpha)
e2 = energy(P, A2)
if e2 < e: # @line L7
A, e, success = A2, e2, True # @line L7
if not success: # @line L8
return A, cycles
def disparity_map(P: Problem, A: Set[Assignment]) -> List[List[Optional[int]]]:
"""The disparity of each left pixel, or None where it is occluded."""
out: List[List[Optional[int]]] = [[None] * P.W for _ in range(P.H)]
for (v, u, d) in A: # @line L9
out[v][u] = d
return out
test_graph_cut_stereo.py 152 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/graph-cut-stereo/. The authors are listed in prov/A0NX9X.jsonl.
import itertools
import random
from graph_cut_stereo import (
INF,
Problem,
disparity_map,
energy,
expansion_move,
graph_cut_stereo,
move_energy,
result_of,
)
def random_problem(rng, H, W, D):
left = [[rng.choice([10, 20, 50, 90]) for _ in range(W)] for _ in range(H)]
right = [[rng.choice([10, 20, 50, 90]) for _ in range(W)] for _ in range(H)]
return Problem(left, right, D, K=rng.choice([5, 10, 20]), lam=rng.choice([1, 2, 4]))
def random_valid_configuration(rng, P):
A, used_l, used_r = set(), set(), set()
cand = P.assignments()
rng.shuffle(cand)
for (v, u, d) in cand:
if rng.random() < 0.5 and (v, u) not in used_l and (v, u - d) not in used_r:
A.add((v, u, d))
used_l.add((v, u))
used_r.add((v, u - d))
return A
def binary_value(unary, terms, const, x):
e = const + sum(unary[i][x[i]] for i in range(len(x)))
for (p, q, A, B, C, Dd) in terms:
e += ((A, B), (C, Dd))[x[p]][x[q]]
return e
def test_move_energy_equals_the_stereo_energy():
rng = random.Random(1)
for _ in range(40):
P = random_problem(rng, rng.randint(1, 2), rng.randint(2, 4), rng.randint(2, 3))
A = random_valid_configuration(rng, P)
alpha = rng.randrange(P.D)
var, n_old, unary, terms, const, big = move_energy(P, A, alpha)
for _ in range(30):
x = [rng.randint(0, 1) for _ in var]
e = energy(P, result_of(var, n_old, x))
b = binary_value(unary, terms, const, x)
if e == INF:
assert b >= big
else:
assert b == e
for (p, q, A_, B, C, Dd) in terms:
assert A_ + Dd <= B + C # every term is regular
def test_expansion_move_is_the_best_move():
rng = random.Random(2)
for _ in range(40):
P = random_problem(rng, 1, rng.randint(2, 4), rng.randint(2, 3))
A = random_valid_configuration(rng, P)
alpha = rng.randrange(P.D)
var, n_old, _, _, _, _ = move_energy(P, A, alpha)
assert len(var) <= 10
best = min(energy(P, result_of(var, n_old, x))
for x in itertools.product((0, 1), repeat=len(var)))
A2 = expansion_move(P, A, alpha)
assert energy(P, A2) == best <= energy(P, A)
def all_configurations(P):
cand = P.assignments()
for mask in range(1 << len(cand)):
yield {cand[i] for i in range(len(cand)) if mask >> i & 1}
def test_result_is_a_local_minimum_and_never_below_the_optimum():
rng = random.Random(3)
for H, W, D in ((1, 3, 2), (1, 4, 2), (2, 3, 2), (1, 4, 3)):
for _ in range(3):
P = random_problem(rng, H, W, D)
assert len(P.assignments()) <= 12
A, cycles = graph_cut_stereo(P)
e = energy(P, A)
assert e < INF and e <= energy(P, set())
for alpha in range(D):
assert energy(P, expansion_move(P, A, alpha)) >= e
opt = min(energy(P, B) for B in all_configurations(P))
assert opt <= e
def make_pair(rng, W, H, dmap):
"""Random texture on the left; the right image shows at each column j
the left pixel u with u - d(u) = j of the largest disparity."""
left, right, truth = [], [], []
for v in range(H):
lrow = [rng.randint(0, 255) for _ in range(W)]
owner = [None] * W
for u in range(W):
j = u - dmap[v][u]
if j >= 0 and (owner[j] is None or dmap[v][owner[j]] < dmap[v][u]):
owner[j] = u
rrow = [lrow[owner[j]] if owner[j] is not None else rng.randint(0, 255)
for j in range(W)]
t = [None] * W
for j in range(W):
if owner[j] is not None:
t[owner[j]] = dmap[v][owner[j]]
left.append(lrow)
right.append(rrow)
truth.append(t)
return left, right, truth
def test_recovers_a_step_with_occlusions():
rng = random.Random(4)
W, H, D = 14, 6, 5
dmap = [[1 if u < 7 else 4 for u in range(W)] for _ in range(H)]
left, right, truth = make_pair(rng, W, H, dmap)
P = Problem(left, right, D, K=20, lam=4)
A, cycles = graph_cut_stereo(P)
disp = disparity_map(P, A)
good = total = 0
for v in range(H):
for u in range(W):
if truth[v][u] is not None:
total += 1
good += disp[v][u] == truth[v][u]
assert good >= 0.95 * total
hidden = sum(disp[v][u] is None for v in range(H) for u in range(W)
if truth[v][u] is None)
assert hidden >= 1 # some truly occluded pixels come out as occluded
def test_worked_example():
left = [[10, 50, 50, 90]]
right = [[50, 50, 90, 20]]
P = Problem(left, right, 2, K=10, lam=2)
A, cycles = graph_cut_stereo(P)
assert disparity_map(P, A) == [[None, 1, 1, 1]]
assert energy(P, A) == 20
assert energy(P, set()) == 80
first = expansion_move(P, set(), 0)
assert first == {(0, 1, 0)} and energy(P, first) == 64
assert expansion_move(P, first, 1) == A
assert min(energy(P, B) for B in all_configurations(P)) == 20
History
Roy and Cox (1998) solved stereo over a whole image with one maximum flow. Boykov, Veksler and Zabih (2001) introduced swap and expansion moves and used them for stereo with disparity labels, and Ishikawa (2003) gave an exact cut for convex priors. Kolmogorov and Zabih (2001) moved the variables from pixels to assignments, which allowed a symmetric model of occlusion with uniqueness, and showed that each expansion move of this energy is a minimum cut. Their later paper of 2004 gave the general condition, regularity, under which such moves are cuts. Kolmogorov, Monasse and Tan (2014) published a detailed description and a reference implementation in IPOL.
References
- Vladimir Kolmogorov and Ramin Zabih, Computing visual correspondence with occlusions using graph cuts, Proceedings of the Eighth IEEE International Conference on Computer Vision (ICCV 2001), volume 2, 508-515, the energy over assignments with data, occlusion, smoothness and uniqueness terms, and its minimization by expansion moves
- Vladimir Kolmogorov, Pascal Monasse and Pauline Tan, Kolmogorov and Zabih's graph cuts stereo matching algorithm, Image Processing On Line 4, 2014, 220-250, the detailed description of the energy and the graph of a move, the cap CUTOFF = 30 on the data cost, the smoothness weight 3 lambda when both intensity differences are below 8 and lambda otherwise, the default lambda = K / 5, and the choice of K in Section 4.2
- Vladimir Kolmogorov and Ramin Zabih, What energy functions can be minimized via graph cuts?, IEEE Transactions on Pattern Analysis and Machine Intelligence 26(2), 2004, 147-159, Theorem 4.1 (regular binary energies of at most two variables per term are graph representable), used for each move
- Yuri Boykov, Olga Veksler and Ramin Zabih, Fast approximate energy minimization via graph cuts, IEEE Transactions on Pattern Analysis and Machine Intelligence 23(11), 2001, 1222-1239, Section 3 (expansion moves) and Section 8 (stereo with disparity labels and a Potts smoothness term)
- Sébastien Roy and Ingemar J. Cox, A maximum-flow formulation of the N-camera stereo correspondence problem, Proceedings of the Sixth International Conference on Computer Vision (ICCV 1998), 492-499, the first formulation of stereo as one maximum flow problem over the whole image
- Hiroshi Ishikawa, Exact optimization for Markov random fields with convex priors, IEEE Transactions on Pattern Analysis and Machine Intelligence 25(10), 2003, 1333-1336, the exact minimum cut for labels on a line with a convex pairwise term, which covers stereo with a convex smoothness term
- Daniel Scharstein and Richard Szeliski, A taxonomy and evaluation of dense two-frame stereo correspondence algorithms, International Journal of Computer Vision 47(1-3), 2002, 7-42, graph cuts (GC) among the global methods of the taxonomy and in the evaluation
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 12, Depth estimation (global optimization with graph cuts)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag A0NX9X Edit this page History Report an error Markdown