CS3000:Algorithms&DataJonathanUllman
Lecture17:MoreApplicationsofNetworkFlow
March25,2020
ImageSegmentation
• Separateimageintoforegroundandbackground• Wehavesomeideaof:• whetherpixeliisintheforegroundorbackground• whetherpair(i,j)arelikelytogotogether
backgroundforeground
e me d
I o.o II Du
Set of pixels n xEm
e g middlepixelsmore
likely tobe
foreground
ImageSegmentation
• Input:• anundirectedgraph! = ($, &);$ =“pixels”,& =“pairs”• likelihoods(), *) ≥ 0 forevery- ∈ $• separationpenalty/)0 ≥ 0 forevery -, 1 ∈ &
• Output:• apartitionof$ into 2, 3 thatmaximizes
4 2, 3 = 6()�
)∈8+6*0
�
0∈:− 6 /)0
�
),0 ∈<=>?8@AB:
Assume all values in the graph
q ofme 9 m externally
a likelihood of foreground
foregroundI
background
i jPij
ReductiontoMinCut• DifferencesbetweenSEGandMINCUT:• SEGasksustomaximize,MINCUTasksustominimize
max8,: 6()�
)∈8+6*0
�
0∈:− 6 /)0
�
),0 ∈<=>?8@AB:
min8,: 6*)�
)∈8+6(0
�
0∈:+ 6 /)0
�
),0 ∈<=>?8@AB:
yShort for Image Segmentation
DMin f x
may f x
Fon Fa FB bi PiiA
DEbtv A B
am Ea ai E bi Epi
I
ReductiontoMinCut• DifferencesbetweenSEGandMINCUT:• SEGallowsanypartition,MINCUTrequiresH ∈ 2,I ∈ 3
SE Af t C B
EE B O_0
se Aqd tqg
Solution Add dummy nodes
s and t to the graph
ReductiontoMinCut• DifferencesbetweenSEGandMINCUT:• SEGhasedgesbetweenAandB,MINCUTconsidersedgesfromAtoB
min8,: 6 /)0�
),0 ∈<JKLM8>L:
min8,: 6*)�
)∈8+6(0
�
0∈:+ 6 /)0
�
),0 ∈<=>?8@AB:
A B
solution yes
Replace undirected oe go no
edge Cii ul Ilyi j and j i B A
both with capacity pi i0 0j Mandy.netjsnmbth
ReductiontoMinCut• DifferencesbetweenSEGandMINCUT:• SEGhastermsforeachnodeinA,B,MINCUTonlyhastermsforedgesfromAtoB
min8,: 6 /)0�
),0 ∈<JKLM8>L:
min8,: 6*)�
)∈8+6(0
�
0∈:+ 6 /)0
�
),0 ∈<=>?8@AB:MIMI
so
sit inedges from s Izand t 7ft capacity we want
t.IT Etb
ReductiontoMinCut• Howshouldthereductionwork?• capacityofthecutshouldcorrespondtothefunctionwe’retryingtominimize
min8,: 6*)�
)∈8+6(0
�
0∈:+ 6 /)0
�
),0 ∈<JKLM8>L:
Replace max with men
Replace undirected edges w pairs of directededge
Add dummy nodes Stbax
Add dummy edges s x x e
Step1:TransformtheInput
InputG,{a,b,p}forSEG
InputG’forMINCUT
ourReplace Max with man
Replace undirected edges w pairs of directededges
Add dummy nodes Stbax
Add dummy edges s x x e
Total Time 0 mtn
Step2:ReceivetheOutput
Solve
InputG’forMINCUT
Output(A,B)forMINCUT
u u v x3were the
original graph
1
A B is a mmmm satat in G
T IneSolve mascot on a
Agraph with n 12 nodes
B and 2Mt 2n edgesso 0Cmn t.me
Step3:TransformtheOutput
Output(A,B)forSEG
Output(A,B)forMINCUT
Return partition
A fu v3B f w x 3
O
OA
B
Time 0 n
ReductiontoMinCut• correctness?
• runningtime?
Every patron A B of the original nodes
corresponds to an s C at A 0953 Bu Et3
For every sf we Auss3 Bust 3 the
capacity is ftp.biifrsaitif.EIEEJPTxatg whatSEG wants to
Total Time 0 mn m.nm.ae
Bottleneck is solving minimum at
ImageSegmentation
• Wanttoidentifycommunitiesinanetwork• “Community”:asetofnodesthathavealotofconnectionsinsideandfewoutside
Mammootty Densest Subgraph
ofedges inside
070
madeHr
i
DensestSubgraph
• Input:• anundirectedgraph! = $, &
• Output:• asubsetofnodes2 ⊆ $ thatmaximizesO < 8,8
|8|
2 ttmsideA
of nodes in A
1
F ASA set of edges w both endpoints in A
ECA B set of edges w one endpoint in A one MB
DS uses an undirectedgraph
Ds ieesuscnooseayseiafmmiIT.es ie
I
iOS O
Add dummy nodes s t
Same transformations as SEG
Need to transform the objective function
DS MINCUT
2 IECA A I E C i jCi j EE
I Al f IEA jtBIs it
FA ai Eff bite cijbtw A B
usang dummy edges
ReductiontoMinCut• Differentobjectives
• maximizeO < 8,88 vs.minimize & 2, 3
• SupposeO < 8,88 ≥ Qandseewhatthatimplies
⇔ 2 & 2, 2 ≥ Q 2⇔ ΣU∈8 deg Y − & 2, 3 ≥ Q 2⇔ ΣU∈Z deg Y − ΣU∈: deg Y − & 2, 3 ≥ Q 2⇔ 2 & − ΣU∈: deg Y − & 2, 3 ≥ Q 2⇔ ΣU∈: deg Y + Q 2 + & 2, 3 ≤ 2 &⇔ ΣU∈: deg Y + ΣU∈8Q + Σ\JKLM8>L:1 ≤ 2 &
If I can ask yes no
questions Is the DS der w
f
Em
than 8 then I can findthe densest subgraph
DO E meoof
ReductiontoMinCut• Differentobjectives
• maximizeO < 8,88 vs.minimize & 2, 3
• SupposeO < 8,88 ≥ Qandseewhatthatimplies
⇔ 2 & 2, 2 ≥ Q 2⇔ ΣU∈8 deg Y − & 2, 3 ≥ Q 2⇔ ΣU∈Z deg Y − ΣU∈: deg Y − & 2, 3 ≥ Q 2⇔ 2 & − ΣU∈: deg Y − & 2, 3 ≥ Q 2⇔ ΣU∈: deg Y + Q 2 + & 2, 3 ≤ 2 &⇔ ΣU∈: deg Y + ΣU∈8Q + Σ\JKLM8>L:1 ≤ 2 &
If I can ask yes no
questions Is the DS der w
f
Em
than 8 then I can findthe densest subgraph
DOEadegenTEAdegcul jfdegh E.de o
IFudegCu TEodesh
IECAB IE L
Sla efromA B
3 SvC A
Ifs degli t Fa s t Ee L
fromA to B
If the value is E 21 El
then the subgraph A has
2 IEEa AlTai 38
ReductiontoMinCut
ΣU∈: deg Y + ΣU∈8Q + Σ\JKLM8>L:1 ≤ 2 &000
Isdegg
I s
degce
Thisgraphhas mmeat ELIE if andonly if F a subgraphof dusty 8