|
Alpha Expansion Library
C++ library for the Alpha-Expansion graph-cut algorithm with Python bindings
|
The library includes an interactive PyQt6 application that shows the alpha-expansion algorithm working step by step on two problems: image segmentation and community detection.
The app needs PyQt6, numpy, Pillow, networkx and matplotlib, all listed in requirements.txt.
From the project root (with the virtual environment active):
A window opens with a sidebar on the left and a canvas on the right.
The app opens in this mode. You load an image and draw seed strokes to mark regions, then the algorithm segments the image based on those strokes.
Workflow:
SequentialStrategy (up to 20 cycles) and go straight to the final result.Once you click Initialize you cannot add or remove labels or change strokes. Start over with Initialize after switching the mode or reloading an image.
Click Community Detection at the top of the sidebar to switch modes. Here you partition a social network graph into communities.
Workflow:
Click Load Custom Graph… to open a file dialog, then set the number of communities and the smoothness weight (lambda) in the dialog that follows.
Supported file formats:
| Format | Extension | Description |
|---|---|---|
| Edge list | .edgelist, .txt | One node1 node2 pair per line; lines starting with # are comments |
| GraphML | .graphml | XML-based format exported by Gephi, igraph, and similar tools |
| GML | .gml | Graph Modelling Language, supported by most graph libraries |
Tuning parameters:
demo/graphs/ contains two ready-to-use edge lists:
| File | Nodes | Edges | Suggested settings |
|---|---|---|---|
two_cliques.edgelist | 12 | 31 | 2 communities, lambda 10–20 |
three_cliques.edgelist | 15 | 33 | 3 communities, lambda 5–15 |
two_cliques.edgelist contains two 6-node cliques joined by a single bridge edge — the algorithm should recover the two cliques as perfect communities in one step. three_cliques.edgelist contains three 5-node cliques arranged in a ring, each pair connected by one bridge edge.
| Control | Description |
|---|---|
| Segmentation / Community Detection | Switch problem mode. Resets state. |
| Initialize | Build the energy model from the current configuration. |
| Step | Run one alpha-expansion move (cycles through labels 0, 1, ...). |
| Run to Convergence | Run SequentialStrategy up to 20 cycles. |