We have two digital blobs of arbitrary shape, i.e. two connected components on a digital image. They are described by a run-length-coded representation, i.e. a list of $(x, y, l)$ triples of integers.
I want to find the shortest Euclidean distance between them (from pixel center to pixel center) in an efficient way.
Emphasis is on speed, and the obvious brute-force approach (trying every pair of run endpoints) isn't acceptable. Good asymptotic behavior is not necessarily a concern, the solution must be truly fast.
The blobs are usually of moderate size (say $50$ runs) but can on occasion be larger (say $1000$).
There are two degrees of freedom:
- short preprocessing of the blobs is allowed, as several distances to a given blob will be computed;
- an approximate solution is allowed (say to a relative error of $20\%$).
How would you tackle this ?
Update:
Using the convex hulls of the blobs may seem to be an option, because there are less vertices to be considered, and there is an efficient way (linear time) to compute the distance between two disjoint convex polygons. Anyway the algorithm isn't so simple and this won't work for disjoint blobs with non-disjoint convexhulls.
Next update:
Based on the ideas of @bubba and Vobarkun, I change the rules a little. It came back to me that the Voronoi diagram solves the "all nearest neighbors" problem, which is actually what I am after.
The Voronoi diagram of the set of blobs is directly related to the distance map to all blobs, which can be computed in linear time wrt the image size (A. Meijster, J. B. T. M. Roerdink and W. H. Hesselink, A general algorithm for computing distance transforms in linear time.)
As the blobs do result from binarization of a source image, preprocessing the image in linear time is allowed as well.
Now when we have a distance map, the shortest distances will be found on the common boundaries of two Voronoi cells that are in contact. My problem is directly related to the medial axis transform.
Next update:
It is indeed possible to modify the Euclidean distance map algorithm so that it computes not only the distance to the nearest blob, but also the identity of this blob and the closest pixel of the blob.
Now among the pixels on the border common to the two desired blobs, we may select the border pixels that lead to the closest pair from the two blobs. I believe that in most cases this indeed gives the shortest distance between the blobs, but this needs to be checked.