Chain code can be used to describe a shape. We can use two main classes of chain code. One isabsolute chain code, another isrelative chain code.
For absolute chain code,we define a set of absolute directions. Then we code the shape as follows:
We start from the green pixel above and go clockwise. For each new pixel, we check the direction of the vector from the old pixel to the new pixel. As the second pixel is on the SW corner. So it’s code number is 5 by our definition. Go on until we return the start pixel. Then we get the chain code 5,5,7,1,1,3,3. This is a shape feature vector. If we want to match a shape. What we do is just compare two vectors.
For relative chain code, the difference is that we don’t use absolute direction. Instead, we choose relative direction. In this method, when we want to get a chain code, we don’t check the absolute direction of the new pixel and the old pixel. We just check the relative direction of the direction. If the new pixel is frontier, then the code is 2. If it’s back, then the code is 6. What we need to take care of is that, in relative chain code, the start pixel’s chain code is decided by the last pixel.
The absolute chain code stores the position information of the shape, while relative chain code don’t.