motivation connected component treecwjs70/c2comptree.pdf · connected components labeling with...

50
1 J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 1 Connected Component Tree Jean Cousty FOUR-DAY COURSE on Mathematical Morphology in image analysis Bangalore 19-22 October 2010 J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 2 Motivation Connectivity plays important role for image processing Morphological connected filters Morphological filters acting on components of a set Morphological filters acting on components of the flat zones of a function Graphs are adapted for handling digital connectivity How can connected filters be efficiently implemented? Problem

Upload: others

Post on 04-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

1

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 1

Connected Component Tree

Jean Cousty

FOUR-DAY COURSE

on

Mathematical Morphology in image analysis

Bangalore 19-22 October 2010

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 2

Motivation

Connectivity plays important role for image processing

Morphological connected filters

Morphological filters acting on components of a set

Morphological filters acting on components of the flat zones of a function

Graphs are adapted for handling digital connectivity

How can connected filters be efficiently implemented?

Problem

Page 2: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

2

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 3

Outline

Connected filters on (weighted) graphs

Connected components

Component tree

Example of application

Algorithms for connected filters on (weighted) graphs

Union of disjoint set

Connected component labeling

Component tree extraction

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 4

Structuring a discrete set

Let V be a set

(eg, the set of all image pixels)

Let X be a subset of V

(eg, a binary object to be processed)

Page 3: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

3

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 5

Discrete set

V (white & black dots) and X (black dots)

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 6

Discrete set

V (white & black dots) and X (black dots)

Page 4: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

4

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 7

Graph

Neighborhood (in blue) of a point (in red)

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 8

Graph

Vertex set (dots) and edge set E (line segments) of a graph (V,E)

Page 5: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

5

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 9

Connected sets

Let G = (V,E) be a (undirected) graph

Let X be a subset of V

X is connected if

there exists a path between any two points of X

Definition

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 10

Example: Discrete set that is not connected

Page 6: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

6

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 11

Example: Connected discrete set

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 12

Connected components

Let G = (V,E) be a (undirected) graph.

Let X be a subset of V

Let Y be a subset of X

Y is a (connected) component of X if

Y is connected

no proper superset of Y included in X is connected

Definition

Y is a component of X iff for any x in Y

Y is the union of all connected subsets of X that conains x

Property

Page 7: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

7

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 13

Example : Connected components partition

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 14

Connected opening a discrete set

According to a given criterion (e.g., the size), keep the most important components of X

Page 8: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

8

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 15

Example: area filtering a discrete set

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 16

Example: area filtering a discrete set

Page 9: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

9

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 17

From maps to sets

k

Fk = {x E, F(x) k}, i.e., points above kJ. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 18

From maps to sets

k

Fk = {x E, F(x) < k}, i.e., points below k

Page 10: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

10

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 19

Structuring a discrete map: level sets decomposition

Let F be a map from V to N and let k be an integer

The (upper) level-set of F at level k is the set made of the points of V whose value is greater than or equal to k

Fk = {x E, F(x) k}

Definition

Any connected component of any (upper) level set of F is called a (upper) component of F

Remark

Any two components of F are either nested or disjoint

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 20

Structuring a discrete map: (upper) Component tree

Components + inclusion relation tree structure

Page 11: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

11

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 21

Structuring a discrete map: (upper) Component tree

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 22

Level-sets, components: the 2D case

F

Page 12: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

12

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 23

F1

Level-sets, components: the 2D case

F

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 24

Level-sets, components: the 2D case

F2F

Page 13: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

13

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 25

F3

Level-sets, components: the 2D case

F

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 26

Level-sets, components: the 2D case

F4F

Page 14: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

14

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 27

Cross-sections, components: the 2D case

+ + +

F

F4 F3 F2 F1

28

Component tree: the 2D case

C1 C1 C1 C1 C1C1 C1

C1 C4 C4

C1 C6 C6

C1

C1 C1

C1 C4 C4

C2

11 C1C1

C5 C7 C1

C2 C5 C7 C1

C3

C1C1

C6 C3

C1 C1 C1 C1 C1 C5 C1

C1 C1 C1C3

C3 C1

C1

C1

C2

C5C4

C7

C3

C6

C8

Level 1

Level 2

Level 3

Level 4

Component tree Component mapping

C8

Page 15: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

15

29

Component tree: the 2D case

C1 C1 C1 C1 C1C1 C1

C1 C4 C4

C1 C6 C6

C1

C8

C1 C1

C1 C4 C4

C2

11 C1C1

C5 C7 C1

C2 C5 C7 C1

C3

C1C1

C6 C3

C1 C1 C1 C1 C1 C5 C1

C1 C1 C1C3

C3 C1

C1

C1

C2

C5C4

C7

C3

C6

C8

Level 1

Level 2

Level 3

Level 4

Component tree Component mapping

C7

C7

C8

30

Component tree: the 2D case

C1 C1 C1 C1 C1C1 C1

C1 C4 C4

C1 C6 C6

C1

C1 C1

C1 C4 C4

C2

11 C1C1

C5 C7 C1

C2 C5 C7 C1

C3

C1C1

C6 C3

C1 C1 C1 C1 C1 C5 C1

C1 C1 C1C3

C3 C1

C1

C1

C2

C5C4

C7

C3

C6

C8

Level 1

Level 2

Level 3

Level 4

Component tree Component mapping

C6 C6

C6C6

C8

C5

C5

C5C5

C5C4

C4 C4

C4

Page 16: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

16

31

Component tree: the 2D case

C1 C1 C1 C1 C1C1 C1

C1 C4 C4

C1 C6 C6

C1

C1 C1

C1 C4 C4

C2

11 C1C1

C5 C7 C1

C2 C5 C7 C1

C3

C1C1

C6 C3

C1 C1 C1 C1 C1 C5 C1

C1 C1 C1C3

C3 C1

C1

C1

C2

C5C4

C7

C3

C6

C8

Level 1

Level 2

Level 3

Level 4

Component tree Component mapping

C8

C2

C2

C2

C2

C2

C2

C2

C2C2

C2C2

C3C3C3C3C3

C3 C3 C3

32

Component tree: the 2D case

C1 C1 C1 C1 C1C1 C1

C1 C4 C4

C1 C6 C6

C1

C1 C1

C1 C4 C4

C2

11 C1C1

C5 C7 C1

C2 C5 C7 C1

C3

C1C1

C6 C3

C1 C1 C1 C1 C1 C5 C1

C1 C1 C1C3

C3 C1

C1

C1

C2

C5C4

C7

C3

C6

C8

Level 1

Level 2

Level 3

Level 4

Component tree Component mapping

C8

C1

Page 17: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

17

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 33

Filtering a discrete map : flooding

A leaf of the component tree T of F is:

a regional minimum of F, if T is a lower component tree

a regional maximum of F, if T is an upper component tree

According to a given criterion, we can iteratively remove the leaf components of F

Such a removal is called a flooding

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 34

Flooding: intuitive example step 1

Page 18: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

18

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 35

Flooding: intuitive example step 1

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 36

Flooding: intuitive example step 2

Page 19: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

19

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 37

Flooding: intuitive example step 3

We remove one branch of T

We flood one “ lobe ” of FJ. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 38

Flooding: formal definition

Let x in V

The elementary flooding of F at x is defined by:

ηxF(y) = F(y) + 1 if x and y belong to the same minimum

ηxF(y) = F(y) otherwise

Any map obtained from F by composition of elementary floodings is called a flooding of F

Definition

Page 20: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

20

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 39

Filtering a grayscale map

What criterion (attribute) to select the non-significant minima to be flooded?

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 40

Attributes: height

h

Page 21: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

21

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 41

Attributes: area

a

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 42

Attributes: volume

v

Page 22: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

22

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 43

Filtering by volume

Regional minimaJ. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 44

Filtering by volume

Regional minima

Page 23: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

23

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 45

Application: keep the 10 most volumic lobes

Original image (top) and

its many minima (bottom)

Filtered image (top) and its

10 minima (bottom)

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 46

Algorithms requested for achieving this result

Component tree algorithm

Flooding the minima with attribute below a given threshold

Or alternatively, keeping only the k most significant minima

Page 24: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

24

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 47

Algorithms for the component tree

There exist several algorithms for the component tree

Breen & Jones 1996

Salembier, Oliveras & Garido 1998

Mattes & Demongeot 2000

Couprie & Najman 2006

Tarjan’s union find

Connected components labeling

Quasi-linear time component tree extraction

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 48

Disjoint set problem

Maintaining a collection of disjoint subsets of a set V under the operation of union

Each subset X is represented by a unique element of X called the canonical element of X

Three operations allow the collection to be managed:

MakeSet(x): add the set {x} to the collection

Find(x): return the canonical element of the set containing x

Link(x,y):

● Remove the two sets whose canonical elements are x and y

● Add their union

Page 25: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

25

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 49

Tarjan’s union-find algorithm

Quasi-linear algorithm: O(m X α(m,|V|))

for m operations

α : inverse of Ackerman function (in practice never greater than 4)

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 50

Connected components labeling with union-find

Page 26: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

26

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 51

Connected components labeling with union-find

12

34 6

6

3

75

2

1

47

5

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 52

Connected components labeling with union-find

12

34 6

6

3

75

2

1

47

5

Page 27: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

27

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 53

Connected components labeling with union-find

12

34 6

6

3

75

2

1

47

5

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 54

Connected components labeling with union-find

12

34 6

6

3

75

2

1

47

5

Page 28: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

28

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 55

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 56

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

Page 29: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

29

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 57

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 58

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

Page 30: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

30

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 59

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 60

Connected components labeling with union-find

12

34 5 6

6

3

75

2

1

47

Page 31: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

31

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 61

Connected components labeling with union-find

12

34 5 6

2

2

72

2

2

27

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 62

Component tree algorithm

General case

Two collections of disjoint subsets of V

Particular case: all values are distinct

One collection of disjoint subsets of V

Page 32: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

32

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 63

Component tree algorithm: all values distinct

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 64

Component tree algorithm: all values distinct (init)

A B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

Image Lowest Node nodes Disjoint sets

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 33: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

33

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 65

Component tree algorithm: all values distinct (step 1)

A B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = C

Image Lowest Node nodes Disjoint sets

C

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 66

Component tree algorithm: all values distinct (step 2)

A B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = G

Image Lowest Node nodes Disjoint sets

CG

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 34: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

34

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 67

Component tree algorithm: all values distinct (step 3)

A B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = A

Image Lowest Node nodes Disjoint sets

CG A

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 68

Component tree algorithm: all values distinct (step 4)

A B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = D

Image Lowest Node nodes Disjoint sets

CG A

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 35: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

35

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 69

Component tree algorithm: all values distinct (step 4)

D B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = D

Image Lowest Node nodes Disjoint sets

CG A

y = A

D

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 70

Component tree algorithm: all values distinct (step 4)

D B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = D

Image Lowest Node nodes Disjoint sets

CG A

y = G

D

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 36: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

36

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 71

Component tree algorithm: all values distinct (step 5)

H B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = H

Image Lowest Node nodes Disjoint sets

CG A

y = G

DH

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 72

Component tree algorithm: all values distinct (step 6)

E B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = E

Image Lowest Node nodes Disjoint sets

CG A

y = D

DH

E

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 37: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

37

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 73

Component tree algorithm: all values distinct (step 6)

E B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = E

Image Lowest Node nodes Disjoint sets

CG A

y = H

DH

E

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 74

Component tree algorithm: all values distinct (step 7)

I B C

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = I

Image Lowest Node nodes Disjoint sets

CG A

y = H

DH

EI

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 38: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

38

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 75

Component tree algorithm: all values distinct (step 8)

I B F

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = F

Image Lowest Node nodes Disjoint sets

CG A

y = C

DH

EI

F

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 76

Component tree algorithm: all values distinct (step 7)

I B F

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = F

Image Lowest Node nodes Disjoint sets

CG A

y = E

DH

EI

F

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 39: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

39

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 77

Component tree algorithm: all values distinct (step 7)

I B F

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = F

Image Lowest Node nodes Disjoint sets

CG A

y = I

DH

EI

F

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 78

Component tree algorithm: all values distinct (step 9)

I B B

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = B

Image Lowest Node nodes Disjoint sets

CG A

y = A

DH

EI

FB

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Page 40: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

40

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 79

Component tree algorithm: all values distinct (step 10)

I B B

D E F

G H I

A:7B:1C:9

D:6E:4 F:2

G:8H:5I:3DIF

E C

HA

B

G

x = B

Image Lowest Node nodes Disjoint sets

CG A

y = C

DH

EI

FB

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 80

Component tree algorithm: all values distinct

O(|V|)

O(|V|+|E|)

O(|E|.α(|E|,|V|))

O(|E|. α(|E|,|V|))

O(|E|)

O(|E|)

O(|E|)

foreach point x in V in decreasing order of altitude do

foreach neighbor y of x do

● If (F(y) > F(x)) and (Find(x) != Find(y)) do

– adjNode := lowestNode[Find(y)]

– nodes[x].addChild(nodes[adjNode])

– curNode := Link(x,adjNode)

– lowestNode[curNode] := nodes[x]

Time complexity : quasi-linear

with respect to the number of edges and vertices

Requires a sorting pre-processing step

Page 41: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

41

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 81

Component tree algorithm: general case

Two union-find implementations needed

One for building the union of connected components over height

● Similar to the one in the case where all values were distinct

One for building the connected components of a given altitude

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 82

Build the component tree

Page 42: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

42

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 83

Auxiliary functions

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 84

Example

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

12;

0;

2;

1;

14;

13;

3; 4; 5; 8; 9; 10; 11;

6;

7

[120]

[110]

[100]

[90]

[80]

[70]

[50]

[40]

[20]

Page 43: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

43

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 85

step 1

[12] 120

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 86

Step 2

[12] 120

0 1 1

3 4 5

12 13 14

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[0] 110

Page 44: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

44

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 87

step 3

[12] 120

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[0] 110 [2] 100

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 88

step 4

1 1 1

3 4 5

12 13 14

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[12] 120

[1] 90

[2] 100[0] 110

Page 45: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

45

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 89

step 5

1 1 1

3 4 5

12 13 14

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[12] 120

[1] 90

[2] 100[0] 110

[14] 80

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 90

step 6

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 1 1

3 4 5

13 13 13

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

Page 46: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

46

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 91

step 7

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 1

3 4 5

13 13 13

6 7 8

9 10 11

Fth1

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 92

step 8

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 1

3 3 5

13 13 13

6 7 8

9 10 11

Fth1

0 1 2

3 3 5

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50

Page 47: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

47

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 93

step 9

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

3 3 3

13 13 13

6 7 8

9 10 11

Fth1

0 1 2

3 3 3

12 13 14

6 7 8

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 94

step 10

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

3 3 3

13 13 13

6 7 3

9 10 11

Fth1

0 1 2

3 3 3

12 13 14

6 7 3

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50

Page 48: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

48

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 95

step 11

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

3 3 3

13 9 13

6 7 3

9 10 11

Fth1

0 1 2

3 3 3

12 13 14

6 7 3

9 10 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50 [9] 50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 96

step 12

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

3 3 3

13 9 13

6 7 3

9 9 11

Fth1

0 1 2

3 3 3

12 13 14

6 7 3

9 9 11

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[3] 50 [9] 50

Page 49: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

49

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 97

step 13

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

9 3 3

13 9 13

6 7 3

9 9 3

Fth1

0 1 2

9 3 3

12 13 14

6 7 3

9 9 3

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

9 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[9] 50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 98

step 14

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

1 3 3

9 3 3

13 9 13

9 7 3

9 9 3

Fth1

0 1 2

9 3 3

12 13 14

6 7 3

9 9 3

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

6 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[9] 50

[6] 40

Page 50: Motivation Connected Component Treecwjs70/C2CompTree.pdf · Connected components labeling with union-find 2 1 4 3 6 6 3 5 7 2 1 4 7 5 J. Serra, J. Cousty, B.S. Daya Sagar: Course

50

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 99

step 15

1 3 3

9 9 3

13 9 13

9 9 9

9 9 3

Fth1

0 1 2

9 3 3

12 13 14

6 7 3

9 9 3

Fth2

0 1 2

3 4 5

12 13 14

6 7 8

7 10 11

SubtreeRoot

110 90 100

50 50 50

120 70 80

40 20 50

50 50 50

[1] 90

[2] 100[0] 110 [12] 120 [14] 80

[13] 70

[9] 50

[6] 40

[7] 20

J. Serra, J. Cousty, B.S. Daya Sagar: Course on Math. Morphology 100

Component tree: conclusion

Another insight into connected filters (level sets stacking)

Useful to compute floodings

then attribute openings & closings

Efficient algorithm

Quasi-linear time

Easy implementation

Many applications in signal processing and image analysis

Important for computing connection values

There exist self-dual trees