Binary MRF Optimization using Min-Cut Setup
Problem Statement
In image processing, minimizing the energy function of a Binary Markov Random Field (MRF) is a common method for tasks like image denoising or segmentation. The goal is to assign a binary label () to every pixel to minimize the total energy:
where is the unary cost (fitting the label to local data) and is the pairwise cost (enforcing smoothness/prior constraints).
A fundamental technique for solving this optimization problem exactly when the pairwise costs are submodular is by transforming it into a Minimum Cut (Min-Cut) problem on a constructed graph.
Your Task
Implement the graph construction step for a simplified 2×1 image (two pixels, and ) where is adjacent to . Given the unary costs and the fixed pairwise costs, calculate the capacities of the required links in the Max-Flow/Min-Cut graph:
- Source-to-w₁ link capacity:
- w₁-to-Sink link capacity:
- Source-to-w₂ link capacity:
- w₂-to-Sink link capacity:
- w₁-to-w₂ directional capacity:
- w₂-to-w₁ directional capacity:
Pairwise Costs
Assume the pairwise costs are fixed as:
- (cost if w₁=0, w₂=1)
- (cost if w₁=1, w₂=0)
- and (zero-diagonal form)
Graph Construction Rules
Using the standard convention:
- — Cost if wₙ is separated from source (assigned wₙ=1)
- — Cost if wₙ is separated from sink (assigned wₙ=0)
- C(w₁, w₂) = C(w₂, w₁) = P(0,1) = P(1,0) — Symmetric capacity for disagreement cost
Example
U1(0)=5.0, U1(1)=1.0, U2(0)=2.0, U2(1)=6.0
[1.0, 5.0, 6.0, 2.0, 4.0, 4.0]
- Inputs: four unary costs, two per pixel. and say pixel is much cheaper as label 1; and say prefers label 0. The pairwise disagreement cost is fixed at .
- Terminal links for : and . Cutting puts on the sink side (label 1), so that link carries ; cutting keeps it on the source side (label 0), so it carries . That is why the two values swap places relative to the input order.
- Terminal links for : likewise and .
- Neighbour links: both directions get the disagreement cost, .
- Output:
[1.0, 5.0, 6.0, 2.0, 4.0, 4.0], in the order source/sink for , source/sink for , then the two neighbour links. - Sanity check: with the source side meaning label 0, the labeling cuts , and , costing , exactly . Notice that the cut cost equals the MRF energy for every labeling, which is why the min-cut gives the optimal labels.
Constraints
- Uₙ(wₙ) inputs are floats ≥ 0
- Output capacities must be floats
- The pairwise costs P₁₂(0,0) = 0 and P₁₂(1,1) = 0 are fixed
- P₁₂(0,1) = P₁₂(1,0) = 4.0 (representing the smoothness cost for disagreement)