liveBook · Manning

Contour

As explained in Geometry for Programmers

A curve representing the boundary of a model cross-section or printable layer.

A contour is a curve marking a model cross-section or printable layer. In image processing, it begins as the boundary between neighboring pixel values on opposite sides of a light/dark threshold. section 12.4.2 section 1.0

A practical contour-extraction pipeline proceeds in stages:

  • Treat interpolated image values as a signed, quasi-distance function and define the target curve where it equals zero. section 12.4.5
  • Create an initial border from one-pixel segments wherever neighboring cells straddle the threshold. section 12.4.2
  • Fit each segment’s vertices toward the threshold curve with finite-difference derivatives and an iterative correction loop. section 12.4.5
  • Estimate tangent vectors and replace straight segments with cubic polynomial curves; subdividing them into line segments makes plotting easier. section 12.4.5

From pixels to a smooth boundary

For a grayscale image, choose a distance threshold of 128. Opposite-sign samples identify the initial pixel border; iterative fitting moves its vertices onto the threshold isoline, and cubic curves produce a smooth contour. section 12.4.5

Figure 12.20 An initial contour is a border between pixels with values below the threshold and above.
12-20

The figure makes the initial contour intuitive: it traces borders between pixels below and above the selected threshold before smoothing and fitting. section 12.4.2

How Geometry for Programmers covers it

How deep it goes
Builds contours through thresholding, interpolation, iterative fitting, and cubic smoothing, but defers broader mesh-processing details.
Examples
Demonstrates grayscale pixel borders, threshold isolines, fitted vertices, and smooth cubic contours through figures and Python listings.
What it assumes
Assumes basic grids, neighboring pixels, thresholds, and derivatives while developing the geometric interpretation from image values.
What you can do after
Build it from scratch by extracting, fitting, and smoothing a threshold boundary from a sampled image.
How it connects
Connects contours with signed distance functions, image interpolation, vectorization, cubic polynomial curves, CAD, and 3D printing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.