Chain Code and Types of chain code digital image processing
VarshiniRamar
7 views
16 slides
Aug 28, 2025
Slide 1 of 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
About This Presentation
Chain code in digital image processing is a technique used to represent the boundary of a binary object in a digital image. Instead of storing all the pixel coordinates of the boundary, chain code encodes the contour as a sequence of directional moves between successive boundary pixels. Each move is...
Chain code in digital image processing is a technique used to represent the boundary of a binary object in a digital image. Instead of storing all the pixel coordinates of the boundary, chain code encodes the contour as a sequence of directional moves between successive boundary pixels. Each move is assigned a numeric value depending on the chosen connectivity, typically 4-connectivity or 8-connectivity, where 4-connectivity considers movements in the cardinal directions (up, down, left, right), and 8-connectivity also includes diagonal directions.
The main advantage of chain code is its compact representation of shape and ease of extracting geometric features such as perimeter, area, and orientation. It is widely used in pattern recognition, object tracking, and shape analysis because the code can be normalized for rotation, scaling, and starting point, making it robust for comparing similar shapes. However, chain codes are sensitive to noise and small boundary variations, so preprocessing like smoothing or edge detection is often applied before generating the chain code
Size: 958.32 KB
Language: en
Added: Aug 28, 2025
Slides: 16 pages
Slide Content
NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE Digital Image Processing Chain Code By: R. VARSHINI II- M.Sc (Computer Science)
What is Chain Code Chain Code is a way to represent the boundary (contour) of a digital image object using a sequence of directional codes . It follows the connected pixels along the boundary of an object in a clockwise or counterclockwise manner. Instead of storing all boundary pixel coordinates, chain code compresses them into directions (0–7 or 0–3) depending on connectivity .
Example : For 8-connectivity, directions are labeled like: 3 2 1 4 P 0 5 6 7 Where P = current pixel. If the next boundary pixel is right of P → direction , if above → 2 , etc.
Why use Chain Code Reduces storage: Instead of saving all coordinates, just store a starting point + direction sequence. Shape representation: Encodes object’s outline compactly. Useful for pattern recognition (digits, letters, objects). Easy to rotate, scale, and compare shapes.
1. Freeman Chain Code (FCC) 👉 Proposed by Herbert Freeman (1961). 👉 The most widely used method for representing boundaries. Principle: Represent the boundary as a sequence of directions Based on connectivity between pixels .
Types of FCC: 4-connectivity: Only horizontal and vertical directions. Possible codes = {0, 1, 2, 3}. Direction mapping: 2 3 P 1 8-connectivity: Includes diagonal directions too. Possible codes = {0, 1, 2, 3, 4, 5, 6, 7}. Direction mapping: 3 2 1 4 P 0 5 6 7 Example: Boundary pixels: (2,2) → (2,3) → (3,3) → (3,2) → (2,2) Chain Code (8-connectivity) = [0, 6, 4, 2]
2. Differential Chain Code (DCC) Example: Freeman Chain Code = [0, 0, 6, 6, 4, 2] → Differential Chain Code: First code = 0 (absolute direction). Next steps: 0→0 = 0 (no change) 0→6 = -2 (turned right) 6→6 = 0 6→4 = -2 4→2 = -2 DCC = [0, 0, -2, 0, -2, -2] Advantage: Compact, rotation invariant (if normalized). ❌ Still sensitive to noise 👉 An improvement over Freeman Chain Code . 👉 Instead of storing absolute directions , it stores the difference (turning angle) between successive moves. Principle: Start with an initial absolute direction. Then store relative changes (e.g., left turn, right turn, straight).
3. Vertex Chain Code (VCC) 👉 Represents the boundary as polygon vertices instead of all pixels. Principle: Approximate the object boundary with straight-line segments . Each vertex direction (corner) is encoded. More compact than FCC/DCC. Example: Square boundary → only 4 directions (corners). Instead of [0,0,0,6,6,4,4,2,2] (FCC), VCC = [East, South, West, North]. Advantage: Very compact, less redundant. Useful in polygonal shape approximation . ❌ Approximation may lose fine details.
Comparison of Types Feature Freeman Chain Code (FCC) Differential Chain Code (DCC) Vertex Chain Code (VCC) Storage Large (depends on pixels) Smaller (relative turns) Very small (vertices only) Rotation Invariance No (needs normalization) Yes (if relative changes used) Yes Detail High (pixel-wise) Moderate Low (only vertices) Noise Sensitivity High Medium Low Applications OCR, boundary tracing Shape recognition, matching Polygon approximation, CAD
Example Problem Example: Object boundary pixels (coordinates): (2,2) → (2,3) → (3,3) → (4,3) → (4,2) → (3,2) → (2,2) Step 1: Take (2,2) as starting pixel. Step 2: Trace clockwise, write direction using 8-connectivity. (2,2) → (2,3) → direction = 0 (east) (2,3) → (3,3) → direction = 6 (south-east) (3,3) → (4,3) → direction = 6 (4,3) → (4,2) → direction = 4 (west) (4,2) → (3,2) → direction = 2 (north-west) (3,2) → (2,2) → direction = 2 Chain Code = [0, 6, 6, 4, 2, 2]
coding bw =zeros(10); bw (3:8,3:8)=1; B= bwboundaries ( bw ); p=B{1}; x=p(:,2); y=p(:,1); dirs =[1 0;1 -1;0 -1;-1 -1;-1 0;-1 1;0 1;1 1]; fcc =[]; for i =1:length(x)-1,[~,k]= ismember ([x(i+1)-x( i ),y(i+1)-y( i )], dirs ,'rows'); if k,fcc (end+1)=k-1;end,end dcc=[ fcc (1) mod(diff( fcc ),8)]; v=p(1:5:end,:); vx =v(:,2); vy =v(:,1); vcc ={}; for i =1:length( vx )-1,d=[ vx (i+1)- vx ( i ), vy (i+1)- vy ( i )]; if d(1)>0,vcc{end+1}=' E';elseif d(1)<0,vcc{end+1}=' W';elseif d(2)>0,vcc{end+1}='S'; else,vcc {end+1}='N'; end,end disp ('FCC:'), disp ( fcc ) disp ('DCC:'), disp (dcc) disp ('VCC:'), disp ( vcc )
Advantages Compact representation of shape boundary. Rotation/scaling handling possible. Useful for object recognition, matching, and classification. Reduces memory vs. pixel storage .
Disadvantages Sensitive to noise (small distortions change the chain). Not invariant to starting point (different starting pixels → different code). Requires normalization for rotation/scale invariance. Boundary smoothing may be needed.
Applications OCR (Optical Character Recognition): Detecting letters/numbers. Fingerprint recognition: Ridge boundary encoding. Medical Imaging: Tumor/organ boundary representation. Shape analysis & classification in computer vision. Robotics & path planning: Representing obstacle boundaries. Industrial Inspection: Defect detection in objects.