Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

25
Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai

Transcript of Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

Page 1: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

Digital Image Processing Lecture 12: Image TopologyProf. Charlene Tsai

Page 2: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

2

Introduction

Definition: The study of properties of a figure that are unaffected by any deformation, as long as there is no tearing or joining of the figure.

A region with 2 holes

A region with 3 connected

components (objects)

Page 3: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

3

Another example

How many bacteria here?

Page 4: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

4

Neighbors and Adjacency We often have interests in classifying pixels into

different categories Neighbourhoods:

Two pixels P and Q are 4-adjacent if they are 4-neighbours of one another, and 8-adjacent if they are 8-neighbours of one another.

4 4-nghbr

• P •

• • •

• P •

• • •

8 8-nghbr

4-adjacent 8-adjacent

Page 5: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

5

Paths Suppose that P and Q are any two pixels (not

necessarily adjacent), and suppose P and Q can be joined by a sequence of pixels as shown:

If the path contains only 4-adjacent pixels, then P, Q are 4-connected.

If the path contains 8-adjacent pixels, then P and Q are 8-connected

4-adjacent

4-connected

8-adjacent

8-connected

Page 6: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

6

Components

A set of pixels all of which are 4-connected to each other is called a 4-component; if all the pixels are 8-connected the set is an 8-component.

4-component4-component

One 8-component

Page 7: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

7

Formal Definition of a Path

A 4-path from P to Q is a sequence of pixels

P = p0, p1, p2, …, pn = Q

such that for each i=0,1,…, n-1, pixel pi is 4-adjacent to pixel pi+1.

An 8-path is where the pixels in the sequence connecting P and Q are 8-adjacent

Page 8: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

8

Properties of Connectivity – Equivalence Relations

A relation x~y between two objects x and y is an equivalence relation if the relation is Reflexive: Symmetric: Transitive:

Examples for equivalence relation? Examples that are not equivalence relation?

Page 9: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

9

Equivalence Relations

The importance of the equivalence relation concept is that it allows us a very neat way of dealing with issues of connectedness.

Equivalence class: the set of all objects equivalent to each other.

Examples of some relations which are not equivalence:

— Personal relations— Subset relation— Pixel adjacency

Some examples:

— Numeric equality

— Set cardinality— Connectedness

Page 10: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

10

Connected Component Labelling Define the components of a binary image as

being the equivalence classes of the connectedness equivalence relation.

Finding all equivalence classes of connected pixels in a binary image is called connected component labelling.

The result of connected component labeling is another image in which everything in one connected region is labelled "1" (for example), everything in another connected region is labelled "2", etc.

Page 11: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

11

Connected Component Labelling (con’d) Labelling all the 4-components of a binary

image, starting a the top left and working across and down. “Scan” the image row by row moving across from

left to right. Assign labels to pixels in the image; these labels

will be the numbers of the components of the image.

A pixel in the image will be called a foreground pixel (fp); a pixel not in the image will be called a background pixel (bp).

Page 12: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

12

Connected Component Labeling: Algorithm1. Check the state of p. If it is a bp, move on to the

next scanning position. If it is fp, check the state of u and l. If they are both bp, assign p a new label.

If only one of u and l are fp, assign the label to p If both u and l are fp, but different labels, assign

either label to p, and make the 2 labels equivalent.2. At the end of the scan, all foreground pixels

have been labelled, but some labels may be equivalent. Then sort the labels into equivalence classes, and assign a different label to each class.

3. Do a second pass through the image, replacing the label on each foreground pixel with the label assigned to its equivalence class in the previous step

u

l p

Page 13: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

13

Example 1

Step 1.

The first foreground pixelUpper neighbor : non-existentLeft neighbor : background

First foreground pixel in 2nd rowUpper neighbor : background Left neighbor : non-existent

2nd foreground pixel in 2nd rowUpper neighbor : foregroundLeft neighbor : foreground

3rd foreground pixel in 2nd rowUpper neighbor : backgroundLeft neighbor : background

Page 14: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

14

Step 2. We have the following equivalent classes of labels

{1,2} and {3, 4,5}

Assign label 1 to the first class, and label 2 to the second class

Step 3. Each pixel with labels 1 or 2 from the first step will be assigned label 1, and each pixel with labels 3, 4, or 5 from the first step will be assigned label 2

1st foreground pixel in 3rd row: Upper neighbor :backgroundLeft neighbor : background

1st foreground pixel in 3rd row: Upper neighbor :foreground ( label 3)Left neighbor : foreground (label 4)

Page 15: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

15

Example 2

Original Binary image Pass 1:

Pass 2:

Page 16: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

16

Example 3Original Binary image Pass 1:

Pass 2:

Page 17: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

17

Matlab bwlabel Function Syntax:

Description: L = bwlabel(BW,n) returns a matrix L, of the same size as

BW, containing labels for the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects (defaults to 8).

The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on.

[L,num] = bwlabel(BW,n) returns in num the number of connected objects found in BW.

See the supplemental notes on using lookup table.

L = bwlabel(BW,n)[L,num] = bwlabel(BW,n)

Page 18: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

18

Distances and Metrics

A distance function d(x,y) is called a metric if it satisfies the following: 1. 2. 3.

A standard distance metric is Euclidean distance (a straight line between 2 points)

where

(symmetry) ,, xydyxd y)(positivit iff 0, and 0, yxyxdyxd inquality) triangle(the ,,, zxdzydyxd

222

211, yxyxyxd

2121 , and , yyyxxx

Page 19: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

19

Distance Metrics for Grid

The Euclidean distance is For 4-path and 8-path?

yxd ,8 yxd ,4

39.525 22

metric) (taxicab , 22114 yxyxyxd

,max, 22118 yxyxyxd

Page 20: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

20

The Distance Transform

How to find the distance of every pixel from a region R?

A well-known method is Chamfering Algorithm:

Given: subset S of image Initialization: elements of S contain 0, and for others. Step1: Row by row, from top to bottom and left to right:

Step2: Row by row, from bottom to top and right to left:

)(),(),(min)( qFqpMpFpF f

pNq

)(),(),(min)( qFqpMpFpF b

pNq

Page 21: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

21

Masks for Chamfering

Mask1:

Mask2: 3-4 chamfer (most popular)

1

1 0 0 1

1

4 3 4

3 0 0 3

4 3 4

Forward mask, Mf Backward mask, Mb

Forward mask, Mf Backward mask, Mb

Page 22: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

22

Masks for Chamfering (con’d) Mask 3:

11 11

11 7 5 7 11

5 0 0 5

11 7 5 7 11

11 11

Forward mask, Mf Backward mask, Mb

Page 23: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

23

Example

Initialization:(using 3-4 chamfer)

Step1: ???

Step2: ???

0 0

0

0

0

)(),(),(min)( qFqpMpFpF f

pNq

)(),(),(min)( qFqpMpFpF b

pNq

4 3 4

3 0 3

4 3 4

fwbw

Page 24: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

24

Summary

We discussed Neighbors and Adjacency Definition of path Equivalence relation Component labeling Distance metrics

Euclidean distance Metrics for 4- and 8-path Chamfering

Page 25: Digital Image Processing Lecture 12: Image Topology Prof. Charlene Tsai.

25