chapter 3 binary image analysis. types of images ► digital image = i[r][c] is discrete for i, r,...

44
Chapter 3 Chapter 3 Binary Image Analysis Binary Image Analysis

Upload: clinton-washington

Post on 25-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Chapter 3Chapter 3

Binary Image AnalysisBinary Image Analysis

Page 2: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Types of imagesTypes of images

►Digital image = I[r][c] is discrete for I, r, and Digital image = I[r][c] is discrete for I, r, and c.c. B[r][c] = binary image - range of I is in {0,1}B[r][c] = binary image - range of I is in {0,1} B’[r][c] – complement or inverse of BB’[r][c] – complement or inverse of B

= 1 if B[r][c]=0= 1 if B[r][c]=0

= 0 if B[r][c]=1= 0 if B[r][c]=1

Gray-scale image = range of I is in {min, min+1,Gray-scale image = range of I is in {min, min+1,…,max-1,max}…,max-1,max}

Multispectral image = vector-valuedMultispectral image = vector-valued►Ex. Color image = range is in {<r,g,b> | (r,g,b) in {0,1,Ex. Color image = range is in {<r,g,b> | (r,g,b) in {0,1,

…,max} }…,max} }

Page 3: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

How do we create binary How do we create binary images?images?

►By selecting (foreground) pixels of By selecting (foreground) pixels of interest and thereby separating them interest and thereby separating them from background pixels = segmentationfrom background pixels = segmentation Ex. Thresholding = selecting ranges of gray Ex. Thresholding = selecting ranges of gray

(or color) values(or color) values►Ex.Ex.

1 if value>1001 if value>100 0 otherwise0 otherwise

0 = background0 = background 1 = foreground1 = foreground

Page 4: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 5: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 6: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 7: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 8: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Pixel and its neighborsPixel and its neighbors

►4-neighbors/4-adjacent/4-connected4-neighbors/4-adjacent/4-connected { <r-1,c>, <r+1,c>, <r,c-1>, <r,c+1> }{ <r-1,c>, <r+1,c>, <r,c-1>, <r,c+1> } Or as displacements:Or as displacements:

►{ <-1,0>, <+1,0>, <0,-1>, <0,+1> }{ <-1,0>, <+1,0>, <0,-1>, <0,+1> }

►How about 8-adjacent?How about 8-adjacent? Distances?Distances?

Page 9: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

MasksMasks

Page 10: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

► Mask = set of pixel positions and Mask = set of pixel positions and corresponding values called weightscorresponding values called weights

► Mask origin = Mask origin = usuallyusually center center► How?How?

1.1. Calculate sum of productsCalculate sum of products► BoundaryBoundary

1.1. Replicate nearest pixel valueReplicate nearest pixel value

2.2. Use 0Use 0

2.2. Normalize (or an amplitude shift will occur)Normalize (or an amplitude shift will occur)

Applying masks to imagesApplying masks to images

Page 11: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Applying masks to imagesApplying masks to images

►Derived from convolution:Derived from convolution:

►Discrete form is cross correlation:Discrete form is cross correlation:

► where f is the input image, h is the mask/filter kernel, and g is the output where f is the input image, h is the mask/filter kernel, and g is the output image resultimage result

ydxdyxfyyxxhyxfyxh ,,,,yx,g

x y

yxfyyxxhyxfyxh ,,,,yx,g

Page 12: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

ConvolutionConvolution

►See See http://en.wikipedia.org/wiki/Convolution for some nice animations. for some nice animations.

Page 13: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 14: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

1*40+2*40+1*80+

2*40+4*40+2*80+

1*40+2*40+1*80

=800

Page 15: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

1*40+2*80+1*80+

2*40+4*80+2*80+

1*40+2*80+1*80

=1120

Page 16: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

But what about borders?But what about borders?

►When we are missing data at the edges, When we are missing data at the edges, we typically do one of the following:we typically do one of the following:1.1. Copy to the missing value, the nearest Copy to the missing value, the nearest

neighboring value.neighboring value.

2.2. Use 0 for the missing value(s).Use 0 for the missing value(s).

(Regardless, it really doesn’t matter, but (Regardless, it really doesn’t matter, but we need to consistently do something.)we need to consistently do something.)

Page 17: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 18: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

1*40+2*40+1*40+

2*40+4*40+2*40+

1*40+2*40+1*40

=640

Method 1: copy nearest

Page 19: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

The importance of The importance of normalizing the result.normalizing the result.

►Otherwise, the values might get larger Otherwise, the values might get larger and larger (brighter and brighter).and larger (brighter and brighter).

Page 20: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

1+2+1+

2+4+2+

1+2+1

=16

640/16

Page 21: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

1 2 1

2 4 2

1 2 1

Page 22: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Counting objects (instead of Counting objects (instead of holes)holes)

► If we complement our masks from the If we complement our masks from the hole counting algorithm, we can count hole counting algorithm, we can count objects!objects!

►(Or if we complement our image, we (Or if we complement our image, we can count objects!)can count objects!)

Page 23: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

I don’t care for this format!

Page 24: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Object counting assumptions Object counting assumptions (complement of hole counting (complement of hole counting

assumptions)assumptions)

1.1. All image border pixels must be 0s.All image border pixels must be 0s.

2.2. Each region of 1s (objects) must be Each region of 1s (objects) must be 4-connected4-connected..

3.3. Objects must also be Objects must also be simply simply connectedconnected (not contain any holes). (not contain any holes).

Page 25: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Implement object counting Implement object counting algorithmalgorithm

► Check assumptions 1 and 2.Check assumptions 1 and 2. (Skip 3 for now.)(Skip 3 for now.)

► Report number of objects.Report number of objects.

► Exercise 3.1 p. 56 - Efficiency of counting objects.Exercise 3.1 p. 56 - Efficiency of counting objects.

What is the maximum number of times that the function What is the maximum number of times that the function count_objectscount_objects examines each pixel of the image? examines each pixel of the image?

How can functions How can functions external_matchexternal_match and and internal_matchinternal_match be coded to be as efficient as possibly?be coded to be as efficient as possibly?

Page 26: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

More object analysisMore object analysis

►So far, we can count objects!So far, we can count objects!

But how big are they?But how big are they?

What shape are they?What shape are they?

Page 27: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

PathsPaths

There exists a path from (xThere exists a path from (x11,y,y11) to (x) to (xnn,y,ynn))

iff there exists a sequence (xiff there exists a sequence (x11,y,y11), ), (x(x22,y,y22), … , (x), … , (xnn,y,ynn))

s.t. all (xs.t. all (xii,y,yii) and (x) and (xi+1i+1,y,yi+1i+1) are (4- or 8-) ) are (4- or 8-) connected and B(xconnected and B(xii,y,yii)=B(x)=B(xi+1i+1,y,yi+1i+1).).

Page 28: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Connected componentConnected component

A connected component of value v is a A connected component of value v is a set of pixels C with:set of pixels C with:

1.1. each having value veach having value v

2.2. and for every c and d in C, there exists a and for every c and d in C, there exists a path from c to d.path from c to d.

Page 29: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Objects are 1s (and white) here.

Page 30: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

LabelsLabels

►0 = background (not part of any object)0 = background (not part of any object)

►1 = first labeled object1 = first labeled object►2 = second labeled object2 = second labeled object►……

►-1 = part of an unlabeled object (ready -1 = part of an unlabeled object (ready for labeling)for labeling)

Page 31: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

I don’t care for this format!

Recursive connected components algorithm:

3 functions

Page 32: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

I don’t care for this format!

Recursive connected components algorithm

// 0 --> 0; 1 --> -1// incremented before use so first will actually be 1

Page 33: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

I don’t care for this format!

Recursive connected components algorithm

(Why not use r and c instead of L and P, respectively?)

Page 34: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

I don’t care for this format!

Recursive connected components algorithm

<-- What does this mean/do?

<-- recursion!

This is an example of a flood fill algorithm (see http://en.wikipedia.org/wiki/Flood_fill for nice animations).

Page 35: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

Begin skip other Begin skip other algorithms in this algorithms in this

section.section.

Page 36: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 37: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 38: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 39: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 40: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 41: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 42: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 43: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}
Page 44: Chapter 3 Binary Image Analysis. Types of images ► Digital image = I[r][c] is discrete for I, r, and c.  B[r][c] = binary image - range of I is in {0,1}

End skip.End skip.