Contour Analysis

Machine Learning
Introduced by
Satoshi Suzuki and Keiichi Abe
Year
1985
Type
Shape and contour analysis
Family
Boundary detection

What does it do?

Contour analysis detects the boundaries of objects in images by tracing the outer and hole borders of connected foreground regions in a binary image, then describing those borders with shape measurements.

In the form described here, the input is a binary image and the Suzuki–Abe border-following procedure extracts the contours. The resulting outlines can support shape-based classification or refine a segmentation.

The intuition behind the method

A contour is a continuous boundary separating an object from its background. In this method, contour detection traces the closed borders of connected foreground regions in a binary image. The Suzuki–Abe algorithm starts from a border pixel and follows the boundary of each foreground region, producing an ordered list of coordinates for each contour. Shape features such as area, perimeter, moments and convex hulls can then be computed from these coordinates, which is what makes shape-based classification possible.

History

Suzuki and Abe's 1985 paper in Computer Vision, Graphics, and Image Processing describes topological structural analysis of digitised binary images by border following, which is the algorithm used here. Moment-based shape description, used in the evaluation step, goes back to Hu's 1962 paper on visual pattern recognition by moment invariants.

When to use it

Choose contour analysis when objects are separated from the background by a clear boundary and the question concerns shape, for example counting objects, measuring outlines or classifying shapes in document, industrial or biological images. It is a sensible first choice when a clean binary mask can be produced. Avoid relying on it when boundaries are faint, noisy or textured, because border following can only trace edges that the binarisation has already delivered. Region-based or active-contour methods are often more suitable for those cases. Before use, check three assumptions: the foreground is coded as 1 and the background as 0; each object is a well-defined region whose border closes in the mask, since open or gapped boundaries yield open or fragmented contours; and the connectivity convention (4- or 8-connected foreground) is consistent with the tracing rule described in Suzuki and Abe (1985). The minimum area or other size cut-off that separates objects from noise is a user choice and should be validated on the data.

Limitations and considerations

  • Requires a binary input, so output quality is capped by the thresholding or edge detector used upstream
  • Weak or broken boundaries produce open or fragmented contours, and the tracing step cannot close gaps on its own
  • Regions defined by texture rather than by a closed edge are not captured as objects
  • Boundary noise produces irregular contours, and the shape descriptors computed from them vary with pixel-level noise
  • Touching or merging objects are returned as a single contour unless post-processing separates them

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Turns a binary mask into ordered boundary coordinates for every object, without a separate training stage
  • Reports outer borders and hole borders with their nesting relation, so holes need not be mistaken for separate objects
  • Supplies the boundary sequences from which moment-based descriptors are computed; Hu's moment invariants are invariant to translation, similitude and orthogonal transformations for continuous figures, which suits recognition regardless of position, size and orientation, with approximate invariance for digitised contours
  • Performs well when object-background contrast is high and the binary map is clean

Applications

  • Document image analysis: detecting text blocks, table cells and document structure
  • Industrial quality control: extracting object boundaries and checking them against specifications
  • Biological image analysis: counting and characterising cells, nuclei or organisms
  • Shape-based object recognition: classifying objects using contour descriptors such as Hu moments
  • Segmentation refinement: improving segmentation quality through boundary-based post-processing

How it works

How it works

1

Obtain a binary image in which foreground pixels are 1 and background pixels are 0, typically by thresholding. An edge map, such as one produced by Canny edge detection, is not itself a binary foreground image: its edges must first be closed and filled into regions before tracing. The quality of this binary map limits the quality of every contour that follows.

2

This is a preparation step, and no parameters are learned from data. Scan the image in raster order and mark pixels where a foreground pixel borders background as candidate starting points for border following, with an empty contour list to be filled.

3

From each unvisited starting point, follow the border by moving between connected foreground pixels and append each visited coordinate to the current contour until the path returns to its start. The output is an ordered coordinate sequence for each boundary, together with information on whether a border is an outer boundary or a hole boundary.

4

Compute shape descriptors from each contour, then use them to classify objects or to judge whether the segmentation is plausible. Common descriptors are: area; perimeter, the length of the contour; centroid; aspect ratio, the ratio of the object's length to its width; solidity, the object area divided by the area of its convex hull, which equals 1 for convex shapes and falls for concave ones; and moments. Hu's moment invariants are one descriptor family. Hu showed that they are invariant to translation, similitude and orthogonal transformations for ideal continuous figures. For digitised contours this invariance is approximate.

Common pitfalls

  • Feeding a poor edge map or an unvalidated threshold into the algorithm; errors in the binary image propagate directly into every traced contour
  • Ignoring the contour hierarchy: treating hole borders as separate objects inflates object counts
  • Computing shape descriptors from raw, unsmoothed contours; pixel noise changes perimeter and other boundary-based measures
  • Treating every traced contour as an object; small noise blobs should be filtered by area or another criterion before counting
  • Accepting counts or descriptors without checking them against a labelled sample of the target images

Frequently asked questions

What is the Suzuki-Abe border-following algorithm and how does it work?

The Suzuki-Abe algorithm operates on a binary image. It scans the image in raster order to find border starting points, then follows each border from pixel to neighbouring pixel through connected foreground pixels, recording every coordinate, until the path returns to its start. This produces an ordered coordinate sequence for each outer or hole border. The exact neighbourhood scan and stopping rules are given in Suzuki and Abe (1985).

What is contour hierarchy and why does it matter?

Contour hierarchy describes the nesting of contours: outer contours of objects, inner contours of holes within objects, and contours of objects nested within holes. The Suzuki-Abe algorithm produces hierarchical information, allowing distinction between outer boundaries and inner holes. Ignoring hierarchy can lead to misclassification of holes as separate objects.

How can I use contour shape descriptors for object classification?

From contours, shape descriptors can be computed: area, perimeter, aspect ratio, eccentricity, Hu moments (shape descriptors based on image moments) and solidity (area divided by convex hull area). Solidity equals 1 for convex shapes and decreases for concave ones. Eccentricity describes how elongated a shape is, based on its moments, while aspect ratio compares the length and width of the object. These features can be used directly for classification or as input to machine learning models. Hu moments are useful for shape recognition because they are designed to be invariant to scale, rotation and translation; for digitised contours this invariance is approximate rather than exact.

Why is contour smoothing necessary before shape analysis?

Contours traced from a binary mask inherit pixel-level noise and staircase artefacts from the digital grid. When shape descriptors are computed from noisy contours, the descriptors include noise-related variation, making them less reliable for classification. Smoothing, for example spline fitting or Gaussian smoothing of the coordinate sequence, reduces this noise while preserving the true shape, which improves descriptor reliability. Smoothing is an additional choice that should be checked, because too much smoothing can remove genuine shape detail.

Related methods

Sources

  1. Suzuki, S., & Abe, K. (1985). Topological structural analysis of digitized binary images by border following. Computer Vision, Graphics, and Image Processing, 30(1), 32–46.

    Open DOI reference
  2. Hu, M. K. (1962). Visual pattern recognition by moment invariants. IRE Transactions on Information Theory, 8(2), 179–187.

    Open DOI reference