You are on page 1of 67

Introduction to

Min-Cut/Max-Flow Algorithms
Hong Chen
UCLA CIVS
Outline
Generic framework of graph cut method
Introduction to graph,flow and cut
The equivalence of max-flow/min-cut
Maximum flow algorithms
Labeling as a graph problem
Each pixel = node
Add two nodes F & B
Labeling: link each pixel to either F or B
F
B
F
B
QuickTime?and a
TIFF (LZW) decompressor
are needed to see this picture.
F
F F
F B
B
B
Desired result
Data term
Put one edge between each pixel and both F & G
Weight of edge = minus data term
Dont forget huge weight for hard constraints
Careful with sign
B
F
Smoothness term
Add an edge between each neighbor pair
Weight = smoothness term
B
F
Min cut
Energy optimization equivalent to graph min cut
Cut: remove edges to disconnect F from B
Minimum: minimize sum of cut edge weight
B
F
cut
Min cut
Graph with one source & one sink node
Edge = bridge
Edge label = cost to cut bridge
What is the min-cost cut that separates source from
sink
sink source
cut
Min cut <=> labeling
In order to be a cut:
For each pixel, either the F or G edge has to be cut
In order to be minimal
Only one edge label
per pixel can be cut
(otherwise could
be added)
B
F
cut
Min cut <=> optimal labeling
Energy = -

weight of remaining links to F & B
+

weight cut neighbor links
B
F
cut
-data
Min cut <=> optimal labeling
Energy = -

all weights to F & B
+

weight of cut links to F & B
+

weight cut neighbor links
Minimized when last 2
terms are minimized
B
F
cut
General Framework of Graph Cut
Method in Computer Vision
vision problem
Labeling problem
by Energy Minimization
other problem
Example: Interactive image segmentation
General Framework of Graph Cut
Method in Computer Vision
vision problem
Labeling problem
by Energy Minimization
Multiple-Label
Binary Label
Mini-cut problem
General Framework of Graph Cut
Method in Computer Vision
vision problem
Labeling problem
by Energy Minimization
Binary Label
Mini-cut problem
Global optimization in
polynomial time
Max-flow problem
General Framework of Graph Cut
Method in Computer Vision
vision problem
Labeling problem
by Energy Minimization
Multiple-Label
Binary Label
Mini-cut problem
Max-flow problem
General Framework for Graph
Cut Method in Computer Vision
vision problem
Labeling problem
by Energy Minimization
Multiple-Label
Binary Label
Mini-cut problem
Max-flow problem
Outline
Generic framework of graph cut method
Introduction to graph,flow and cut
The equivalence of max-flow/min-cut
Maximum flow algorithms
An Example of Max-flow
Applications
Network
Router a
100M
10M
10M
20M
10M
Source
Sink
s
t
b
10
20
100
10
10 10
a
Router b
An Example of Min-Cut
Applications
Bridges
River
s
a
b
t
2
4
5
1
3
s
t
a
b
2
5
4
3
1
1
s-t Graph
A source node and a sink node
Directed edge (Arc) <i,j> from node i to node j
Each arc <i,j> has a nonnegative capacity cap(i,j)
for non-exist arcs
( , ) 0 cap i j =
, G V E =< >
s
3
3
2
1
6
t
( , ) cap i j
i
j
Flow in s-t Graph
Flow is a real value function that assign a real
value to each arc <i,j> under :
Capacity constraint :
Mass balance constraint:
is the value of flow
f
( , ) ( , ) f i j cap i j
, ,
0 { , }
( , ) ( , ) | |
| |
i j E k i E
i V s t
f i j f k i f i s
f i t
< > < >

= =


| | f
( , ) f i j
f
s-t Flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Function flow: A ! R
Flow of arc " arc capacity
Flow is non-negative
For all vertex expect s,t
Incoming flow
= Outgoing flow
s-t Flow
Function flow: A ! R
flow(a) " c(a)
Flow is non-negative
For all vertex expect s,t
Incoming flow
= Outgoing flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
Function flow: A ! R
flow(a) " c(a)
For all vertex expect s,t
Incoming flow
= Outgoing flow
flow(a) # 0
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

Incoming flow
= Outgoing flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

= Outgoing flow
!
(u,v)!A
flow((u,v))
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

= !
(v,u)!A
flow((v,u))
!
(u,v)!A
flow((u,v))
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

E
flow
(v) = 0
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
s-t Flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

E
flow
(v) = 0
3
1 10
3
4
!
s-t Flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

E
flow
(v) = 0
-1
-1
-1
!
s-t Flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Function flow: A ! R
flow(a) " c(a)
flow(a) # 0
For all v ! V \ {s,t}

E
flow
(v) = 0
1
1
1
"
Value of s-t Flow
Outgoing flow of s
- Incoming flow of s
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Value of s-t Flow
!
(s,v)!A
flow((s,v))
- !
(u,s)!A
flow((u,s))
-E
flow
(s) E
flow
(t)
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Value of s-t Flow
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
!
(s,v)!A
flow((s,v))
- !
(u,s)!A
flow((u,s))
-E
flow
(s) E
flow
(t)
1
1
1
Value = 1
Flow in s-t Graph
maximum flow is the flow has maximum value among
all possible flow functions
s
t
3/3
2/2
3/6
0/1
i
j
( , ) / ( , ) f i j cap i j
An example of flow
2/3
s-t Cut
A cut is a partition of node set V which has two
subsets S and T
A cut is a s-t cut iif
, s S t T
T
s
t
3
3
2
1
6
S
s
t
3
3
2
1
6
S
T
s-t cut
not a s-t cut
Cut
v
1
v
2
v
3
v
4
10
5
3
2
Let U be a subset of V
C is a set of arcs such that
(u,v) ! A
u ! U

v ! V\U

D = (V, A)
C is a cut in the digraph D
Cut
v
1
v
2
v
3
v
4
What is C?
D = (V, A)
U

V\U
{(v
1
,v
2
),(v
1
,v
4
)} ?
{(v
1
,v
4
),(v
3
,v
2
)} ?
{(v
1
,v
4
)} ?
"
10
5
3
2
Cut
v
1
v
2
v
3
v
4
What is C?
D = (V, A)
U

V\U

{(v
1
,v
2
),(v
1
,v
4
),(v
3
,v
2
)} ?
{(v
1
,v
4
),(v
3
,v
2
)} ?
{(v
4
,v
3
)} ?
"
10
5
3
2
Cut
What is C?
D = (V, A)
V\U

U

{(v
1
,v
2
),(v
1
,v
4
),(v
3
,v
2
)} ?
{(v
1
,v
4
),(v
3
,v
2
)} ?
{(v
3
,v
2
)} ?
"
v
1
v
2
v
3
v
4
10
5
3
2
Cut
C = out-arcs(U)
D = (V, A)
v
1
v
2
v
3
v
4
10
5
3
2
Capacity of Cut
Sum of capacity of all
arcs in C
v
1
v
2
v
3
v
4
10
5
3
2
Capacity of Cut
!
a ! C
c(a)
v
1
v
2
v
3
v
4
10
5
3
2
Capacity of Cut
3
v
1
v
2
v
3
v
4
U

V\U
10
5
3
2
Capacity of Cut
15
V\U

U

v
1
v
2
v
3
v
4
10
5
3
2
s-t Cut
A source vertex s
C is a cut such that
s ! U

t ! V\U
D = (V, A)
C is an s-t cut
A sink vertex t
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Capacity of s-t Cut
!
a ! C
c(a)
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Capacity of s-t Cut
5
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Capacity of s-t Cut
17
v
1
v
2
v
3
v
4
6
5
3
s

t

1 8
7
3
2
Capacity of s-t Cut (cost)

Minimum cut is the s-t cut whose capacity is minimum


among all possible s-t cuts
ca
, , ,
([ , ]) ( , )
i j E i S j T
p S T cap i j
< >
=

s
t
3
2
1
6
S
T
([ , ]) 2 3 5 cap S T = + =
3
Flow Across s-t Cut
, , , , , ,
([ , ]) ( , ) ( , )
i j i j
i j E v S v T j i E v S v T
f S T f i j f j i
< > < >
=

T
s
t
1/3
1/3
2/2
1/1
0/6
S
([ , ]) 2 1 1 2 f S T = + =
Properties I
For any s-t cut and flow, the capacity of s-t cut is the
upper-bound of the flow across the s-t cut
, , ,
, , ,
, , , , , ,
([ , ])
( , )
( , )
( , ) ( , )
([ , ])
i S i j E j T
i S i j E j T
i S i j E j T i S j i E j T
cap S T
cap i j
f i j
f i j f j i
f S T
< >
< >
< > < >
=


Properties II
For any s-t cut, the value of flow across the cut
equals the value of the flow
, ,
, , , , , , , ,
, , , , , , , , ,
| | [ ( , ) ( , )]
[ ( , ) ( , ) ( , ) ( , )]
( , ) ( , ) ( , ) ( , )
i S i j E j i E
i S i j E j S i j E j T j i E j S j i E j T
i S i j E j S i S i j E j T i S j i E j S i S
f f i j f j i
f i j f i j f j i f j i
f i j f i j f j i f j i
< > < >
< > < > < > < >
< > < > < >
=
= +
= +



, , ,
, , , , , ,
( , ) ( , )
([ , ])
j i E j T
i S i j E j T i S j i E j T
f i j f j i
f S T
< >
< > < >
=
=


Properties III
For any s-t cut and any flow, the capacity of s-t cut is
the upper-bound of value of the flow
([ , ]) ([ , ]) f S T cap S T
([ , ]) | | f S T f =
| | ([ , ]) f cap S T
Outline
Generic frame work of Graph cut
Introduction to graph,flow and cut
The equivalence of max-flow/min-cut
Maximum flow algorithms
Residual Graph G
r
The non-negative value means maximum additional flow
on the arc <i,j>
Add flow in inversed arc means reduce flow in current arc
From flow to residual graph
Deduct flow from capacity
Add inverse arc of current flow
Current Flow
s
t
1/3
1/3
2/2
1/1
0/6
Residual Graph
s
t
2
1
6
2
2
1
1
( , ) r i j
Equivalence of Maximum Flow
and Minimum Cut
Theorem: If f is a flow function of a s-t graph,then the
follows statements are equivalent:
A. f is a maximum flow
B. there is a s-t cut that its capacity equals to the value of f
C. The residual graph contains no directed path from source
to sink
Equivalence of Maximum Flow
and Minimum Cut
If B: there is a s-t cut that its capacity equals to the value of f
Then A: f is a maximum flow
The capacity of any s-t cut is upper bound of the value of any flow.
So if there is a s-t cut that its capacity equals to the value of flow f,
then the value of f is also the upper bound of any flow. That means
f is a maximum flow.
Equivalence of Maximum Flow
and Minimum Cut
If A: f is a maximum flow
Then C: The residual graph contains no directed path from source to sink
If has an path from source to sink, we augment the flow of this path
by an amount equal to the minimum residual capacity of the edges
along this path. So the original flow f is not a maximum flow. So if f
is a maximum flow, then no augmenting path can exist.
Additional flow
Residual Graph
4
2
t
2
1
1
6
1
3
1
2
1
1
3
s
1
4
t
1
s
3
Equivalence of Maximum Flow
and Minimum Cut
If C: The residual graph contains no directed path from source to sink
Then B: there is a s-t cut that its capacity equals to the value of f
From the source, the residual graph can be separate into reachable
S and non-reachable T, it must be a s-t cut. And there is no arc
from S to T in the residual graph. So f(i,j)=cap(i,j) for any arc from S
to T and f(j,i)=0 for arc from T to S. In this case, cap([S,T])=f([S,T]),
as we know f([S,T])=|f|, so cap([S,T]) = |f|
s
t
1
3
2
1
3
2
3
s
t
2/3
3/3
2/2
0/1
3/6
Residual Graph
Minimum Cut
S
T
S
T
Maximum Flow
Outline
Generic framework of Graph cut
Introduction of graph,flow and cut
The equivalence of max-flow/min-cut
Maximum flow algorithms
Maximum Flow Algorithms
Augmenting Path (Ford-Fulkerson)
ford-fulkerson
Capacity scaling
Successive shortest path
Layered Network
..
Push/Relabel
Push/relabel
FIFO preflow-push
Highest-label preflow-push
..
( ) O nmU
( log ) O nm U
2
( ) O n m
2
( ) O n m
2
( ) O n m
3
( ) O n
2
( ) O n m
Augmenting Path Algorithm
(Ford-Fulkerson)
Computer the Residual Graph
Repeat
Find a directed path in from the source to the
sink by depth-first search
Augment the flow of this path by an amount equal
to the minimum residual capacity of the edges
along this path
Update the residual graph
Until no augmenting path exists
r
G
r
G
An Example of Augmenting Path
Algorithm - I
Augmenting Path Residual Graph
4
t
3
3
2
1
6
2
s
t
2
1
1
6
1
3
1
1
s
3
Current Flow
s
t
0/3
1/3
1/2
1/1
0/6
An Example of Augmenting Path
Algorithm - II
Residual Graph
Augmenting Path
Current Flow
4
2
t
2
1
1
6
1
3
1
s
t
2
1
6
2
2
1
1
1
s
3
s
t
1/3
1/3
2/2
1/1
0/6
An Example of Augmenting Path
Algorithm - III
Residual Graph
Augmenting Path
s
t
2
1
5
2
1
1
2
1
Current Flow
4
t
2
1
6
2
2
1
1
2
1
s
3
s
t
2/3
1/3
2/2
0/1
1/6
An Example of Augmenting Path
Algorithm - IV
Residual Graph
Augmenting Path
Current Flow
s
1
3
2
1
3
2
3
t
s
t
2/3
3/3
2/2
0/1
3/6
4
3
t
2
1
5
2
1
1
2
1
2
1
s
Complexity of Basic Augmenting
Path Algorithm
n is the number of nodes
m is the number of arcs
U is the maximum capacity
(all capacity is integer)
( ) O nU
Augmentations
( ) O nmU
Runtimes

You might also like