'How to find the shortest path inside a blob in a binary image using python?

I have a binary image (2D NumPy array) with some blobs. For each blob, I want to find the shortest connected path between the leftmost and rightmost coordinates of the blob.

Using cv2.connectedComponentsWithStats() I can obtain information on each label (bbox, pixels belonging to this blob, etc.). This allows obtaining the leftmost and rightmost points for each blob.

Is there any simple way to compute the shortest connected path?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source