How do I locate the end points of a bridge-like structure in an image?
Below is a generalized representation.
I have a set of images that look like what you see on the left hand column as shown in the above picture. What I am trying to detect/locate is actually the two endpoints that are shown on the right hand column in the above picture. It's quite like locating the "two ends points" of the 'bridge'.
I have applied some basic morphological operations; however, either I'm doing it wrong or those basic morphological operations aren't working in this scenario. (I have tried making it into skeletons; however, once the skeletons are formed, I can't seem to detect the cross with three edges).
Thanks for the previous suggestion; however, it looks like the original sets of images cannot be completely generalized like what I'd previously drawn.
I have attached the latest updates to this question. Below is a more detailed representation that includes the original segmented regions and the corresponding images that'd undergone a "thinning" morphological operation. Again, the left side is the originally segmented region; while on the right would be the points to be detected.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With