Skip to content

Chain code

A contour representation that encodes a connected digital boundary as a start coordinate followed by symbols for successive grid-neighbor directions.

Core Idea

Chain codes compact binary-object boundaries and support translation normalization, perimeter and shape analysis, reconstruction, and differential encodings under four-, eight-, or generalized connectivity. A boundary-following rule selects a start point and orientation, moves between adjacent boundary pixels or vertices, and records each direction until the path closes; decoding replays the moves. The abstraction is therefore identified by a declared carrier, a transformation or constraint over that carrier, and an invariant that tells an analyst whether the named structure is genuinely present.

How would you explain it like I'm…

Step-by-Step Outline Walk

Draw a shape on graph paper. Start at one square on its edge and walk around the outline, writing down which way you step each time: up, right, down, or left. When you get back to the start, that list of steps is the chain code. Anyone can follow the list to draw the same outline again.

Outline Direction List

A computer picture is made of tiny squares called pixels. To save the outline of a shape, a computer can pick a starting pixel on the edge and walk around the border, writing down each step's direction with a number, like 0 for right, 1 for up-right, and so on. When it gets back to the start, the list of numbers is the chain code. It takes much less space than storing every pixel, and you can use it to measure the shape's border or redraw it. You have to agree on the rules first, like whether diagonal steps are allowed and which way you walk around.

Boundary Direction Encoding

A chain code is a compact way to describe the boundary of a shape in a black-and-white digital image. You choose a starting point on the boundary and a direction to travel, then move from one boundary pixel to the next, recording each move as a direction code until you get back to the start. Using 4-connectivity allows only up, down, left, and right; 8-connectivity also allows diagonals. Replaying the moves from the start point reconstructs the outline. Chain codes make it easy to measure perimeter, compare shapes regardless of where they sit in the image, and build differential codes that record turns instead of absolute directions. The result only makes sense once the grid, connectivity rule, start point, and direction of travel are stated.

 

A chain code is a compact boundary representation for objects in a binary image. A boundary-following rule selects a start point and traversal orientation, then moves between adjacent boundary pixels (or vertices) and records each step as a symbol from a direction alphabet—four directions under 4-connectivity, eight under 8-connectivity, or more under generalized connectivity—until the path returns to the start. Decoding replays the moves from the start point to reconstruct the boundary. Because it stores relative moves rather than absolute coordinates, the code is naturally normalized for translation, and it supports perimeter estimation, shape analysis, and reconstruction. Differential chain codes encode the change in direction between successive steps, which helps with further normalization. A proper specification states the image grid, foreground and connectivity convention, boundary and start-point rule, orientation, direction alphabet, closure condition, and any normalization or differential encoding.

Scope of Application

Chain code belongs to digital image representation and is useful where the analyst can specify the typed digital image representation carrier, defining objects and relations, parameters, conventions, evidence, boundary cases, and comparison targets, then evaluate the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding are explicit. The scope is broad within that domain but bounded by the need for the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding are explicit. The entry records a descriptive analytical identity; practical use requires the governing domain's evidence, standards, and safety obligations.

Clarity

The abstraction clarifies a crowded vocabulary by making the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding are explicit the center of the account. A claim should name the carrier, the governing operation or relation, the applicable assumptions, and the recognition test. A bare label is insufficient because the name Chain code can be used for a formal identity, an implementation, or a neighboring result unless carrier and convention are stated.

Manages Complexity

Without the abstraction, an analyst must reason directly over many local details: the carrier roles, admissibility assumptions, competing conventions, derived invariants, boundary cases, and proof or validation obligations specific to Chain code. Chain code compresses them into the roles in the structural signature. That compression permits comparison across instances without erasing the variables that determine validity. It also exposes which details may be varied safely and which are constitutive.

Abstract Reasoning

  1. Identify the carrier. State what the elements, states, objects, or observations are: the typed digital image representation carrier, defining objects and relations, parameters, conventions, evidence, boundary cases, and comparison targets. Reject examples whose alleged carrier belongs to a different problem.
  2. Lock the constitutive rule. Express the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding are explicit independently of one notation or implementation.

Knowledge Transfer

Knowledge transfers strongly among subfields of digital image representation because they reuse the typed digital image representation carrier, defining objects and relations, parameters, conventions, evidence, boundary cases, and comparison targets, A boundary-following rule selects a start point and orientation, moves between adjacent boundary pixels or vertices, and records each direction until the path closes; decoding replays the moves., and type the carrier, state every parameter and convention in the definition, test that the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding are explicit, compare the nearest accepted identity, and report counterexamples, uncertainty, and limiting cases.

Relationships to Other Abstractions

Local relationship map for Chain codeParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Chain codeDOMAINPrime abstraction: Encoding And Decoding — is a kind ofEncodingAnd DecodingPRIME

Current abstraction Chain code Domain-specific

Parents (1) — outgoing typed relations

  • Chain code is a kind of Encoding And Decoding Prime

    It remains its own entry because its identity is fixed by the image grid, foreground and connectivity convention, boundary and start-point rule, traversal orientation, direction alphabet, closure condition, and normalization or differential encoding.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Chain code sits in a crowded region of the domain-specific corpus (21st percentile for distinctiveness): several abstractions share nearly its structure, so a description that fits it tends to fit its neighbors too.

Family — Spatial Data Structures & Meshing (17 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-25