Chain Codes in Boundary Representation
Chain codes are used to represent the boundary of an object in a digital image using a connected sequence of straight-line segments. These segments have specific lengths and directions.
Freeman Chain Code
The Freeman Chain Code, developed by Herbert Freeman, is the most commonly used chain code. It represents boundaries using either:
- 4-connectivity or
- 8-connectivity,
with each direction assigned a unique number.
Direction Numbering:
- 4-directional chain code:
Direction | Code |
---|---|
Right | 0 |
Down | 1 |
Left | 2 |
Up | 3 |

How Chain Codes are Generated
- Start from a boundary point, usually the uppermost-leftmost pixel.
- Traverse the boundary in clockwise direction.
- Assign a number (0–7) to each move based on the segment’s direction.
- The result is a sequence of numbers like:
0, 7, 6, 6, 1, 2, 1, 2, ...
Problems with Raw Chain Codes
- Too long: Every small boundary segment is recorded.
- Sensitive to noise: Minor changes in boundary due to segmentation errors cause large variations in the chain code.
Solution: Resampling
To reduce complexity and noise sensitivity:
- Use a coarser sampling grid (Fig. 11.4a).
- Map original boundary points to nearest grid points (Fig. 11.4b).
- Generate a simpler chain code based on the resampled boundary (Fig. 11.4c).

Normalization Techniques
To make chain codes independent of starting point, rotation, and size, normalization is applied:
1. Starting Point Normalization
- Treat the chain code as a circular sequence.
- Choose a starting point such that the numerical value of the code is minimized.
2. Rotation Normalization
- Use the first difference of the chain code.
- First difference = number of direction changes between adjacent elements.
- Example:
Chain code:1 0 1 0 3 3 2 2
First difference:3 1 3 3 0 3 0
3. Scale Normalization
- Achieved by changing the grid spacing.
- Larger grid = fewer direction changes = shorter, smoother chain code.
Limitations
- Normalizations are approximate.
- In real-world images, scale and rotation may change the shape due to different pixel resolutions.