SHAPE ANALYSIS
INEL 6088 Computer Vision
Refs.: ch. 6, Davies; Ch. 2 Jain et al.
SHAPE ANALYSIS INEL 6088 Computer Vision Refs.: ch. 6, Davies; Ch. - - PowerPoint PPT Presentation
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
INEL 6088 Computer Vision
Refs.: ch. 6, Davies; Ch. 2 Jain et al.
4-neighbors 8-neighbors
Foreground S: set of all1- pixels A pixel p in S is connected to another pixel q in S if there is a path from p to q consisting only
connected component: set
connected to all other pixels.
Examples of a 4-path and an 8-
indices such that the pixels are neighbors. Ref: connected components: sec. 3.3.4 Szelinski
S: complement of S background: set of all connected components of S that have points in the border of an image. holes: components of S that are not background.
Ref: connected components: sec. 3.3.4 Szelinski
4-neighbors 8-neighbors
Examples of a 4-path and an 8-
indices such that the pixels are neighbors.
Ambiguous!
If 1’s are connected they should isolate the 0 Use 8-connectivity for the foreground and 4-connectivity for the background
Boundary S’’: set of pixels in S that have neighbors in S Interior: set of pixels in S that are not in S’’ Surroundings T of region S: any 4-path from a pixel in S to the border of the image must intersect T
CONNECTED COMPONENT (OBJECT) LABELING
Recursive algorithm:
assign it a new label L
pixels
Sequential Algorithm
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
consider
Jain et.al. for an example)
6.3 Object Labeling and Counting 165
4 4 4 4 4 3 4 3 3 3 3 1 3 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 2 2 1 2 2 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.
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
See textbook by Davies
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 3 1 3 5 5 6 6 5 5 6 6 5 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 3 1 3 5 5 6 6 5 5 6 6 5 6
6.3 Object Labeling and Counting 1 67
Table 6.4 Coexist table redrawn again with minimized columns
1 2 3 4 5 6 7 1 1 1 1 1 1 1 1 1 1
5 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 2 3 4 5 6 7 1 1 1 1 1 1 1 1 1 1
5 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
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
p+q order moments: 0-order moment = Area: 1st-order moment = position of centroid: For binary images B(i,j) = 1 for pixels in CC
mpq =
n
∑
i=1 m
∑
j=1
ipjqBij mpq =
n
∑
i=1 m
∑
j=1
Bij
¯ i = m10 m00 ¯ j = m01 m00
a =
n
X
i=1 m
X
j=1
(i −¯ i)2B(i, j)
b = 2
n
X
i=1 m
X
j=1
(i −¯ i)(j − ¯ j)B(i, j) c =
n
X
i=1 m
X
j=1
(j − ¯ j)2B(i, j)
tan2θ = b a − c
90 − θ is the angle with horizontal axis
SIZE FILTER
ROW AND COLUMN PROJECTIONS
EXAMPLE OF PROJECTIONS
Row Proj.
The first moments of an image equal the first moments
ROW AND COLUMN PROJECTIONS
H[i] =
m−1
∑
j=0
B[i, j] V[j] =
n−1
∑
i=0
B[i, j]
J=i= J=m-1 i=0 i=n-1 J=0 Affine transformation: Solve to get: d=0 d=n+m-2
Diagonal Projection
What’s the reason for the last one?
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, OR EULER NUMBER TRANSLATION-, ROTATION- & SCALING-INVARIANT
E = C − H GENUS = Euler number: # connected components # holes
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 − − d4 = |xi − xj| + |yi − yj| = ( ) dE = q (xi − xj)2 + (yi − yj)2 | − | | − | d8 = max (|xi − xj|, |yi − yj|)
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.
Skeleton S*
The set of locally maximum pixels of an
skeleton, or medial axis. A pixel [i,j] is locally maximum if its distance to S is not closer than that of all its neighboring pixels [u,v]. Here we are using 4- neighbors.
THINNING
EXPANDING AND SHRINKING
Expanding: Change pixel from 0 to 1 if any neighbors of the pixel are 1. Shrinking: Change a pixel from 1 to 0 if any neighbors of a pixel are 0. Expanding followed by shrinking can be used to fill holes. Shrinking followed by expanding can remove isolated noise pixels.