header

eikonal equation | Distance Field

Let say you have some black and white image (purely binary for now), and you want to compute a distance field from it.

$A:ℝ²→\{0,1\} \\ \;$
$B:ℝ²→ℝ \\ B(\vec{x}) := \min \{ |\vec{x}-\vec{y}| \;;\; y∈ℝ² \;,\; A(y)=1\}$

An alternative way to build our distance field $B$ is, for each pixel of value $1$ in $A$, to fill the entire image $B$ with a "distance cone" or a "radial gradient", and then take the minimum value of each value.

This formulation is very similar to a convolution ! Indeed with $C$ the "distance cone" that is $C(x) = |x|$ where $x∈ℝ^n$

$$\al{ \text{convolution : } (A⊕C)(x) &=& ∫∫ dy⋅A(y)⋅C(x-y) \\ \text{distance field : } (A⊙C)(x) &=& \min_{y∈ℝ^n} A(y)⋅C(x-y) } $$ Then there is a cool property of Fourier transform that can compute convolution much quicker. $$\al{ \mathcal{F}[A]⋅\mathcal{F}[C] &= ∫∫ dx⋅e^{-ikx} A(x)∫∫ dy⋅e^{-iky} C(y) \\ &= ∫∫ dx ∫∫ dy⋅e^{-ik(x+y)}⋅A(x)⋅C(y) \\ F[A⊕C](k) &= ∫∫dx⋅e^{-ikx} ∫∫ dy⋅A(y)⋅C(x-y) \\ &= ∫∫dx ∫∫ dy⋅e^{-ikx}⋅A(y)⋅C(x-y) \\ % z+y = x &= ∫∫dx ∫∫ dz⋅e^{-ik(z+y)}⋅A(y)⋅C(z) \\ }$$ Thus $F[A⊕C](k) = \mathcal{F}[A]⋅\mathcal{F}[C]$
Thus $A⊕C = F^{-1}[\mathcal{F}[A]⋅\mathcal{F}[C]]$

Let's try the same strategy for the distance field ! $$\al{ F[A⊙C](k) &= ∫∫dx⋅e^{-ikx} \min_{y} A(y)⋅C(x-y) \\ &≠ ∫∫dx \min_{y} e^{-ikx}⋅A(y)⋅C(x-y) \\ }$$ Oh no ! we cannot move the $\min$ operator like we could with the integral operator ! This was crucial to allow the change of variable $z=x-y$ ! Moreover $\min$ on complex number is total non sens.