You can compute Voronoi diagrams for each pixel of an image with distance fields in O(N) where N is the number of pixels. This is faster than the shown jump flooding algorithm, which is only O(N log N).<p>Here is an example for a CPU-based implementation: <a href="https://github.com/983/df" rel="nofollow">https://github.com/983/df</a><p>It is not difficult to implement for the GPU because the algorithm can be run in parallel for each image row and column, assuming general GPU compute capability, which admittedly is still lacking in some browsers.