AI Glossary / Computer vision and multimodal AI / Beginner
Distance map
Definition
A distance map is an image or grid in which each location stores its distance to a specified set of locations, such as the nearest background pixel, object, or boundary. It is commonly produced by a distance transform. Its meaning depends on the reference set, distance metric, sample spacing, and any sign convention.
What it means
An ordinary binary image says whether a location belongs to an object. A distance map adds information about how far that location lies from something relevant. Locations deep inside an object can have larger distances to the background than locations near its edge.
The reference must be stated. Some tools assign each foreground pixel its distance to the nearest background pixel. Other applications measure distance to obstacle cells, selected feature points, or a represented surface. A signed distance map additionally distinguishes sides of a boundary using positive and negative values, with the sign convention chosen by the application.
A distance map is not generally a camera depth map. The former measures distance relative to a selected set within a representation; the latter records a scene-depth quantity from a viewing system.
How it works
Define the set to which distances will be measured. In a binary image, confirm whether zero or nonzero values represent that set, because software conventions differ.
Choose the metric. Euclidean distance measures straight-line separation. Grid-based alternatives, such as Manhattan distance, count movement according to specified axis-aligned rules. The resulting maps can differ even for identical input pixels.
Compute the nearest-reference distance for each location using a suitable distance-transform algorithm. Some implementations can also return the location of a nearest reference point, which supports additional geometric operations.
Apply physical sample spacing when appropriate, especially for grids with unequal intervals along different axes. Finally, check whether the values describe distances between sample centers, distances to an explicitly modeled continuous boundary, or another convention. These distinctions matter when interpreting small features or comparing against physical measurements.
Three practical examples
1. Object separation: An image pipeline uses peaks of an interior distance map as candidate markers for separating touching objects.
2. Clearance visualization: A mapped environment displays each location's distance to represented obstacles, subject to the map's resolution and completeness.
3. Shape comparison: A vision algorithm measures how far points on one detected outline fall from a reference outline.
Think of it this way
Think of a map showing the distance from every house to the nearest designated service point. The number at a house tells you how close that reference set is, rather than identifying the house itself.
The analogy is limited because the metric matters. Straight-line distance to a service point does not equal road-travel distance, just as Euclidean distance in an image does not automatically represent a feasible path around obstacles.
Worked example
Consider a grid with unit spacing and two reference points at coordinates (0, 0) and (6, 0). We want the Euclidean distance map relative to these two points.
At location (3, 4), the distance to either reference is the square root of 3 squared plus 4 squared, or 5. The distance-map value is therefore 5. At location (5, 0), the nearest reference is (6, 0), so the value is 1.
Using Manhattan distance instead, the value at (3, 4) is 3 + 4 = 7. This is a different metric, not a calculation error.
Now suppose one vertical grid step represents two millimeters and one horizontal step represents one millimeter. The physical Euclidean distance from (3, 4) to either reference is the square root of 3 squared plus 8 squared, approximately 8.54 millimeters. The coordinate indices did not change, but the meaningful physical distance did. A map used for measurement must carry the appropriate spacing information.
Illustrative case study
Fictional case study: GrainSplit analyzes binary images of touching particles. Its team computes distances from foreground pixels to the background and uses interior peaks to propose separate particle centers.
Some irregular particles produce several peaks, so the team adds marker-selection rules and checks results against manually reviewed examples. It does not assume that every local maximum represents a different particle.
The team also records the pixel scale and binary convention to make repeated analyses comparable. This fictional case illustrates how a distance map can support segmentation; it does not claim that the transform alone resolves every touching-object problem.
Common misconceptions and mistakes
Do not use the phrase distance map without identifying the reference set. Distance to background and distance to foreground describe different quantities.
Do not assume a signed map has the same sign convention across tools. Positive may mean inside in one system and outside in another.
Do not confuse distance to a background pixel center with exact distance to a continuous object boundary. The represented geometry and sampling conventions determine the interpretation.
Do not treat a large distance value as proof of safe physical clearance. An obstacle map can be incomplete, outdated, or too coarse, and a moving object's own dimensions also matter.
Business use
Distance maps are useful intermediate representations for inspection, segmentation, geometric matching, and spatial analysis. They convert a binary or sparse representation into graded information that can support thresholds, markers, and optimization.
Teams should document the reference set, metric, units, grid spacing, and handling of locations outside the observed domain. Validate final decisions using representative geometry rather than relying only on a smooth-looking distance visualization. The transform can be mathematically exact for the supplied discrete data while the data remain an approximation of the real scene.
People also ask
Does a distance map always use Euclidean distance?
No. Different metrics produce different maps and suit different questions.
Can it be three-dimensional?
Yes. Distance transforms can operate on voxel grids and other multidimensional arrays.
Is a signed distance map the same as an ordinary distance map?
It adds a sign indicating a chosen side of a boundary; an unsigned distance alone does not provide that distinction.
Check your understanding
Why can two correct distance maps assign different values to the same pixel?
Answer: They may use different reference sets, metrics, spacing, or geometric conventions. Those definitions must match before comparing the values.
Related terms
- Euclidean distance
- Digital geometry
- Watershed segmentation
- Binary image
- Distance transform
- signed distance function
- voxel
Learn next
Learn watershed segmentation next to see one use of distance-map peaks. Then compare Euclidean and path-based distances so you can choose a representation that matches the question being asked.
More in Computer vision and multimodal AI
- Dirichlet distribution - The Dirichlet distribution is a probability distribution over vectors of proportions that sum to one.
- Disocclusion - Disocclusion is the process by which a previously hidden part of a scene becomes visible when the viewpoint or scene changes.
- Disparity map - A disparity map records the positional differences of corresponding scene points between two images, usually a stereo pair.
- Distant supervision - Distant supervision creates training signals by connecting unlabeled examples with an external source of information, rather than manually labeling every...
- Divergence - In vector calculus, divergence measures the local net outward flow of a vector field per unit volume, or per unit area in two dimensions.
- Division model (Fitzgibbon) - The division model associated with Fitzgibbon is a compact mathematical model of radial lens distortion.
Sources
SciPy, scipy.ndimage.distance_transform_edt: primary scientific-software documentation consulted for nearest-background Euclidean distances, sample spacing, and nearest-point output. The coordinate example and fictional particle case are original teaching material. https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_edt.html
Previous: Distance Next: Distance-Regular Graphs