|
Alpha Expansion Library
C++ library for the Alpha-Expansion graph-cut algorithm with Python bindings
|
The library is built around four classes:
EnergyModel owns the graph structure (neighbor lists) and the energy function (unary and pairwise costs). It also holds the current label assignment, which strategies update after each move.
The cost type T can be int32_t, float or double. Integer costs are generally preferred for image segmentation (faster and exact). Floating-point works better when cost functions involve continuous quantities.
AlphaExpansion performs a single expansion move. Given a label alpha, it:
alpha (the active nodes).alpha or keep its current label.MaxFlowSolver.AlphaExpansion holds a non-owning reference to its EnergyModel. The model must outlive the optimizer.
A factory function (SolverFactory) is used instead of a single solver instance, because a new solver must be created for every expansion move.
MaxFlowSolver is a pure virtual interface. The library provides two implementations:
| Class | Backend | Available |
|---|---|---|
BKSolver<T> | Boykov-Kolmogorov | always |
ORToolsSolver<T> | Google OR-Tools | -DUSE_OR_TOOLS=ON |
To use a different backend, implement the virtual methods and pass a factory lambda to AlphaExpansion. See the Custom Solver guide.
ExpansionStrategy is a pure virtual interface that controls the iteration loop. It calls AlphaExpansion::perform_expansion_move() in whatever order it defines and returns the number of cycles completed.
| Class | Behavior |
|---|---|
SequentialStrategy<T> | Labels 0, 1, ..., K-1 in fixed order each cycle |
GreedyStrategy<T> | Best-energy label first each cycle (O(K) solves/cycle) |
RandomizedStrategy<T> | Random shuffle of labels each cycle |
To implement a custom strategy, see the Custom Strategy guide.