Euclidean Distance Transforms: Background and Grid Spacing
2026-11-18

Euclidean Distance Transforms: Background and Grid Spacing

Euclidean distance transforms replace each nonzero grid location with its distance to a nearest zero-valued location. The definition depends on which values represent foreground and background, and on the spacing assigned to each grid axis. A distance map should therefore be read together with its binary interpretation and sampling convention.

Zero locations are the target background

The SciPy 1.16 distance_transform_edt documentation defines background as zero and foreground as nonzero. The input is interpreted in binary terms rather than as a set of numeric distance weights. A value seven is a nonzero foreground value, not a request to make its path seven times more expensive.

For an invented three-by-three grid, put zero at the central location and one at every other location. There is one background target, at row one and column one under zero-based indexing. All foreground locations measure distance to that same central background point. The background's own distance is zero.

Unit-spacing distances are sqrt2 atcorners,1 ataxisneighbors and0 atcenter.
These are independently derived Euclidean distances to the sole zero at grid index1,1, not measured clearance data. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

Unit spacing gives axis distances one and diagonal distance square root two

With unit spacing along both axes, the foreground locations immediately above, below, left and right of the center are distance one from it. Each corner differs by one row and one column, giving the square root of one squared plus one squared, or the square root of two.

The resulting rows are square root two, one, square root two; one, zero, one; and square root two, one, square root two. This is a direct Euclidean calculation for the synthetic grid. It is not the count of horizontal and vertical steps along a chosen path, which would assign two to a corner instead.

The distinction matters when explaining a map. An exact Euclidean transform uses the geometric straight-line distance under its stated grid metric. A diagram of grid connections should not silently change that definition into a restricted walking distance or a cost that accumulates foreground intensities.

Unequal sampling changes the metric rather than the binary labels

Now assign spacing two to the row axis and spacing one to the column axis. The central zero and all eight foreground labels remain in the same array positions. A one-row offset has geometric length two, while a one-column offset has length one. A corner is consequently distance square root five from the center.

The transformed rows become square root five, two, square root five; one, zero, one; and square root five, two, square root five. The change follows from the sampling values, not from changing which locations are background. Naming these axes explicitly avoids guessing whether an application's informal x label refers to rows or columns.

Sampling row2,column1 changes cornerdistance tosqrt5,rowneighbors2,columnneighbors1.
Distances use sampling lengths, while returned feature indices remain grid coordinates; the sole target is still1,1. Source: Zhilianhai editorial desk, original AI-assisted conceptual illustration.

The feature transform identifies the target location

The interface can also return indices of a closest background location. For the single-zero example, every target index is row one, column one. The index result has an extra leading axis for coordinate components, so a two-dimensional input of shape three by three gives indices of shape two by three by three.

The first component array stores target row indices and the second stores target column indices. They are grid indices, not coordinates already multiplied by the sampling values. A consumer that needs physical displacements must combine source indices, target indices and spacing consistently rather than treating the returned integer pair as a distance vector.

The wrapper separates nearest features from distance arithmetic

The original SciPy implementation obtains the nearest-feature transform from the underlying image routine. It subtracts source grid indices from target indices, scales each axis by its sampling, squares the components, sums them and takes a square root when distances are requested. That wrapper is not the complete nearest-feature algorithm.

A reusable explanation should retain the binary mask, spacing and output meaning. With several equally near background points, a distance alone need not identify a unique target, so avoid reading a selected feature index as evidence of a preferred physical direction. The single-zero example removes that ambiguity for teaching arithmetic.

The interface also permits caller-provided output arrays. The documented distance output uses float64 with the input shape, while the feature-index output uses int32 with the extra coordinate-component axis. Providing a storage array changes where that requested output is placed; it does not change the binary meaning or metric. A wrapper should check both return flags and supplied buffers before assuming that every call returns a two-item tuple. Distances and nearest-feature indices are separately requested outputs, with separately specified storage contracts.

The figures contain no measured factory map, obstacle clearance or robot-safety result. They show a synthetic grid and a chosen metric only. Related explanations appear in the industry data geometry section and the technical article collection.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我