CS 7 Algorihm Fll 24 Dvid Wgner /3 Noe The min-u problem Le G = (V,E) be direed grph, wih oure verex V nd ink verex V. Aume h edge re lbelled wih o, whih n be modelled o funion : E N h oie non-negive inegrl o (e) o every edge e E. A (,)-u (L,R) i wy of priioning he verie ino wo dijoin e L nd R, o h L R = V, L, nd R. (From here on, we will imply ll hi u.) The o of u i he um of he o of he edge from L o R: (L,R) = u L,v R (u,v) E The min-u problem i o find minimum-o u in G. Exmple (u,v). Conider he following grph: b Here i minimum-o u in h grph: b CS 7, Fll 24, /3 Noe
Thi u i (L,R), where L = {,,b} nd R = {,}. The o of hi u i, ine i u he edge (b,), whih h o. Here i noher wy o look i. Conider he following phyil nlogy. We n hink of eh o- edge hough i were pring h rie o onr, nd eh o- edge hough i were n infiniely rehy eli bnd, like hi: b Now imgine king verex in your lef hnd, nd verex in your righ hnd, nd pulling hem pr from eh oher fr poible (leving he oher verie o flo freely). Wh going o hppen? Well, due o he igh pring onneing nd, verex will ry o y loe o poible. Similrly, verex will ry o y loe o. Thi pull lefwrd nd righwrd. Finlly, when we drw u down he middle, we ll ge piure like hi: b The pring onneing nd rie o mke nd y on he me ide of he u; ine i fored o be on he lef ide, hi i equivlen o ying h i rie o mke be on he lef ide of he u. Similrly, he pring beween nd rie o pull owrd he righ ide of he u. And h exly wh hppen. So, peking looely, we n hink of he min-u problem hough we hve nework of pring. Eh edge orrepond o pring of ome peifi enion: An edge lbelled wih o ple no onrin ll. I like he edge in preen ll. An edge wih poiive o i like pring of erin enion h rie o keep boh edge of he pring on he me ide of he u. The lrger he o, he hrder he pring pull, i.e., he lrger he o on n edge, he hrder we ry o keep boh end of he edge on he me ide of he u. CS 7, Fll 24, /3 Noe 2
Here i noher exmple, o illure hee priniple. On he lef i flow nework (we ue double-rrowed line beween nd o repreen wo direed edge, one from o b nd one in he revere direion, boh wih he me o), nd on he righ i orreponding pring nework: b b In hi exmple, we n ee h he pring beween nd rie o pull owrd he lef ide of he u; nd he pring beween nd b rie o keep hee wo edge on he me ide of he u, hu pulling b owrd he lef ide of he u. Th i exly wh hppen when we ompue he miniml-o u. However, one word of uion bou he pring nlogy i in order. In he ul min-o problem, he direion of eh edge mer, ine we only oun edge h go ro he u from lef o righ owrd he ol o of he u. Spring don hve direion, nd o n model h pe of he min-u problem. So he pring nlogy i reonble rough-pproximion wy o hink of he problem, bu only fir guide o he inuiion; i doen pure everyhing h i going on in he min-u problem. The overll inuiion i: when you hve n edge (u,v) wih poiive o, i rie o void puing u on he lef ide of he u nd v on he righ ide, ine doing o would inur o. Pu noher wy, n edge (u,v) of poiive o rie o eiher () pu boh u nd v on he me ide of he u, if poible, or (2) pu u on he righ ide of he u nd v on he lef ide, if poible. Of oure in grph wih mny edge i my no be poible o ify ll of hee ompeing demnd, bu he minimum-o u omehow rie o ify mny of hem poible. Algorihm There i righforwrd wy o ompue he min-o u, uing nework flow lgorihm. We re he o on eh edge piy, re he grph hough i were nework of oil pipeline, nd find he mximum flow from o in he grph. By he mx-flow-min-u heorem, he mximum-vlue flow orrepond o minimum-piy u, whoe piy will be he me he vlue of he flow. The proof of he mx-flow-min-u heorem ell u how o expliily idenify minimum-piy u. We ompue he reidul grph G r, find ll of he verie h re rehble from in he reidul grph (vi ome equene of edge of poiive reidul piy), nd pu hem on he lef ide of he u. All he oher verie go on he righ ide of he u. We proved erlier h hi form miniml-piy u. Finlly, noe h he piy of he u i equl o he o of he u ( defined erlier). Therefore, hi provide n effiien lgorihm for he min-u problem. CS 7, Fll 24, /3 Noe 3
A minor uion: hi lgorihm erhe for (,)-u, i.e., u h re onrined o ple he oure on he lef ide of he u nd re onrined o ple he ink on he righ ide of he u. (Reerher hve lo udied u problem where here i no oure or ink verex, nd where we wn o look ll u, regrdle of where ny verex end up; h i differen problem nd he be lgorihm for h problem urn ou o be prey differen. We won onider h problem ny furher here.) Appliion: imge egmenion Here i ne ppliion of he min-u problem. We hve m n pixel imge, I[..m,..n], where I[i, j] denoe he olor of he pixel row i nd olumn j. The piure inlude foreground obje (y, ree), in fron of bunh of bkground enery (ky, gr, e.). We re wriing n imge proeing ool, nd we wn o idenify he e of pixel oied wih he foreground obje. Thi k urn ou o be quie hllenging o do in purely uomed fhion, bu i beome eier if we k humn o help u. We k he uer o mrk he re of he foreground obje, hin. Le H[..m,..n] be m n boolen rry, where H[i, j] = rue for eh pixel (i, j) h he uer h mrked pr of he foreground obje. The uer hin re no perfe, bu we n ume h hey re orre for he overwhelming mjoriy of pixel. Alo, we n ume h if wo neighboring pixel hve pproximely he me olor, hen hey re likely pr of he me obje, nd hu likely eiher boh pr of he foreground, or boh pr of he bkground. The obje i o lify eh pixel eiher foreground or bkground, in wy h i onien poible wih he uer hin nd lo wih he me-olor informion. We n repreen hi lifiion m n boolen mrix F[..m,..n], where F[i, j] = rue if pixel (i, j) i lified pr of he foreground, or fle if h pixel i lified pr of he bkground. Bed upon he hin bove, we ll define he o of lifiion he um of he following hrge: I o $ for eh pixel (i, j) where our lifiion digree wih he uer hin, i.e., where F[i, j] H[i, j]. I o $ for eh pir of neighboring pixel (i, j),(i, j ) h hve imilr olor bu re lified differenly, i.e., where I[i, j] I[i, j ] bu F[i, j] F[i, j ]. The imge egmenion problem i follow: given I nd H, find he lifiion F whoe o i miniml. Here i oluion. We build grph wih one verex for eh pixel (i, j) in he imge. We lo dd peil oure verex nd ink verex v, o h he grph h nm + 2 verie in ll. We dd he following edge: For eh pixel (i, j) h he uer hined i pr of he foreground (i.e., where H[i, j] = rue), we dd n edge from o (i, j) of o. For eh pixel (i, j) h he uer hined i pr of he bkground (i.e., where H[i, j] = fle), we dd n edge from (i, j) o of o. CS 7, Fll 24, /3 Noe 4
For eh pir of neighboring pixel (i, j),(i, j ) wih imilr olor (i.e., where I[i, j] I[i, j ]), we dd n edge from (i, j) o (i, j ) of o, nd n edge in he revere direion lo of o. Finlly, we find he miniml-o u (L, R) in hi grph. Thi u yield lifiion: we lify eh pixel in L foreground, nd lify eh pixel in R bkground. Noe h he o of ny priulr u i he me he o of he orreponding lifiion, due o he wy we hve onrued he grph. For inne, if he u pu nd (i, j) on oppoie ide of he u, where he uer hined h (i, j) i foreground (i.e., where H[i, j] = rue), hi will inree he ol o of he u by, ine i u he edge from o (i, j). Thi orrepond o hrge of $ for lifying pixel (i, j) bkground when he uer h hined i hould be pr of he foreground. And o on. Conequenly, he miniml-o u i he me he miniml-o lifiion. The inuiion behind hi lgorihm i imple. The oure verex repreen he foreground, nd he ink verex repreen he bkground. When we wn pixel o be pr of he foreground, we dd n edge beween nd h pixel. The effe will be o ry o keep hem on he me ide of he u ( hough hey hd pring pulling hem ogeher), nd in priulr, o pull h pixel o he foreground ide of he u. When we wn pixel o be pr of he bkground, we dd n edge beween h pixel nd, whih h he effe of rying o pull hem boh o he bkground ide of he u. Finlly, when we wn wo neighboring pixel o be lified he me, we pu n edge beween hem, whih h he effe of rying o keep hem on he me ide of he u ( hough hey hd pring beween hem). Conequenly, he grph repreen he onrin we re rying o ify, nd he miniml-o u repreen he be oluion h obey mny of he onrin poible. Imge re-izing The bonu queion on Homework 9 (Q6) inrodued he imge re-izing problem: ke lrge imge, nd hnge i pe rio by mking i kinnier, wihou mking everyhing look unnurl nd wihou ropping ou imporn pr of he imge. The homework problem hllenged you o find oluion uing dynmi progrmming. I will how you noher oluion o hi problem, bed upon nework flow nd minimum u. You probbly remember he problem emen. We hve n imge I[..m,..n]. A er i equene of pixel h form onneed ph from he op of he imge o he boom of he imge. Conneed men h he pixel row i + i mo one poiion o he righ or lef of he pixel row i (i.e., he pixel row i + i eiher ouhe, ouh, or ouhwe of he pixel row i). Deleing er will re-ize he imge o m (n ) imge, yielding new imge h i one pixel nrrower. For eh pixel (i, j), we re given he o of deleing h pixel, nmely, o(i, j). The o of er i he um of he o of he pixel deleed. The gol i o find le-o er. To olve i, we ll define grph where he miniml-o u orrepond o he miniml-o er. The grph i grid wih one verex for eh pixel, long wih peil oure verex nd ink verex. The bi bkbone of he grph look like hi: CS 7, Fll 24, /3 Noe 5
Eh red edge i inended o repreen n edge whoe o i. The effe of red (infinie-o) edge from u o v i preven he u from puing u on he lef ide nd v on he righ (ine h would innly mke he o of he u be infinie); ny finie-o u will eiher pu u on righ, or v on he lef, or boh. If you look he pern of he red edge hown bove, i urn ou h hi men h he u will be onneed ph: when i goe from row i o row i +, i n move o he lef or righ by mo one pixel. For inne, onider hi hypoheil u, hown in blue: u v Noie h he edge from u o v ( lbelled in he piure) goe from he lef ide of he u o he righ ide of he u. Alo h edge h infinie o, whih men h he hypoheil u hown in blue h infinie o. Of oure, no infinie-o u n ever be miniml if here exi ny finie-o u, o he blue u hown bove will be exluded. On he oher hnd, he u below i no exluded by he red edge, nd indeed, i orrepond o onneed ph h doe no jump more hn poiion o he lef or righ in eh row: CS 7, Fll 24, /3 Noe 6
In ummry, he red edge enfore he onrin h er n only jump lef or righ by one poiion in eh row. To omplee he grph we dd n edge from eh pixel o he neighbor on i righ, hown in blk below. In oher word, we hve dded n edge from eh pixel (i, j) o i neighbor (i, j + ) o he immedie righ. We ign o o hi edge ording o he o of deleing pixel (i, j), i.e., he o of hi edge i o(i, j). (In he e of pixel on he righmo olumn of he imge, nmely pixel (i,n), we ign hi o o he edge from (i,n) o.) Finlly, we ompue he miniml-o u in hi grph. The miniml-o u mu hve he following form. In he fir row, i ple he lefmo x pixel, for ome vlue x, on he lef ide of he u, nd he remining pixel on he righ. In he eond row, i ple he lefmo x 2 pixel on he lef nd he reminder on he righ, for ome x 2. And o on. A rgued bove, we hve x x 2, nd generlly, x i x i+. Conequenly, eh u orrepond o vlid er, where he er i defined o be he e of pixel immediely o he lef of he er line (one pixel per row). The o of he u i he um of he righ-going edge h i u, whih orrepond o he um of he o of he pixel in he er. Conequenly, he miniml-o u in hi grph i exly he miniml-o er. Thi how how lgorihm for he minimum-u problem n be ued o reize imge uomilly. Even more beuifully, hi ide n be exended in righforwrd wy o reizing of video. We ry o find er in eh frme of video, uh h he wo er in wo oneuive frme re CS 7, Fll 24, /3 Noe 7
hifed from eh oher by mo ± poiion in eh row. Thi n be enoded minimum-u problem in grph where he pixel form 3-dimenionl ube (rher hn 2-dimenionl grid). I urn ou h hi provide pril nd effiien wy o uomilly reize video, whih i prey nify. CS 7, Fll 24, /3 Noe 8