How do I locate the end points of a bridge-like structure in an image?
Below is a generalized representation.
Here is a code example to locate branch points after skeletonizing the image:
import pymorph as m
import mahotas
from numpy import array
image = mahotas.imread('1.png') # load image
b1 = image[:,:,1] < 150 # make binary image from thresholded green channel
b2 = m.thin(b1) # create skeleton
b3 = m.thin(b2, m.endpoints('homotopic'), 15) # prune small branches, may need tuning
# structuring elements to search for 3-connected pixels
seA1 = array([[False, True, False],
[False, True, False],
[ True, False, True]], dtype=bool)
seB1 = array([[False, False, False],
[ True, False, True],
[False, True, False]], dtype=bool)
seA2 = array([[False, True, False],
[ True, True, True],
[False, False, False]], dtype=bool)
seB2 = array([[ True, False, True],
[False, False, False],
[False, True, False]], dtype=bool)
# hit or miss templates from these SEs
hmt1 = m.se2hmt(seA1, seB1)
hmt2 = m.se2hmt(seA2, seB2)
# locate 3-connected regions
b4 = m.union(m.supcanon(b3, hmt1), m.supcanon(b3, hmt2))
# dilate to merge nearby hits
b5 = m.dilate(b4, m.sedisk(10))
# locate centroids
b6 = m.blob(m.label(b5), 'centroid')
outputimage = m.overlay(b1, m.dilate(b6,m.sedisk(5)))
mahotas.imsave('output.png', outputimage)