SHAPE ANALYSIS INEL 6088 Computer Vision Refs.: ch. 6, Davies; Ch. 2 Jain et al.
TOPICS • Connected components • CC Labeling • Image moments • Geometrical properties: position and orientation • Region-boundary following Algorithm • Distance-metrics and skeleton • Morphological operations
DEFINITIONS Foreground S : set of all1- pixels A pixel p in S is connected to 4-neighbors 8-neighbors another pixel q in S if there is a path from p to q consisting only of 1-pixels in S . connected component: set of pixels in which all pixels are connected to all other pixels. Examples of a 4-path and an 8- path. A path is a sequence of pixel indices such that the pixels are neighbors. Ref: connected components: sec. 3.3.4 Szelinski
DEFINITIONS S : complement of S background : set of all 4-neighbors 8-neighbors connected components of S that have points in the border of an image. holes: components of S that are not background. Examples of a 4-path and an 8- path. A path is a sequence of pixel indices such that the pixels are neighbors. Ref: connected components: sec. 3.3.4 Szelinski
If 1’s are connected they should isolate the 0 Ambiguous! Boundary S’’: set of pixels in S that have neighbors in S Use 8-connectivity Interior: set of pixels in S that are not for the foreground in S’’ and 4-connectivity for the background Surroundings T of region S: any 4-path or vice versa. from a pixel in S to the border of the image must intersect T
CONNECTED COMPONENT (OBJECT) LABELING Recursive algorithm: 1. Scan the image to find an unlabelled 1 pixel and assign it a new label L 2. Recursively assign a label L to all its 1 neighbours 3. Stop if there are no more neighbouring un-labeled 1 pixels 4. Go to step 1
Sequential Algorithm 1. Scan image left-to-right, top-to-bottom 2. If a pixel is 1, a) if only one of its upper or left neighbours has a label, or if both have the same label, copy the label b) if both have different labels, copy the upper’s label and enter the labels as equivalent in the equivalence table c) otherwise, assign a new label to this pixel 3. Repeat step 2 until there are no more pixels to consider 4. Eliminate equivalent labels (see tables 6.1 - 6.5 in Jain et.al. for an example)
6.3 Object Labeling and Counting 165 1 2 2 1 2 2 1 2 2 1 1 1 1 1 3 3 1 4 1 4 3 3 1 1 4 4 3 3 1 1 1 4 4 3 3 1 1 1 5 6 5 7 7 8 8 6 5 7 7 8 8 6 5 7 7 8 6 5 5 7 7 Figure 6.5 Solving the labeling problem in a more complex case. See textbook by Davies using a minimum rather than a maximum labehng convention, so that the values are in general sUghtly closer to the eventual ideal labels. (This also serves to demonstrate that there is not just one way of designing a suitable labeling algorithm.) The algorithm itself indicates that the coexist table should now appear as in Table 6.1. However, the whole process of calculating ideal labels can be made more efficient by inserting numbers instead of ticks, and also adding the right numbers along the leading diagonal, as in Table 6.2. For the same reason, the numbers below the leading diagonal, which are technically redundant, are retained here. The next step is to minimize the entries along the individual rows of the table, as in Table 6.3; next we minimize along the individual columns (Table 6.4); and then we minimize along rows again (Table 6.5). This process is iterated to completion, which has already happened here after three stages of minimization. We can now read off the final result from the leading diagonal. Note that a further stage of computation is needed to make the resulting labels consecutive integers, starting with unity. However, the procedure needed to achieve this is much more basic and does not need to manipulate a 2-D table of data. This will be left as a simple programming task for the reader. At this point, some comment on the nature of the process described above will be appropriate. What has happened is that the original image data have effectively been condensed into the minimum space required to express the
1 66 CHAPTER 6 Binary Shape Analysis Table 6.1 Coexist table for the image of Fig. 6.4* V V V V *The ticks correspond to clashes of labels. Table 6.2 Coexist table with additional numerical information* 1 2 3 4 5 6 7 8 1 1 1 1 2 1 2 3 1 3 3 4 3 4 5 5 5 6 6 6 7 5 7 7 8 6 7 8 *This coexist table is an enhanced version of Table 6.3. Technically, the numbers along, and below, the leading diagonal are redundant, but nevertheless they speed up the subsequent computation. Table 6.3 Coexist table redrawn with minimized rows. At this stage the table is no longer symmetrical 1 1 3 3 5 5 6 6 5 5 5 6 6 6
1 66 CHAPTER 6 Binary Shape Analysis Table 6.1 Coexist table for the image of Fig. 6.4* V V V V *The ticks correspond to clashes of labels. Table 6.2 Coexist table with additional numerical information* 1 2 3 4 5 6 7 8 1 1 1 1 2 1 2 3 1 3 3 4 3 4 5 5 5 6 6 6 7 5 7 7 8 6 7 8 *This coexist table is an enhanced version of Table 6.3. Technically, the numbers along, and below, the leading diagonal are redundant, but nevertheless they speed up the subsequent computation. Table 6.3 Coexist table redrawn with minimized rows. At this stage the table is no longer symmetrical 1 1 3 3 5 5 6 6 5 5 5 6.3 Object Labeling and Counting 1 67 6 6 6 Table 6.4 Coexist table redrawn again with minimized columns 1 1 1 1 2 1 1 3 1 1 1 4 1 1 5 6 5 7 5 5 5 5 Table 6.5 Coexist table redrawn yet again with minimized rows. At this stage the table is in its final form and is once again symmetrical 1 2 3 4 5 6 7 8 1 1 1 1 2 1 1 3 1 1 1 4 1 1 5 6 5 7 5 5 5 5 labels—namely, just one entry per original clash. This explains why the table retains the 2-D format of the original image: lower dimensionahty would not permit the image topology to be represented properly. It also explains why minimization has to be carried out, to completion, in two orthogonal directions. On the other hand, the particular implementation, including both above- and below-diagonal elements, is able to minimize computational overheads and finalize the operation in remarkably few iterations. Finally, it might be felt that too much attention has been devoted to finding connected components of binary images. This is a highly important topic in practical applications such as industrial inspection, where it is crucial to locate all the objects unambiguously before they can individually be identified and scrutinized. In addition. Fig. 6.5 makes clear that it is not only U-shaped objects that give problems, but also those that have shape subtleties—as happens at the left of the upper object in this figure.
IMAGE MOMENTS AND GEOMETRICAL PROPERTIES n m ∑ ∑ p+q order moments: i p j q B ij m pq = i =1 j =1 For binary images B(i,j) = 1 for pixels in CC n m ∑ ∑ 0-order moment = Area: m pq = B ij i =1 j =1 1 st -order moment = position of centroid: i = m 10 j = m 01 ¯ ¯ m 00 m 00
orientation from 2 nd & 1 st order moments n m ( i − ¯ X X i ) 2 B ( i, j ) a = i =1 j =1 n m ( i − ¯ i )( j − ¯ X X b = 2 j ) B ( i, j ) i =1 j =1 n m ( j − ¯ X X j ) 2 B ( i, j ) c = i =1 j =1 b tan 2 θ = a − c 90 � − θ is the angle with horizontal axis
SIZE FILTER
ROW AND COLUMN PROJECTIONS
EXAMPLE OF PROJECTIONS
ROW AND COLUMN PROJECTIONS Col. Proj. Row Proj. n − 1 m − 1 ∑ ∑ V [ j ] = B [ i , j ] H [ i ] = B [ i , j ] i =0 j =0 The first moments of an image equal the first moments of its projections!
Diagonal Projection Affine transformation: J=m-1 J=i= i=0 0 What’s the reason for the last one? Solve to get: i=n-1 J=0 d=n+m-2 d=0 Binary image and its diagonal projection
Image moments can be calculated (quickly) from the vertical, horizontal and diagonal projections (B.K.P. Horn, Robot Vision, MIT Press, 1986) defined as: From these we can find the orientation:
GENUS = Euler number: E = C − H # connected components # holes GENUS, OR EULER NUMBER TRANSLATION-, ROTATION- & SCALING-INVARIANT
Region boundary: Set of pixels of S that are adjacent to S
Perimeter P: number of pixels in boundary. Can be computed by totaling the number of 0-valued 4- neighbors for each point. Compactness:
RUN-LENGTH CODES From these we can calculate the projections w/o generating the image, which in turn let us find the zero- first- and second-order moments and thus the orientation!
Distance metrics q ( x i − x j ) 2 + ( y i − y j ) 2 d E = q − − d 4 = | x i − x j | + | y i − y j | = ( ) | | | | − − d 8 = max ( | x i − x j | , | y i − y j | )
Distance transform: provides the minimum distance from a pixel of an object to the background. To compute, use where m is the iteration number for all pixels [u,v] such that d([u,v],[i,j])=1. Use 4-neighbors.
The set of locally maximum pixels of an object are the skeleton, or medial axis. Skeleton A pixel [i,j] is locally maximum if its S* distance to S is not closer than that of all its neighboring pixels [u,v]. Here we are using 4- neighbors.
THINNING
Recommend
More recommend