Professional Documents
Culture Documents
Chain Code
Chain coding is among the most widely used techniques for boundary shape
description. The boundary curve is approximated via a sequence of con-
nected straight line segments of preselected direction and length. Every line
segment is coded with a specific coding number depending on its direction.
The basic idea of chain coding is to code contour directions instead of
naïve bit-by-bit binary image coding or even coordinate representations of
the contours. Chain coding is based on identifying and storing the directions
from each pixel to its neighbor pixel on each contour. Before defining this
process, it is necessary to clarify the various types of neighbors that are
associated with a given pixel in a binary image.
Boundary Features
Figure 2.2 depicts two neighborhood systems around a pixel (shaded).
To the left are depicted the 4-neighbors of the pixel, which are connected
along the horizontal and vertical directions. The set of 4-neighbors of a
pixel located at coordinate n will be denoted N4(n). To the right are the
8-neighbors of the shaded pixel in the center of the grouping. These include
the pixels connected along the diagonal directions. The set of 8-neighbors
of a pixel located at coordinate n will be denoted N8(n).
Figure 2.2: Depiction of the 4-neighbors and the 8-neighbors of a pixel (shaded)
Figure 2.3: Representation of a binary contour by direction codes. (a) A connected contour can be
represented exactly by an initial point and the subsequent directions; (b) only 8 direction codes are
required.
The chain codes for the example region in Figure 2.4(a) are shown in
Figure 2.5. Figure 2.5(a) shows the chain code for the four-way connectivity.
In this case, we have that the direction from the start point to the next is
south (i.e. code 2), so the first element of the chain code describing the
shape is 2. The direction from point P1 to the next, P2, is east (code 1), so
the next element of the code is 1. The next point after P2 is P3, which is
south, giving a code 2. This coding is repeated until P23, which is connected
eastwards to the starting point, so the last element (the 12th element) of the
code is 1.
The code for eight-way connectivity shown in Figure 2.5(b) is obtained
in an analogous way, but the directions are assigned according to the def-
inition in Figure 2.5(b). Notice that the length of the code is shorter for
this connectivity, given that the number of boundary points is smaller for
eight-way connectivity than it is for four-way.
illustrated in the fig.2.6, where the initial chain code is that from the shape
in Figure 2.5. Here, the result of the first shift is given in Figure 2.6(b);
this is equivalent to the code that would have been derived by using point
P1 as the starting point. The result of two shifts (Figure 2.6c) is the chain
code equivalent to starting at point P2, but this is not a code corresponding
16 Chapter 2. Feature Extraction I
to the minimum integer. The minimum integer code (Figure 2.6d) is the
minimum of all the possible shifts and is the chain code that would have
been derived by starting at point P11. That fact could not be used in appli-
cation since we would need to find P11; it is much easier to shift to achieve
a minimum integer.
Rotation invariance
In addition to starting point invariance, we can obtain a code that does not
change with rotation. This can be achieved by expressing the code as a
difference of chain code, since relative descriptions remove rotation depen-
dence. To use the difference of chain code instead of the code itself, count
counterclockwise the number of directions that separates two adjacent ele-
ments (First difference) as shown in fig 2.7.
Area
The area is the number of pixels in a shape. While the convex area of an
object is the area of the convex hull that encloses the object as shown in the
figure below.
Perimeter
The perimeter (length) is the number of pixels in the boundary of the object.
If X1 , ..., Xn is a boundary list (Xi = (xi , yi ), the perimeter is given by:
q
P(S) = (xi − xi−1 )2 + (yi − yi−1 )2 or (3.2)
Compactness
Compactness is defined as the ratio of the area of an object to the area of a
circle with the same perimeter.
4π · area
compactness = (3.3)
( perimeter )2
Regional Features
A circle is used as it is the object with the most compact shape. The measure
takes a maximum value of 1 for a circle
Objects which have an elliptical shape, or a boundary that is irregular
rather than smooth, will decrease the measure. Using an alternate formula-
tion:
( perimeter )2
compactness = (3.4)
4π · area
The measure takes a minimum value of 1 for a circle. Objects that have
complicated, irregular boundaries have larger compactness.
Figure 3.1: Regions with Euler number equal to 0 and −1, respectively.