Top Banner
Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech Republic http://cmp.felk.cvut.cz /~ hlavac
59

Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

Dec 17, 2015

Download

Documents

Clifton Holt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

Graph-based image segmentation

Václav HlaváčCzech Technical University in Prague

Faculty of Electrical Engineering

Department of Cybernetics

Prague, Czech Republic

http://cmp.felk.cvut.cz/~hlavac

Based on the presentation of D. Hoiem ,S. Lazebnik, Jianbo Shi

Page 2: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

2

Types of segmentations

Oversegmentation Undersegmentation

Multiple Segmentations

Page 3: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

3

Major processes for segmentation Bottom-up: group tokens with similar

features Top-down: group tokens that likely belong to

the same object

[Levin and Weiss 2006]

Page 4: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

4

Page 5: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

5

Main Ideas

Convert image into a graph• Vertices for the pixels• Edges between the pixels• Additional vertices and edges to encode

other constraints Manipulate the graph to segment the

image

Page 6: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

6

Papers

Interactive graph cuts for optimal boundary & region segmentation ofobjects in N-D images • Boykov and Jolly• Minimize an energy function

Efficient Graph-based Segmentation• Felzenszwalb and Huttenlocher• Cluster the vertices based on edge weight

Page 7: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

7

Boykov and Jolly

Binary image segmentation• Classify pixels as object or background• Their contribution is adding interactivity

Minimise an energy function• E(A) = B(A) + λR(A)

A: Segmentation (assign each pixels to object or background)

B(A): The cost of all the edges between object pixels and background pixels

R(A): The cost of deciding a pixel to be object or background

Page 8: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

8

Creating the Graph

Each pixel has a corresponding vertex Additionally, a source (“object”) and a

sink (“background”) Each pixel vertex has an edge to its

neighbours (e.g. 8 adjacent neighbours in 2D), an edge to the source, an edge to the sink

Page 9: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

9

An image represented as a graph

Page 10: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

10

Undirected/directed graph

Page 11: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

11

Page 12: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

12

Page 13: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

13

Page 14: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

14

Intelligent Scissors

Mortenson and Barrett (SIGGRAPH 1995)

Page 15: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

15

Intelligent Scissors

A good image boundary has a short path through the graph.

Mortenson and Barrett (SIGGRAPH 1995)

1 2 1

4

1

6

9

1

3

1

4

113

2

3

5

Start

End

Page 16: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

16

Intelligent Scissors Formulation: find good boundary between seed

points Challenges

• Minimize interaction time• Define what makes a good boundary• Efficiently find it

Page 17: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

17

Intelligent Scissors: method

1. Define boundary cost between neighboring pixels

2. User specifies a starting point (seed)

3. Compute lowest cost from seed to each other pixel

4. Get path from seed to cursor, choose new seed, repeat

Page 18: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

18

Intelligent Scissors: methodDefine boundary cost between neighboring pixels

a) Lower if edge is present (e.g., with edge(im, ‘canny’))

b) Lower if gradient is strong

c) Lower if gradient is in direction of boundary

Page 19: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

19

Gradients, Edges, and Path Cost

Gradient Magnitude

Edge Image

Path Cost

Page 20: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

20

Intelligent Scissors: method

1. Define boundary cost between neighboring pixels

2. User specifies a starting point (seed)• Snapping

Page 21: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

21

Intelligent Scissors: method

1. Define boundary cost between neighboring pixels

2. User specifies a starting point (seed)

3. Compute lowest cost from seed to each other pixel

• Dijkstra’s shortest path algorithm

Page 22: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

22

Dijkstra’s shortest path algorithmInitialize, given seed s: Compute cost2(q, r) % cost for boundary from pixel q to

neighboring pixel r cost(s) = 0 % total cost from seed to this point A = {s} % set to be expanded E = { } % set of expanded pixels P(q) % pointer to pixel that leads to q

Loop while A is not empty1. q = pixel in A with lowest cost2. Add q to E3. for each pixel r in neighborhood of q that is not in E

a) cost_tmp = cost(q) + cost2(q,r)

b) if (r is not in A) OR (cost_tmp < cost(r))

i. cost(r) = cost_tmp ii. P(r) = qiii.Add r to A

Page 23: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

23

Intelligent Scissors: method

1. Define boundary cost between neighboring pixels

2. User specifies a starting point (seed)

3. Compute lowest cost from seed to each other pixel

4. Get new seed, get path between seeds, repeat

Page 24: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

24

Intelligent Scissors: improving interaction

1. Snap when placing first seed

2. Automatically adjust to boundary as user drags

3. Freeze stable boundary points to make new seeds

Page 25: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

25

A cut of a graph

Page 26: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

26

Flow network, flow

Page 27: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

27

Page 28: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

28

Page 29: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

29

Page 30: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

30

Page 31: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

31

Page 32: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

32

Page 33: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

33

Page 34: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

34

Page 35: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

35

Pixel-based statistical model

has limitations because of existing relations to other pixels.

P(foreground | image)

Page 36: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

36

Solution: encode dependences between pixels

P(foreground | image)

edgesji

jiNi

i datayypdataypZ

dataP,

2..1

1 ),;,(),;(1

),;( y

Labels to be predicted Individual predictions Pairwise predictions

Normalizing constant called “partition function”

Page 37: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

37

Writing likelihood as an energy

edgesji

jiNi

i datayypdataypZ

dataP,

2..1

1 ),;,(),;(1

),;( y

edgesji

jii

i datayydataydataEnergy,

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

Cost of assignment yi Cost of pairwise assignment yi ,yj

- log(.)

Page 38: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

38

Notes on energy-based formulation

Primarily used when you only care about the most likely solution (not the confidences).

Can think of it as a general cost function. Can have larger “cliques” than 2. The clique is the

set of variables that go into a potential function.

edgesji

jii

i datayydataydataEnergy,

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

Page 39: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

40

Markov Random Fields

edgesji

jii

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

Page 40: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

41

Label smoothing grid example

Unary potential

0 10 0 K1 K 0

K>0

0: - logP(yi = 0 | data)1: - logP(yi = 1 | data)

Pairwise Potential

edgesji

jii

i datayydataydataEnergy,

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

Page 41: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

42

Creating the graph

Each pixel has a corresponding vertex Additionally, a source (“object”) and a sink

(“background”) Each pixel vertex has an edge to its

neighbors (e.g. 8 adjacent neighbors in 2D), an edge to the source, an edge to the sink

Page 42: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

43

Edge weights between pixels

Weight of edges between pixel vertices are determined by the function expressing dependence between two pixels

Low score when boundary is likely to pass between the vertices

High score when vertices are probably part of the same element

E.g. the difference in pixel intensities, the image gradient

Page 43: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

44

Solving MRFs with graph cuts

edgesji

jii

i datayydataydataEnergy,

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

Source (Label 0)

Sink (Label 1)

Cost to assign to 1

Cost to assign to 0

Cost to split nodes

Page 44: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

45

Solving MRFs with graph cuts

edgesji

jii

i datayydataydataEnergy,

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

Source (Label 0)

Sink (Label 1)

Cost to assign to 1

Cost to assign to 0

Cost to split nodes

Page 45: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

46

Graph cut, Boykov & Jolly 2001

Image Min Cut

Cut: Separating source and sink; Energy: collection of edgesMin Cut: Global minimal energy in polynomial time

Foreground (source)

Background

(sink)

Page 46: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

47

Max flow

Directed graph with one source & one sink node Directed edge = pipe Edge label = capacity What is the max flow from source to sink?

Source Sink

1010

1212

9

8

8 8

9 8

4

5

92

2

52

6

1

1

7

6

3

10

4

5

1

1

3

99

Page 47: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

48

Max flow

Graph with one source & one sink node Edge = pipe Edge label = capacity What is the max flow from source to sink?

Source Sink

10/102/10

9/121/12

9/9

0/8

8/8 8/8

8/9 8/8

2/4

1/5

9/92/2

1/2

5/52/2

1/6

0/1

0/1

2/7

0/6

3/3

7/10

4/4

5/5

0/1

0/1

3/3

0/93/9

Page 48: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

49

Max flow What is the max flow from source to sink? Look at residual graph

• remove saturated edges (green here)• min cut is at boundary between 2 connected

components

Source Sink

10/102/10

9/121/12

9/9

0/8

8/8 8/8

8/9 8/8

2/4

1/5

9/92/2

1/2

5/52/2

1/6

0/1

0/1

2/7

0/6

3/3

7/10

4/4

5/5

0/1

0/1

3/3

0/93/9

min cut

Page 49: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

50

Equivalence of min cut/max flow The three following statements are equivalent

• The maximum flow is f• The minimum cut has weight f• The residual graph for flow f contains no

directed path from source to sink

Source Sink

10/102/10

9/121/12

9/9

0/8

8/8 8/8

8/9 8/8

2/4

1/5

9/92/2

1/2

5/52/2

1/6

0/1

0/1

2/7

0/6

3/3

7/10

4/4

5/5

0/1

0/1

3/3

0/93/9

min cut

Page 50: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

51

Normalized cut

• A minimum cut penalizes large segments• This can be fixed by normalizing the cut by

component size• The normalized cut cost is:

• The exact solution is NP-hard but an approximation can be computed by solving a generalized eigenvalue problem

assoc(A, V) = sum of weights of all edges in V that touch A

),(

),(

),(

),(

VBassoc

BAcut

VAassoc

BAcut

J. Shi and J. Malik. Normalized cuts and image segmentation. PAMI 2000

Page 51: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

52

GrabCut segmentation

User provides rough indication of foreground region.

Goal: Automatically provide a pixel-level segmentation.• Less user input, rectangle only.• Handles color

Carsten Rother (professor at TU Dresden now) et al. 2004

Page 52: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

53

Grab cuts and graph cuts

User Input

Result

Magic Wand (198?)

Intelligent ScissorsMortensen and Barrett (1995)

GrabCut

Regions

Boundary

Source: K. Rother

Page 53: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

54

Color model

Gaussian Mixture Model (typically 5-8 components)

Foreground &Background

Background

R

G

Source: K. Rother

Page 54: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

55

Color model 2

Gaussian Mixture Model (typically 5-8 components)

Foreground &Background

Background

Foreground

BackgroundG

R

G

RIterated graph cut

Source: K. Rother

Page 55: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

56

GrabCut segmentation1. Define graph

• usually 4-connected or 8-connected Divide diagonal potentials by sqrt(2)

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

21 2

)()(exp),(_

ycxc

kkyxpotentialedge

));((

));((log)(_

background

foreground

xcP

xcPxpotentialunary

Page 56: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

57

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

Page 57: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

58

Easier examples

GrabCut – Interactive Foreground Extraction 10

Page 58: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

59

More difficult Examples

Camouflage &

Low Contrast

Harder Case

Fine structure

Initial Rectangle

InitialResult

GrabCut – Interactive Foreground Extraction 11

Page 59: Graph-based image segmentation Václav Hlaváč Czech Technical University in Prague Faculty of Electrical Engineering Department of Cybernetics Prague, Czech.

60

Using graph cuts for recognition

TextonBoost (Shotton et al. 2009 IJCV)