liveBook · Manning

Dilation

As explained in Geometry for Programmers

Dilation is a morphological operation that expands foreground regions or, equivalently, produces an outward offset according to a structuring element.

Dilation grows a shape outward by a chosen distance. In a voxel image, it adds empty border voxels near filled ones; in signed distance function (SDF) modeling, it is an outer offset. It is useful whenever a model needs more material, smoother small-scale detail, or clearance-aware processing. section 12.3 section 12.3.6

The representation determines the simplest implementation. For a true SDF, dilation by an offset d is just SDF − d: subtracting makes more locations count as inside the shape. Erosion is the opposite operation, SDF + d. This compact arithmetic is reliable only while the function remains a true distance function. section 10.2.3 section 10.2.5

SDF_dilated = SDF - offset
SDF_eroded = SDF + offset

Subtract an offset to expand a true SDF; add it to shrink the shape. section 10.2.3

Be careful after SDF Boolean operations. A Boolean result can still describe the intended shape without retaining exact distance values. Applying simple subtraction then may produce an almost plausible offset, but features such as crescent horns stay sharp where a genuine offset would round them. Perform offsets before Booleans when possible. section 10.2.3 section 10.2.4

For voxels, one dilation step checks each empty voxel for a filled neighbor, marks qualifying voxels, then fills them after the scan. Repeating that step reaches larger depths, but repeatedly scanning a large image is wasteful. A distance map instead records each empty voxel’s approximate distance to the nearest filled voxel, allowing every voxel within the requested depth to be filled at once. section 12.3.1 section 12.3.1

A practical two-pass distance-map dilation works as follows:

  • Initialize filled voxels with distance 0 and empty voxels with an unknown large distance. section 12.3.1
  • Scan forward, propagating the smallest known neighbor distance plus one through empty voxels. section 12.3.1
  • Scan backward, considering the remaining directions to finish the approximate nearest-distance values. section 12.3.1
  • Fill voxels whose distances are within the requested dilation depth. section 12.3.1
Figure 12.12 Dilating the model by 1 pixel by adding all the pixels with a distance of 1 (left); dilating the same model by 2 pixels at once by adding all the pixels with a distance ≤2 (right)
12-12

A distance map lets one pass add all pixels within a chosen depth instead of repeating single-pixel growth. section 12.3.1

Denoising a thresholded scan

Small thresholding artifacts can be removed by eroding a voxel model and then dilating it by the same depth. The erosion removes isolated noise and thin details below that scale; the following dilation restores the surviving smooth features and reduces border noise. In a binary Python image, filled and empty voxels can be represented as 1 and 0, while erosion can reuse dilation through inversion. section 12.3.3 section 12.3.3

Reversing the pair—dilate first, then erode—patches thin cracks. Combined with Boolean subtraction, these paired operations can flag thin walls, detect thin cracks, or identify models placed too close together for 3D printing. Voxel workflows are often attractive because their Boolean operations are fast and reliable when operands share a grid. section 12.3.5 section 12.3.6

Dilation is analogous across representations, but not equally convenient in each one. SDFs make valid offsets arithmetically simple; voxels make composed cleanup operations practical and robust. Converting a triangle mesh to an SDF and back can make offsetting easier, yet conversion can be expensive and can complicate textures, parameterizations, and accumulated approximation error. section 12.8 section 11.3.3

How Geometry for Programmers covers it

How deep it goes
Explains SDF arithmetic and a two-pass voxel distance-map algorithm, while noting approximate distances and omitted diagonal neighbors.
Examples
Uses offset circles, a hollow disk shell, binary-image denoising, thin-wall detection, crack patching, and 3D-printing models.
What it assumes
Introduces dilation through filled and empty voxels and SDF values, while relying on prior projective transformations for other SDF changes.
What you can do after
Apply it via SDF arithmetic or a voxel distance map, choosing operation order to avoid invalid offsets.
How it connects
Connects dilation with erosion, signed distance functions, voxel models, Boolean operations, distance maps, and boundary representations.

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.