---
id: "exact-euclidean-distance-transform"
title: "Exact Euclidean Distance Transform"
aliases: [EDT, Felzenszwalb distance transform]
domain: "geometry"
stage: "geometry"
realtime: "interactive"
platforms: [cpu, cuda, webgpu, python]
year_introduced: 2012
inputs: [voxels, texture]
outputs: [sdf, texture]
style: "both"
dynamic: "static"
cost: "cheap"
authority: "Felzenszwalb & Huttenlocher, 2012"
url: "https://texelatlas.vercel.app/t/exact-euclidean-distance-transform/"
sources_verified_at: "2026-11-29"
---
# Exact Euclidean Distance Transform (Felzenszwalb & Huttenlocher, 2012)

> Computes the exact squared Euclidean distance from every grid cell to the nearest feature in linear time by running a one-dimensional lower-envelope-of-parabolas pass along each axis.

## Reach for it when

- need accurate distance field from a binary image
- baking font or shape sdfs gives lumpy errors
- approximate distance fields are not precise enough
- generate a clean distance volume from voxels

## How it works

The squared distance to a set of seeds is the minimum over seeds of a parabola per cell: f(q) = min_p ((q-p)^2 + g(p)). In one dimension, that minimum is the lower envelope of parabolas centred at each sample, which can be built in a single left-to-right sweep that keeps a stack of parabola indices and the boundaries where one overtakes the next. Evaluating the envelope at each grid position is a second sweep. Because squared Euclidean distance is separable, doing the 1D transform along rows, then columns (then depth for 3D) yields the exact result in O(n) total. The signed version runs it on both the shape and its complement and subtracts the square roots.

## When to use it

Choose it when you need exact SDFs from binary images or voxel volumes for baking font SDFs, collision fields, [Marching Cubes](https://texelatlas.vercel.app/t/marching-cubes.md) input or ambient occlusion, and when CPU or compute-shader time is acceptable. Prefer [Jump Flooding Algorithm](https://texelatlas.vercel.app/t/jump-flooding-algorithm.md) for per-frame, GPU-render-pass use where small errors are acceptable.

## Cost

cheap — Linear in grid cells; separable, so each row or column is an independent parallel task.
Measured GPU Weight: 2.74× baseline (light) — 0.0901 ms median / 0.0924 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 1.92× baseline (feather) — 0.0306 ms median (2.94× faster on L4).
Ampere A100 scaling: 1.74× baseline (feather) — 0.0501 ms median (1.8× faster on A100).

## Failure modes

- Distances are to cell centres, not to the sub-cell boundary, so binary inputs yield staircase fields unless anti-aliased input is used
- Values near thin features differ by up to half a cell from the true surface distance
- Memory-bound for large 3D volumes
- Squared values overflow low-precision storage unless scaled

## Dataflow

- Inputs: voxels, texture
- Outputs: sdf, texture
- Platforms: cpu, cuda, webgpu, python

## Presets

### Toy: the distance field this transform outputs (computed by brute force, not the linear-time algorithm) (glsl-fragment; rendered 2026-11-29)

```json
{
  "N": 14,
  "BAND": 0.06
}
```

```glsl
// Exact Euclidean distance to the nearest feature (brute-force reference of what the linear-time EDT outputs), shown as banded field.
const int N = 14;
const float BAND = 0.06;
vec2 site(int i) {
    float f = float(i);
    return vec2(fract(sin(f * 12.9898) * 43758.5), fract(sin(f * 78.233 + 1.0) * 24634.6)) * 0.84 + 0.08;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord / iResolution.xy;
    float d2 = 1e9; int id = 0;
    for (int i = 0; i < N; i++) {
        vec2 q = uv - site(i);
        float d = dot(q, q);
        if (d < d2) { d2 = d; id = i; }
    }
    float d = sqrt(d2);
    vec3 col = 0.5 + 0.5 * cos(6.2831 * (d * 2.2) + vec3(0.0, 0.8, 1.6));
    col *= 0.35 + 0.65 * smoothstep(0.0, 0.5, abs(fract(d / BAND) - 0.5) + 0.3);
    col = mix(col, vec3(0.0), smoothstep(0.004, 0.0, abs(fract(d / BAND + 0.5) - 0.5) * BAND - 0.001) * 0.6);
    col = mix(col, vec3(1.0), smoothstep(0.012, 0.008, d));
    fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}

```

Attribution: written for this index

## Combines with

- [Marching Cubes](https://texelatlas.vercel.app/t/marching-cubes.md): Exact SDF from a binary volume gives a smoother input for contouring.

## Sources

1. [primary] Pedro F. Felzenszwalb, Daniel P. Huttenlocher (2012) Distance Transforms of Sampled Functions. Theory of Computing 8(19), 2012. https://theoryofcomputing.org/articles/v008a019 (verified via http on 2026-11-29)

## Cite this entry

Texel. "Exact Euclidean Distance Transform." https://texelatlas.vercel.app/t/exact-euclidean-distance-transform/ (accessed 2026-12-01).
