07 binary images

42
Binary images Alain Boucher - IFI Image processing & Computer vision Xử lí ảnh và thị giác máy tính

Upload: jawad-ahmed

Post on 24-Apr-2015

65 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 07 Binary Images

Binary images

Alain Boucher - IFI

Image processing & Computer visionXử lí ảnh và thị giác máy tính

Page 2: 07 Binary Images

2

Binary images

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Several techniques exist to manipulate and process binary images (0:1)

Useful to process images resulting from segmentation

Page 3: 07 Binary Images

3

Pixel connexity

4-Connexity p and q are 4-connected if q is in N4(p)

8-Connexity p and q are 8-connected if q is in N8(p)

111

111

111

111

111

111

How many objects do you see here?

Page 4: 07 Binary Images

4

4 or 8 connexity?

Advice: Use different connexities for edges and regions

4-Connexity for regions 8-Connexity for edges

Region : 8-connectedEdge : 4-connected

Region : 4-connectedEdge : 8-connected

Page 5: 07 Binary Images

5

How to measure distances?

A

B

What is the distance between A and B?

Page 6: 07 Binary Images

6

Discrete distance between pixels

Distance D4 (Manhattan distance)D4(p,q) = |x-s | + |y-t |

Diamond shape centered on (x,y) Ex: D4 ≤ 2

2

212

21012

212

2

Page 7: 07 Binary Images

7

Discrete distance between pixels

Distance D8 (chessboard distance)D8(p,q) = maximum (|x-s| , |y-t|)

Square shape centered on (x,y) Ex: D8 ≤ 2

22222

21112

21012

21112

22222

Page 8: 07 Binary Images

8

Freeman coding

For coding directions in images, we use the Freeman code:

765

0x4

123

Using this, we can code contours (edges) starting from one pixel (top left pixel) and following it clockwise

3

0x2

1

Freeman code in 4-connexity

Freeman code in 8-connexity

Page 9: 07 Binary Images

9

Contour coding vs connexity

Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.

Page 10: 07 Binary Images

10

Connected component labeling

Connected component = all adjacent pixels (neighbors) belonging to the same entity (region)

A segmented image is only a map of pixels We wish to give a common tag (value) for each pixels belonging to

the same region/contour We wish to have a different tag for each region/contour

Used in post-segmentation

Page 11: 07 Binary Images

11

Connected component labeling

← Background← Segmented objects

We loop over all the image to give a unique number (label) for each region

All pixels from the same region must have the same number (label)

Page 12: 07 Binary Images

12

Connected component labeling

1

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 13: 07 Binary Images

13

Connected component labeling

11

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 14: 07 Binary Images

14

Connected component labeling

2111

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 15: 07 Binary Images

15

Connected component labeling

3111

22111

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 16: 07 Binary Images

16

Connected component labeling

23111

22111

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 17: 07 Binary Images

17

Connected component labeling

55

5555

265555

2

22111

2234111

223111

22111

First loop over the imageFor each pixel in a region, we set

or the smallest label from its top or left neighbors

or a new label

Loop

Neighbors?X

X

Page 18: 07 Binary Images

18

Connected component labeling

55

5555

265555

2

22111

2234111

223111

22111

Second loop over the imageFor each pixel in a region, we set

the smallest from its own label and the labels from its down and right neighbors

Loop

NeighborsX

XX

Page 19: 07 Binary Images

19

Connected component labeling

55

5555

225555

2

22111

2234111

223111

22111

Second loop over the imageFor each pixel in a region, we set

the smallestfrom its own label and the labels from its down and right neighbors

Loop

NeighborsX

XX

Page 20: 07 Binary Images

20

Connected component labeling

55

5555

225555

2

22111

2222111

222111

22111

Second loop over the imageFor each pixel in a region, we set

the smallestfrom its own label and the labels from its down and right neighbors

Loop

NeighborsX

XX

Page 21: 07 Binary Images

21

Connected component labeling

In two loops, we finished to label all regions

Sometimes, we need more than two loops example: spiral region !

We continue, go and back two ways, until no new change in labels

Page 22: 07 Binary Images

22

Connected component labeling

It is possible to do only one loop Manage a table of equivalences when 2 different

labels are neighbors

Page 23: 07 Binary Images

23

Edge labeling

To label edges, we can use the same algorithm We proceed the same way, escept that we use 8-

connexity we compare 4 neighbors instead of 2

Take care: normally the thickness of an edge is only one pixel erase all redondant pixels (non-maxima)

There are other algorithms for edges

?4

321

Page 24: 07 Binary Images

24

Closing contours

From gradient to contours (edges) The methods for gradient seen in that cours does not

necessarily closed contours Many holes and several isolated segments

We must « close the contours » for obtaining a segmentation equivalent to regions

Several methods exist, but nothing easy

Page 25: 07 Binary Images

25

Closing contours

Edge thickness Important condition: an

edge must have a thickness of 1 pixel (everywhere)

If the edge is too thick, or if it has many paths, we must follow the line of highest gradient

Source : lagaule.org/downloads/TC3_03_segmentation.ppt

Page 26: 07 Binary Images

26

Closing contours

Compute and follow the best path in the gradient At the end of edges, we look for the path leading to join

another edge extremity Follow the path of the highest gradient

We can have many possible paths Graphs of path possibilities Choosing paths the shortest / the strongest (gradient)

P0

Pf

edge

Arch of a possible solution

Source : lagaule.org/downloads/TC3_03_segmentation.ppt

Page 27: 07 Binary Images

27

Closing contours

Hysteresis thresholding Define two thresholds

low threshold: minimum to be an edge high threshold: minimum to be edge of an object

(1) Threshold using the high threshold(2) Add the connected edges higher than the low

threshold

Source : Jérome Vicente. Cours de Traitement d'images. IUSTI. iusti.polytech.univ-mrs.fr/~vicente/

(1) Edges found with the high threshold

(2) Edges added using the low

threshold

Page 28: 07 Binary Images

28

Morphological operators

Widely used on binary images (mask images) but also on gray level images

Can change the shape (morphology) of objects To clean the result of segmentation

Fill in the holes, eliminate the noise To smooth the result of segmentation

Used in post-segmentation

Main characteristics a structuring element transforms

erosion, dilation, opening (erosion & dilation), closing (dilation & erosion)

Page 29: 07 Binary Images

29

Morphological operators

Given a binary images with background=0 and object=1

The structrural element « moves » on the object borders (inside and outside) and transform them:

object pixels into background pixels (erosion) background pixels into object pixels (dilation)

Examples of structural elements:

4-Connexity 8-Connexity

There exist other shapes for structural elements, symmetric or not

Page 30: 07 Binary Images

30

Morphological operators

Erosion If a mask pixel is background (value = 0)

then the central pixel becomes background Dilation

If a mask pixel is object (value > 0)then the central pixel becomes object

Opening Erosion then dilation

Closing Dilation then erosion

Page 31: 07 Binary Images

31

Erosion

We put the element B on each pixel x of A like convolution

If all pixels of B are onto object pixels (A), then the central pixel belongs to object

otherwise, set to background

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Structuringelement B

Page 32: 07 Binary Images

32

Dilation

Moving B onto A, for each pixels of A, check if the intersection (pixels belonging to object) is not empty

If yes, the center of B belongs to the result image

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Structuringelement B

Page 33: 07 Binary Images

33

How many objects?

How many objects? 1 or 2 ?

And after one erosion? And after one dilation?

Risk of merging or splitting of objects...

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Page 34: 07 Binary Images

34

Example: erosion + dilation

X X X X X X X X X X X XX X X X X X X XX X X X X X X X X X X X

InitialAfter erosion

X After dilation (final)

Page 35: 07 Binary Images

35

Example of dilation

Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.

Page 36: 07 Binary Images

36

Erosion - dilation

AvantAprès

AvantAprès

Source : Pascal Bertolino, LIS, www.lis.inpg.fr/pages_perso/bertolino/

structural element

erosion

dilation

beforeafter

beforeafter

Page 37: 07 Binary Images

37

Opening - closing

Source : Pascal Bertolino, LIS, www.lis.inpg.fr/pages_perso/bertolino/

structural element

opening

closing

Page 38: 07 Binary Images

38Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.

Page 39: 07 Binary Images

39

Influence of the structural element

Input imageDilation 4-neighbors Dilation 8-

neighbors

Erosion 4-neighbors Erosion 8-neighbors

4-neighbors 8-neighbors

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Page 40: 07 Binary Images

40

Summary example

Input image

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Erosion Opening

Closing Dilation

Page 41: 07 Binary Images

41

Morphological gradient

Input image – Erosion image = internal gradient

Dilation image – Input image = External gradient

Internal gradient: inside contour/edge

External gradient: outside contour/edge

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.

Page 42: 07 Binary Images

42

Morphological gradient

Dilation image – Erosion image = Morphological gradient

Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.