Picture a black-and-white image â shapes painted in white on a black canvas. Now ask a simple question for every black pixel: how far is it from the nearest white pixel?
That question, answered simultaneously for the whole image, is the distance transform. The result is not just another black-and-white picture: it is a field of numbers, a topographic map where height encodes proximity to the shapes. Pixels deep inside empty space carry large values; pixels hugging an edge carry small ones. Painted as a glow, the image literally radiates outward from every boundary.
The naĂŻve approach â for each pixel, scan every foreground pixel and take the minimum â costs for an image of pixels. The chamfer distance transform, introduced by Borgefors in 1984, reduces that to with just two passes: one from top-left to bottom-right, one from bottom-right to top-left. Each pass propagates small distance increments through the grid, and when both sweeps meet in the middle the field is complete.
The elegance is in the simplicity: no priority queues, no graph traversal â just two nested loops and a handful of additions.
Comments
Loading comments...