Chain
Codes

A chain code is a more succinct way of representing a list of points than a simple [ , ..... ]. It may be defined either with respect to the pixels or the boundaries between pixels. A pixel in a rectangular grid has either 4 or 8 neighbours depending on the definition of connectivity, as represented in Figure 7, below. The chain code is defined in this case by tracking around the white pixels in the outer boundary ( as opposed for example to tracking round the black pixels in the inner boundary ). For the examples shown, the codes are 1100100 etc. and 21017 etc. Alternatively, it is possible to track between the black and white regions along the intersections of the pixels using a 4-connected code. In Figure 8, the edge data is tracked directly, again using an 8-connected form; the short bars represent the thinned edges from a standard edge detection algorithm. A chain code describes the boundary as a series of one (or 1.414 !) pixel vector transitions at different orientations; only the starting point is defined explicitly.

Figure 7
Figure 7: Boundary chain codes

Figure 8
Figure 8: A chain code for edge pixels

Chain codes are position independent if the start point is ignored, which may simplify matching of orientation-fixed linear figures. The derivative of the chain code (i.e. the change in the code either clockwise or anti-clockwise) may be invariant under boundary rotation. A problem arises because of the unequal length of the vectors in a 8-connected scheme, since a diagonal transition is 1.414 times the length of a horizontal or vertical transition. This means that the length of the chain code of a straight line will be orientation dependent unless this is taken into account.


[ Parameter based representation | The -s curve ]

Comments to: Sarah Price at ICBL.
(Last update: 22th April, 1996)