Introduction to Digital Image Processing with MATLAB Asia
Introduction to Digital Image Processing with MATLAB® Asia Edition Mc. Andrew‧Wang‧Tseng Chapter 11: Image Topology 1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1
11. 1 Introduction • We are often interested in only the very basic aspects of an image: ü The number of occurrences of a particular object ü Whether or not there are holes, and so on • The investigation of these fundamental properties of an image is called digital topology or image topology 2 Ch 11 -p. 307 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 1 3 Ch 11 -p. 308 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 2 Neighbor and Adjacency • A first task is to define the concept of adjacency: under what conditions a pixel may be regarded as being next to another pixel • For this chapter, the concern will be with binary images only, and thus we will be dealing only with positions of pixels 4 Ch 11 -p. 307 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 3 Paths and Components • P and Q are any two (not necessarily adjacent) pixels ü If the path contains only 4 -adjacent pixels, as the path does in the below diagram, then P and Q are 4 -connected p 5 p 2 p 3 p 4 p 1 p 0 5 Ch 11 -p. 308 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 3 Paths and 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 Two 4 -component One 8 -component 6 Ch 11 -p. 309 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 4 Equivalence Relations • A relation x ∼ y between two objects x and y is an equivalence relation if the relation is 1. Reflexive, x ∼ x for all x, 2. Symmetric, x ∼ y ⇐⇒ y ∼ x for all x and y, 3. Transitive, if x ∼ y and y ∼ z, then x ∼ z for all x, y, and z 1. Here are some relations that are not equivalence relations 1. Personal relations 2. Pixel adjacency 3. Subset relation 7 Ch 11 -p. 310 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling u l 8 Ch 11 -p. 310 p © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling 9 Ch 11 -p. 311 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling Step 1. We start moving along the top row. The first foreground pixel is the bullet in the second place, and since its upper and left neighbors are either background pixels or nonexistent, we assign it the label 1. 10 Ch 11 -p. 311 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling 11 Ch 11 -p. 313 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling Step 2. We have the following equivalence classes of labels: Assign label 1 to the first class and label 2 to the second class. 12 Ch 11 -p 313 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling 13 Ch 11 -p 314 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling ü Diagonal elements of p used to label 8 -components of an image 14 Ch 11 -p. 314 d u l p e © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling • e. g. 15 Ch 11 -p. 314 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling 16 Ch 11 -p. 315 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 5 Component Labeling figure, imshow(bt) 17 Ch 11 -p. 316 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 6 Lookup Tables • Lookup tables provide a very neat and efficient method of binary image processing 18 20 23 26 21 24 27 22 25 28 Ch 11 -p. 316 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 6 Lookup Tables 19 Ch 11 -p. 317 © 2010 Cengage Learning Engineering. All Rights Reserved.
Figure 11. 2 20 Ch 11 -p. 318 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 3 21 Ch 11 -p. 318 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics • It is necessary to define a function that provides a measure of distance between two points x and y on a grid • A distance function d(x, y) is called a metric if it satisfies the following: 1. d(x, y) = d(y, x) (symmetry) 2. d(x, y) ≥ 0 and d(x, y) = 0 if and only if x = y (positivity) 3. d(x, y) + d(y, z) ≤ d(x, z) (the triangle inequality) 22 Ch 11 -p. 319 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 4 23 Ch 11 -p. 319 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics • 11. 7. 1 The Distance Transform 1. Attach to each pixel (x, y) in the image a label d(x, y), giving its distance from R. Start with labeling each pixel in R with 0 and each pixel not in R with ∞ 2. We now travel through the image pixel by pixel. For each pixel (x, y) replace its label with min{d(x, y), d(x + 1, y) + 1, d(x − 1, y) + 1, d(x, y − 1) + 1, d(x, y + 1) + 1} using ∞ + 1 = ∞ 24 Ch 11 -p. 320 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics 3. Repeat Step 2 until all labels have been converted to finite values 1 1 1 1 min 3 ü e. g. 25 Ch 11 -p. 320 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics ü e. g. another mask Divide all values by 3 26 Ch 11 -p. 322 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics ü e. g. another mask 27 Ch 11 -p. 322 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics ü A quicker method requires two passes only: Ø The first pass starts at the top left of the image and moves left to right, top to bottom Ø The second pass starts at the bottom right of the image and moves right to left, from bottom to top 28 Ch 11 -p. 322 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 5 29 Ch 11 -p. 323 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics ü IMPLEMENTATION IN MATLAB 1. Using the size of the mask, pad the image with an appropriate number of 0 s 2. Change each 0 to infinity, and each 1 to 0 3. Create forward and backward masks 4. Perform a forward pass. Replace each label with the minimum of its neighborhood plus the forward mask 5. Perform a backward pass. Replace each label with the minimum of its neighborhood plus the backward mask 30 Ch 11 -p. 324 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 6 31 Ch 11 -p. 326 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics 32 Ch 11 -p. 326 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics 33 Ch 11 -p. 327 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics 34 Ch 11 -p. 327 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 7 Distances and Metrics 35 Ch 11 -p. 328 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 36 Ch 11 -p. 329 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 9 37 Ch 11 -p. 330 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • Medial axis 38 Ch 11 -p. 331 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • Connectivity 39 Ch 11 -p. 331 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 12 & 11. 13 40 Ch 11 -p. 332 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization ü A pixel can be tested for deletability by checking its 3× 3 neighborhood ü Suppose the central pixel is deleted. There are two options: 1. The top two pixels and the bottom two pixels become separated, in effect breaking up the object 2. The top two pixels and the bottom two pixels are joined by a chain of pixels outside the shown neighborhood (as shown in Figure 11. 12) 41 Ch 11 -p. 332 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 14 42 Ch 11 -p. 332 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 15 43 Ch 11 -p. 333 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • 11. 8. 1 Calculating A(p) and C(p) ü The number of times the subsequence 0, 1 occurs is the crossing number 44 Ch 11 -p. 334 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization ü If X(p) = 1, then A(p) = 1 and thus p is 4 -simple X(p) = 2 ü Implementing the crossing number in MATLAB 45 Ch 11 -p. 334 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization ü Calculating C(p) 46 Ch 11 -p. 336 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • 11. 8. 3 The Zhang-Suen Skeletonization Algorithm Ø Step N Flag a foreground pixel p = 1 to be deletable if 1. 1. 2 ≤ B(p) ≤ 6, 2. X(p) = 1, 3. If N is odd, then p 2 · p 4 · p 6 = 0 p 4 · p 6 · p 8 = 0 If N is even, then p 2 · p 4 · p 8 = 0 p 2 · p 6 · p 8 = 0 47 Ch 11 -p. 337 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 16 48 Ch 11 -p. 338 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 17 49 Ch 11 -p. 339 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 18 50 Ch 11 -p. 339 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 19 51 Ch 11 -p. 340 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 20 52 Ch 11 -p. 340 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 21 53 Ch 11 -p. 341 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 54 Ch 11 -p. 341 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 22 55 Ch 11 -p. 342 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • 11. 8. 4 The Guo-Hall Skeletonization Algorithm ü We imagine the image grid being labeled with 1 s and 2 s in a chessboard configuration: ü At step one, we only consider foreground pixels whose labels are 1. At step two, we only consider foreground pixels whose labels are 2 56 Ch 11 -p. 343 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • Consider our L example from above ü We first superimpose a chessboard of 1 s and 2 s. Step 1 shown in Figure 11. 23 illustrates the first step: we delete only those 1 s satisfying the Guo-Hall deletablity conditions ü These pixels are shown in squares. Having deleted them, we now consider 2 s only; the deletable 2 s are shown in step 2 57 Ch 11 -p. 343 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 23 58 Ch 11 -p. 343 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 24 ü Steps 3 and 4 continue the work; by step 4 there are no more deletions to be done, and we stop 59 Ch 11 -p. 344 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization ü We notice two aspects of the Guo-Hall algorithm as compared with Zhang-Suen: 1. More pixels may be deleted at each step, so we would expect the algorithm to work faster 2. The final result includes more corner information than the Zhang-Suen algorithm ü We can implement this in MATLAB using very similar means to our implementation of Zhang-Suen 60 Ch 11 -p. 344 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 25 61 Ch 11 -p. 345 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 62 Ch 11 -p. 345 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 26 63 Ch 11 -p. 346 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 27 64 Ch 11 -p. 346 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 28 & 29 65 Ch 11 -p. 347 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization • 11. 8. 5 Skeletonization Using the Distance Transform ü The distance transform can be used to provide the skeleton of a region R 66 Ch 11 -p. 347 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 67 Ch 11 -p. 347 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 68 Ch 11 -p. 348 © 2010 Cengage Learning Engineering. All Rights Reserved.
11. 8 Skeletonization 69 Ch 11 -p. 349 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 11. 30 70 Ch 11 -p. 349 © 2010 Cengage Learning Engineering. All Rights Reserved.
- Slides: 70