bwlabel
can be used to get disconnected objects in an image:
[L Ne] = bwlabel(image);
How to calculate the shortest path between two disconnected closed curves?
Is there a practica开发者_Python百科l(not theoretical) solution?
Suggestion 1
Try extracting the coordinates of the perimeter pixels of the objects you want to connect and use them as nodes in your graph. Then use the A* algorithm to find the shortest paths between each pair between your sets. This effectively solves the all-pairs problem using A* but restricting it to nodes of interest (paths from nodes in one object to the other).
Suggestion 2 (simpler)
Another idea (untested) is to compute the shortest path between the centroid of each blob (regionprops can be used to compute the centroid) and see which perimeter pixel is intersected by the path. Of course, this might work if your centroid is within the blob, but things get messy with non-convex blobs. This reduces the complexity of your algorithm to the number of blobs as opposed to the number of perimeter pixels (which can be huge).
Also, if Suggestion 2 works for you, you can use Floyd-Warshall to compute the shortest paths between all the blobs in the image.
精彩评论