MorphologicalComponents can break an image into components.
How can we measure the pairwise distance between these components efficiently? Performance is important.
Here's an example (that I took from here and cleaned up).
It has 112 components:
im = Import["https://i.stack.imgur.com/U7myR.png"]; MorphologicalComponents[im] // Max (* 112 *)
Thus we need to find
Binomial[112, 2] == 6216 distances efficiently.
Computing the pairwise distances of components would allow us to determine which are adjacent. This image is just one example. I am looking for a general approach that would work on any map.
I suspect that there must be something built-in that I did not yet find. I am aware of
DistanceTransform, but I am unable to make it perform sufficiently well. I solved this particular map efficiently using
ImageMesh, but that approach is not generalizable: the mesh is not usually accurate. It is also difficult to map back to the original component indices.