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} B’[r][c] – complement or inverse of B = 1 if B[r][c]=0 = 0 if B[r][c]=1 Gray-scale image = range of I is in {min, min+1,…,max-1,max} Multispectral image = vector-valued ► Ex. Color image = range is in { | (r,g,b) in {0,1,…,max} }
How do we create binary images? ► By selecting (foreground) pixels of interest and thereby separating them from background pixels = segmentation Ex. Thresholding = selecting ranges of gray (or color) values ► Ex. 1 if value>100 0 otherwise 0 = background 1 = foreground
Pixel and its neighbors ► 4-neighbors/4-adjacent/4-connected {,,, } Or as displacements: ► {,,, } ► How about 8-adjacent? Distances?
Masks
► Mask = set of pixel positions and corresponding values called weights ► Mask origin = usually center ► How? 1.Calculate sum of products ► Boundary 1.Replicate nearest pixel value 2.Use 0 2.Normalize (or an amplitude shift will occur) Applying masks to images
► Derived from convolution: ► Discrete form is cross correlation: ► where f is the input image, h is the mask/filter kernel, and g is the output image result
Convolution ► See for some nice animations.
1*40+2*40+1*80+ 2*40+4*40+2*80+ 1*40+2*40+1*80 =800
1*40+2*80+1*80+ 2*40+4*80+2*80+ 1*40+2*80+1*80 =1120
But what about borders? ► When we are missing data at the edges, we typically do one of the following: 1.Copy to the missing value, the nearest neighboring value. 2.Use 0 for the missing value(s). (Regardless, it really doesn’t matter, but we need to consistently do something.)
1*40+2*40+1*40+ 2*40+4*40+2*40+ 1*40+2*40+1*40 =640 Method 1: copy nearest
The importance of normalizing the result. ► Otherwise, the values might get larger and larger (brighter and brighter).
=16 640/16
Counting objects (instead of holes) ► If we complement our masks from the hole counting algorithm, we can count objects! ► (Or if we complement our image, we can count objects!)
I don’t care for this format!
Object counting assumptions (complement of hole counting assumptions) 1. All image border pixels must be 0s. 2. Each region of 1s (objects) must be 4- connected. 3. Objects must also be simply connected (not contain any holes).
Implement object counting algorithm ► Check assumptions 1 and 2. (Skip 3 for now.) ► Report number of objects. ► Exercise 3.1 p Efficiency of counting objects. What is the maximum number of times that the function count_objects examines each pixel of the image? How can functions external_match and internal_match be coded to be as efficient as possibly?
More object analysis ► So far, we can count objects! But how big are they? What shape are they?
Paths There exists a path from (x 1,y 1 ) to (x n,y n ) iff there exists a sequence (x 1,y 1 ), (x 2,y 2 ), …, (x n,y n ) s.t. all (x i,y i ) and (x i+1,y i+1 ) are (4- or 8-) connected and B(x i,y i )=B(x i+1,y i+1 ).
Connected component A connected component of value v is a set of pixels C with: 1.each having value v 2.and for every c and d in C, there exists a path from c to d.
Objects are 1s (and white) here.
Labels ► 0 = background (not part of any object) ► 1 = first labeled object ► 2 = second labeled object ► … ► -1 = part of an unlabeled object (ready for labeling)
I don’t care for this format! Recursive connected components algorithm: 3 functions
I don’t care for this format! Recursive connected components algorithm // 0 --> 0; 1 --> -1 // incremented before use so first will actually be 1
I don’t care for this format! Recursive connected components algorithm (Why not use r and c instead of L and P, respectively?)
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 for nice animations).
Begin skip other algorithms in this section.
End skip.