Segmentation: MRFs and Graph Cuts - Brown...

56

Transcript of Segmentation: MRFs and Graph Cuts - Brown...

Page 1: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good
Page 2: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Segmentation: MRFs and Graph Cuts

Computer Vision

CS 143, Brown

James Hays

10/07/11

Many slides from Kristin Grauman and Derek Hoiem

Page 3: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Today’s class

• Segmentation and Grouping

• Inspiration from human perception

– Gestalt properties

• MRFs

• Segmentation with Graph Cuts

i

j

wij

Slide: Derek Hoiem

Page 4: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Grouping in vision

• Goals: – Gather features that belong together

– Obtain an intermediate representation that compactly

describes key image or video parts

Page 5: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Examples of grouping in vision

[Figure by J. Shi]

[http://poseidon.csd.auth.gr/LAB_RESEARCH/Latest/imgs/S

peakDepVidIndex_img2.jpg]

Determine image regions

Group video frames into shots

Fg / Bg

[Figure by Wang & Suter]

Object-level grouping

Figure-ground

[Figure by Grauman & Darrell]

Slide: Kristin Grauman

Page 6: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Grouping in vision

• Goals: – Gather features that belong together

– Obtain an intermediate representation that compactly

describes key image (video) parts

• Top down vs. bottom up segmentation

– Top down: pixels belong together because they are

from the same object

– Bottom up: pixels belong together because they look

similar

• Hard to measure success

– What is interesting depends on the app.

Slide: Kristin Grauman

Page 7: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

What things should be grouped?

What cues indicate groups?

Slide: Kristin Grauman

Page 8: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Gestalt psychology or Gestaltism

• German: Gestalt - "form" or "whole” • Berlin School, early 20th century

– Kurt Koffka, Max Wertheimer, and Wolfgang Köhler

• Gestalt: whole or group

– Whole is greater than sum of its parts

– Relationships among parts can yield new properties/features

• Psychologists identified series of factors that predispose set of elements to be grouped (by human visual system)

Page 9: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

The Muller-Lyer illusion

Gestaltism

Slide: Derek Hoiem

Page 10: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

We perceive the interpretation, not the senses

Slide: Derek Hoiem

Page 11: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Principles of perceptual organization

From Steve Lehar: The Constructive Aspect of Visual Perception

Page 12: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Principles of perceptual organization

Page 13: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Similarity

http://chicagoist.com/attachments/chicagoist_alicia/GEESE.jpg, http://wwwdelivery.superstock.com/WI/223/1532/PreviewComp/SuperStock_1532R-0831.jpg Slide: Kristin Grauman

Page 14: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Symmetry

http://seedmagazine.com/news/2006/10/beauty_is_in_the_processingtim.php Slide: Kristin Grauman

Page 15: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Common fate

Image credit: Arthus-Bertrand (via F. Durand)

Slide: Kristin Grauman

Page 16: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Proximity

http://www.capital.edu/Resources/Images/outside6_035.jpg Slide: Kristin Grauman

Page 17: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

From Steve Lehar: The Constructive Aspect of Visual Perception

Grouping by invisible completion

Page 18: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

D. Forsyth

Page 19: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good
Page 20: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Emergence

Page 21: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Gestalt cues

• Good intuition and basic principles for grouping

• Basis for many ideas in segmentation and occlusion reasoning

• Some (e.g., symmetry) are difficult to implement in practice

Page 22: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

intensity

pix

el

co

un

t

input image

black pixels gray

pixels

white

pixels

• These intensities define the three groups.

• We could label every pixel in the image according to

which of these primary intensities it is.

• i.e., segment the image based on the intensity feature.

• What if the image isn’t quite so simple?

1 2 3

Image segmentation: toy example

Kristen Grauman

Page 23: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

intensity

pix

el

co

un

t

input image

input image intensity

pix

el

co

un

t

Kristen Grauman

Page 24: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

input image intensity

pix

el

co

un

t

• Now how to determine the three main intensities that

define our groups?

• We need to cluster.

Kristen Grauman

Page 25: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Clustering

• With this objective, it is a “chicken and egg” problem:

– If we knew the cluster centers, we could allocate

points to groups by assigning each to its closest center.

– If we knew the group memberships, we could get the

centers by computing the mean per group.

Kristen Grauman

Page 26: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Smoothing out cluster assignments

• Assigning a cluster label per pixel may yield outliers:

1 2

3

?

original labeled by cluster center’s

intensity

• How to ensure they are

spatially smooth?

Kristen Grauman

Page 27: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Solution

P(foreground | image)

Encode dependencies between pixels

edgesji

ji

Ni

i datayyfdatayfZ

dataP,

2

..1

1 ),;,(),;(1

),;(y

Labels to be predicted Individual predictions Pairwise predictions

Normalizing constant

Slide: Derek Hoiem

Page 28: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Writing Likelihood as an “Energy”

edgesji

ji

Ni

i datayypdataypZ

dataP,

2

..1

1 ),;,(),;(1

),;(y

edgesji

ji

i

i datayydataydataEnergy,

21 ),;,(),;(),;(y

“Cost” of assignment yi

“Cost” of pairwise assignment yi ,yj

Slide: Derek Hoiem

Page 29: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Markov Random Fields

edgesji

ji

i

i datayydataydataEnergy,

21 ),;,(),;(),;(y

Node yi: pixel label

Edge: constrained

pairs

Cost to assign a label to

each pixel Cost to assign a pair of labels to

connected pixels

Slide: Derek Hoiem

Page 30: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Markov Random Fields

• Example: “label smoothing” grid Unary potential

0 1

0 0 K

1 K 0

Pairwise Potential

0: -logP(yi = 0 ; data)

1: -logP(yi = 1 ; data)

edgesji

ji

i

i datayydataydataEnergy,

21 ),;,(),;(),;(ySlide: Derek Hoiem

Page 31: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Solving MRFs with graph cuts

edgesji

ji

i

i datayydataydataEnergy,

21 ),;,(),;(),;(y

Source (Label 0)

Sink (Label 1)

Cost to assign to 1

Cost to assign to 0

Cost to split nodes

Slide: Derek Hoiem

Page 32: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Solving MRFs with graph cuts

edgesji

ji

i

i datayydataydataEnergy,

21 ),;,(),;(),;(y

Source (Label 0)

Sink (Label 1)

Cost to assign to 0

Cost to assign to 1

Cost to split nodes

Slide: Derek Hoiem

Page 33: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

GrabCut segmentation

User provides rough indication of foreground region.

Goal: Automatically provide a pixel-level segmentation.

Slide: Derek Hoiem

Page 34: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Grab cuts and graph cuts

User

Input

Result

Magic Wand (198?)

Intelligent Scissors Mortensen and Barrett (1995)

GrabCut

Regions Boundary Regions & Boundary

Source: Rother

Page 35: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Colour Model

Gaussian Mixture Model (typically 5-8 components)

Foreground &

Background

Background G

R

Source: Rother

Page 36: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Graph cuts

Boykov and Jolly (2001)

Image

Min Cut

Cut: separating source and sink; Energy: collection of edges

Min Cut: Global minimal enegry in polynomial time

Foreground

(source)

Background

(sink)

Source: Rother

Page 37: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Colour Model

Gaussian Mixture Model (typically 5-8 components)

Foreground &

Background

Background

Foreground

Background G

R

G

R Iterated

graph cut

Source: Rother

Page 38: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

GrabCut segmentation

1. Define graph – usually 4-connected or 8-connected

2. Define unary potentials – Color histogram or mixture of Gaussians for

background and foreground

3. Define pairwise potentials

4. Apply graph cuts

5. Return to 2, using current labels to compute foreground, background models

2

2

212

)()(exp),(_

ycxckkyxpotentialedge

));((

));((log)(_

background

foreground

xcP

xcPxpotentialunary

Slide: Derek Hoiem

Page 39: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

What is easy or hard about these cases for graphcut-based segmentation?

Slide: Derek Hoiem

Page 40: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Easier examples

GrabCut – Interactive Foreground Extraction 10

Page 41: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

More difficult Examples

Camouflage &

Low Contrast Harder Case Fine structure

Initial

Rectangle

Initial

Result

GrabCut – Interactive Foreground Extraction 11

Page 42: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Lazy Snapping (Li et al. SG 2004)

Page 43: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Using graph cuts for recognition

TextonBoost (Shotton et al. 2009 IJCV)

Page 44: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Using graph cuts for recognition

TextonBoost (Shotton et al. 2009 IJCV)

Unary Potentials

Alpha Expansion Graph Cuts

Page 45: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Limitations of graph cuts

• Associative: edge potentials penalize different labels

• If not associative, can sometimes clip potentials

• Approximate for multilabel

– Alpha-expansion or alpha-beta swaps

Must satisfy

Slide: Derek Hoiem

Page 46: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Graph cuts: Pros and Cons

• Pros – Very fast inference

– Can incorporate data likelihoods and priors

– Applies to a wide range of problems (stereo, image labeling, recognition)

• Cons – Not always applicable (associative only)

– Need unary terms (not used for generic segmentation)

• Use whenever applicable

Slide: Derek Hoiem

Page 47: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

More about MRFs/CRFs

• Other common uses

– Graph structure on regions

– Encoding relations between multiple scene elements

• Inference methods

– Loopy BP or BP-TRW: approximate, slower, but works for more general graphs

Slide: Derek Hoiem

Page 48: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Further reading and resources

• Graph cuts – http://www.cs.cornell.edu/~rdz/graphcuts.html – Classic paper: What Energy Functions can be Minimized via Graph Cuts?

(Kolmogorov and Zabih, ECCV '02/PAMI '04)

• Belief propagation Yedidia, J.S.; Freeman, W.T.; Weiss, Y., "Understanding Belief Propagation and

Its Generalizations”, Technical Report, 2001: http://www.merl.com/publications/TR2001-022/

• Normalized cuts and image segmentation (Shi and Malik) http://www.cs.berkeley.edu/~malik/papers/SM-ncut.pdf

• N-cut implementation http://www.seas.upenn.edu/~timothee/software/ncut/ncut.html

Slide: Derek Hoiem

Page 49: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Next Class

• Gestalt grouping

• More segmentation methods

Page 50: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Recap of Grouping and Fitting

Page 51: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Edge and line detection

• Canny edge detector = smooth derivative thin threshold link

• Generalized Hough transform = points vote for shape parameters

• Straight line detector = canny + gradient orientations orientation binning linking check for straightness

Slide: Derek Hoiem

Page 52: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Robust fitting and registration

Key algorithms

• RANSAC, Hough Transform

Slide: Derek Hoiem

Page 53: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Clustering

Key algorithm

• K-means

Slide: Derek Hoiem

Page 55: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Segmentation

• Mean-shift segmentation – Flexible clustering method, good segmentation

• Watershed segmentation – Hierarchical segmentation from soft boundaries

• Normalized cuts – Produces regular regions

– Slow but good for oversegmentation

• MRFs with Graph Cut – Incorporates foreground/background/object

model and prefers to cut at image boundaries

– Good for interactive segmentation or recognition

Slide: Derek Hoiem

Page 56: Segmentation: MRFs and Graph Cuts - Brown Universitycs.brown.edu/courses/cs143/2011/lectures/14.pdf · Segmentation • Mean-shift segmentation –Flexible clustering method, good

Next section: Recognition

• How to recognize

– Specific object instances

– Faces

– Scenes

– Object categories

Slide: Derek Hoiem