**1 Answer**

written 5.4 years ago by |

Chain codes are used to represent the binary by a connected sequence of straight â€“line segments. This represented is based on 4-connectivity and 8-connectivity of the segments. The chain code works best with binary images and is a concise way of representing a shape contour. The chain code direction convention is given below:

As an edge is traced from its beginning point to the end point the direction that must be taken to move from one pixel to the next is given by the number represented in either the 4-chain code or the 8- chain code. As an edge can be completely described in terms of its starting coordinate and its sequence of chain codes descriptors. Of the two chain codes, the 4-chain is easier requiring only four different code values. For e.g.: Given an image, for 4-chain code for the same.

Let us take a starting point which is arbitrary chosen (p). From this point on, the cursor follows the contour, usually in the clockwise direction. For every pixel the direction is noted.

The 4-chain code is given edge is

0 0 3 0 3 3 2 2 2 1 1 1

Hence instead of storing the coordinates of each pixel, we can store the chain code and starting coordinates. Remember 8-connectivity is closer to the human eye than 4-connectivity. The chain code allows an edge to be described using vertical, horizontal as well as diagonal descriptors at $45^0, 135^0, 225^0 and \ \ 315^0$.