CS448f: Image Processing For Photography and Vision Graph Cuts.

Slides:



Advertisements
Similar presentations
Filling Algorithms Pixelwise MRFsChaos Mosaics Patch segments are pasted, overlapping, across the image. Then either: Ambiguities are removed by smoothing.
Advertisements

Max Flow Problem Given network N=(V,A), two nodes s,t of V, and capacities on the arcs: uij is the capacity on arc (i,j). Find non-negative flow fij for.
Cutting Images: Graphs and Boundary Finding Computational Photography Derek Hoiem, University of Illinois 09/15/11 “The Double Secret”, Magritte.
Graph cut Chien-chi Chen.
Introduction to Algorithms
Introduction to Markov Random Fields and Graph Cuts Simon Prince
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Recap from Monday Frequency domain analytical tool computational shortcut compression tool.
Recap from Monday Fourier transform analytical tool computational shortcut.
Graph-Based Image Segmentation
Foreground/Background Image Segmentation. What is our goal? To label each pixel in an image as belonging to either the foreground of the scene or the.
Stephen J. Guy 1. Photomontage Photomontage GrabCut – Interactive Foreground Extraction 1.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
1 s-t Graph Cuts for Binary Energy Minimization  Now that we have an energy function, the big question is how do we minimize it? n Exhaustive search is.
Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.
Lecture 6 Image Segmentation
Agenda Seam-carving: finish up “Mid-term review” (a look back) Main topic: Feature detection.
Advanced Topics in Computer Vision Spring 2006 Video Segmentation Tal Kramer, Shai Bagon Video Segmentation April 30 th, 2006.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
MRF Labeling With Graph Cut CMPUT 615 Nilanjan Ray.
Lecture 10: Stereo and Graph Cuts
Stereo Computation using Iterative Graph-Cuts
ECE LP Duality 1 ECE 665 Spring 2005 ECE 665 Spring 2005 Computer Algorithms with Applications to VLSI CAD Linear Programming Duality.
Image Compositing and Blending : Computational Photography Alexei Efros, CMU, Fall 2007 © NASA.
Network Flow & Linear Programming Jeff Edmonds York University Adapted from NetworkFlow.ppt.
Max-flow/min-cut theorem Theorem: For each network with one source and one sink, the maximum flow from the source to the destination is equal to the minimal.
Cutting Images: Graphs and Boundary Finding Computational Photography Derek Hoiem, University of Illinois 09/14/10 “The Double Secret”, Magritte.
Advanced Algorithms Piyush Kumar (Lecture 4: MaxFlow MinCut Applications) Welcome to COT5405.
Interactive Shortest Path Part 3 An Image Segmentation Technique Jonathan-Lee Jones.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
CS 4487/6587 Algorithms for Image Analysis
Network Flow. Network flow formulation A network G = (V, E). Capacity c(u, v)  0 for edge (u, v). Assume c(u, v) = 0 if (u, v)  E. Source s and sink.
Interactive Image Cutout- Lazy Snapping
CS654: Digital Image Analysis Lecture 28: Advanced topics in Image Segmentation Image courtesy: IEEE, IJCV.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
A global approach Finding correspondence between a pair of epipolar lines for all pixels simultaneously Local method: no guarantee we will have one to.
Graph Algorithms for Vision Amy Gale November 5, 2002.
Outline Standard 2-way minimum graph cut problem. Applications to problems in computer vision Classical algorithms from the theory literature A new algorithm.
Computational Photography lecture 8 – segmentation CS (future 572) Spring 2016 Prof. Alex Berg (Credits to many other folks on individual slides)
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
Markov Random Fields in Vision
CS 312: Algorithm Design & Analysis Lecture #29: Network Flow and Cuts This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
ENGM 631 Maximum Flow Solutions. Maximum Flow Models (Flow, Capacity) (0,3) (2,2) (5,7) (0,8) (3,6) (6,8) (3,3) (4,4) (4,10)
Cutting Images: Graphs and Boundary Finding Computational Photography Derek Hoiem, University of Illinois 09/20/12 “The Double Secret”, Magritte.
Hebrew University Image Processing Exercise Class 8 Panoramas – Stitching and Blending Min-Cut Stitching Many slides from Alexei Efros.
Graphcut Textures:Image and Video Synthesis Using Graph Cuts
Image Blending : Computational Photography
Cutting Images: Graphs and Boundary Finding
Digital Visual Effects, Spring 2009 Yung-Yu Chuang 2009/5/21
Image Processing and Reconstructions Tools
Richard Anderson Lecture 23 Network Flow
Image gradients and edges
Maximum Flow Solutions
Instructor: Shengyu Zhang
Haim Kaplan and Uri Zwick
Lecture 31: Graph-Based Image Segmentation
Digital Image Processing
“grabcut”- Interactive Foreground Extraction using Iterated Graph Cuts
Seam Carving Project 1a due at midnight tonight.
Flow Networks and Bipartite Matching
Announcements Project 4 questions Evaluations.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
EE5900 Advanced Embedded System For Smart Infrastructure
Announcements Project 4 out today (due Wed March 10)
Network Flow.
Lecture 22 Network Flow, Part 2
Network Flow.
“Traditional” image segmentation
Presentation transcript:

CS448f: Image Processing For Photography and Vision Graph Cuts

Seam Carving Video Make images smaller by removing “seams” Seam = connected path of pixels – from top to bottom – or left edge to right edge Don’t want to remove important stuff – importance = gradient magnitude

Finding a Good Seam How do we find a path from the top of an image to the bottom of an image that crosses the fewest gradients?

Finding a Good Seam Recursive Formulation: Cost to bottom at pixel x = gradient magnitude at pixel x + min(cost to bottom at pixel below x, cost to bottom at pixel below and right of x, cost to bottom at pixel below and left of x)

Dynamic Programming Start at the bottom scanline and work up, computing cheapest cost to bottom – Then, just walk greedily down the image for (int y = im.height-2; y >= 0; y--) { for (int x = 0; x < im.width; x++) { im(x, y)[0] += min3(im(x, y+1)[0], im(x+1,y+1)[0], im(x-1, y+1)[0]); }

Instead of Finding Shortest Path Here:

We greedily walk down this:

Protecting a region:

Demo

How Does Quick Selection Work? All of these use the same technique: – picking good seams for poisson matting (gradient domain cut and paste) pick a loop with low contrast – picking good seams for panorama stitching pick a seam with low contrast – picking boundaries of objects (Quick Selection) pick a loop with high contrast

Max Flow Min Cut Lazy Snapping Grab Cut Paint Select

Max Flow Given a network of links of varying capacity, a source, and a sink, how much flows along each link?

Aside: It’s Linear Programming One variable per edge (how much flow) One linear constraint per vertex – flow in = flow out Two inequalities per edge – -capacity < flow < capacity One linear combination to maximize – Total flow leaving source – Equivalently, total flow entering sink

Aside: It’s Linear Programming The optimimum occurs at the boundary of some high-D simplex – Some variables are maxed out, the others are then determined by the linear constraints The Simplex method: – Start from some valid state – Find a way to max out one of the variables in an attempt to make the solution better – Repeat until convergence

Start with no flow + - 0/10 0/11 0/8 0/1 0/4 0/7 0/15

Find path from source to sink with capacity + - 0/10 0/11 0/8 0/1 0/4 0/7 0/15

Max out that path Keep track of direction + - 4/10 0/11 4/8 0/1 4/4 0/7 0/15

Repeat + - 4/10 0/11 4/8 0/1 4/4 0/7 0/15

A maxed out edge can only be used in the other direction + - 4/10 1/11 4/8 1/1 3/4 0/7 1/15

Continue /10 1/11 4/8 1/1 3/4 0/7 1/15

Continue /10 8/11 4/8 1/1 3/4 7/7 8/15

Continue /10 8/11 4/8 1/1 3/4 7/7 8/15

Continue /10 11/11 7/8 1/1 3/4 7/7 8/15

Only one path left /10 11/11 7/8 1/1 3/4 7/7 8/15

No paths left. Done /10 11/11 8/8 1/1 4/4 7/7 8/15

The congested edges represent the bottleneck + - 5/10 11/11 8/8 1/1 4/4 7/7 8/15

Cutting across them cuts the graph while removing the minimum amount of capacity + - 5/10 11/11 8/8 1/1 4/4 7/7 8/15

Max Flow = Min Cut + - 5/10 11/11 8/8 1/1 4/4 7/7 8/15 Cut Cost = = 16

Everything Reachable from Source vs Everything Else + - 5/10 11/11 8/8 1/1 4/4 7/7 8/15 Cut Cost = = 16

Everything Reachable from Sink vs Everything Else + - 5/10 11/11 8/8 1/1 4/4 7/7 8/15 Cut Cost = = 16

Aside: Linear Programming It turns out min-cut is the dual linear program to max-flow So optimizing max flow also optimizes min-cut

How does this relate to pixels? Make a graph of pixels. 4 or 8-way connected

Foreground vs Background Edge Capacity = Similarity – So we want to cut between dissimilar pixels

Source and Sink? Option A: Pick two pixels + -

Source and Sink? Option B (better): Add extra nodes representing the foreground and background FG BG

Source and Sink? Connect them with strengths corresponding to likelihood that pixels below to FG or BG FG BG

Switch to 1D Edges between pixels = similarity Edges from FG to pixels = likelihood that they belong to FG Edges from BG to pixels = likelihood that they belong to BG FG BG

Switch to 1D The min cut leaves each pixel either connected to the FG node or the BG node FG BG

Edge strengths between pixels Strength = likelihood that two pixels should be in the same category likelihood = -log(1-probability) probability = ? – Gaussian about color distance will do – P xy = exp(-(I(x) - I(y)) 2 ) – When colors match, likelihood is infinity – When colors are very different, likelihood is small

Edge strengths to FG/BG If a pixel was stroked over using the tool – Strength to FG = large constant – Strength to BG = 0 Otherwise – Strength to FG/BG = likelihood that this pixel belongs to the foreground/background – likelihood = -log(1-probability) – probability = ?

Probability of belonging to FG/BG Here’s one method: Take all the pixels stroked over – Compute a histogram – FG Probability = height in this histogram Do the same for all pixels not stroked over – Or stroked over while holding alt – BG Probability = height in this histogram So if you stroked over red pixels, and a given new pixel is also red, FG probability is high.

In terms of minimization: Graph cuts minimizes the sum of edge strengths cut – sum of cuts from FG/BG + sum of cuts between pixels – penalty considering each pixel in isolation + penalty for pixels not behaving like similar neighbours – data term + smoothness term Much like deconvolution

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 Pixel exists in image 1

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 Pixel does not exist in image 1

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 Low Gradient in both images (CUT HERE!)

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 Low Gradient in one image (meh...)

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 High Gradient in both images (Don’t cut here)

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2 Off the edge of an image boundary DON’T CUT HERE

Picking seams for blending Use Image 1 Use Image 2 Image 1 Image 2

Speeding up Graph Cuts Use a fancy max-flow algorithm – e.g. tree reuse Use a smaller graph

Speeding up Graph Cuts Use Image 1 Use Image 2 Image 1 Image 2 There’s no decision to make at this pixel

Only include the relevant pixels Use Image 1 Use Image 2 Image 1 Image 2

Consider selection again FG BG

Clump pixels of near-constant color FG BG

Clump pixels of near-constant color Lazy Snapping does this (Li et al. SIGGRAPH 04)

Coarse to Fine 1) Solve at low res. FG BG

Coarse to Fine 1) Solve at low res. FG BG

Coarse to Fine 2) Refine the boundary FG BG Paint Selection does this Liu et al. SIGGRAPH 2009 (and uses joint bilateral upsampling to determine the boundary width)

Videos GrabCut (SIGGRAPH 04) – Paint Selection (SIGGRAPH 09) –