FilFinder
FilFinder copied to clipboard
identify branches pixels contaning endpoint
Hello, thank you for this great package Is there a way to identify the pixels of branches that contain an endpoint? best valerian
This works for me:
def find_endpoints(skel):
# Define a kernel that counts the number of neighbors
kernel = np.array([
[1, 1, 1],
[1, 10, 1],
[1, 1, 1]
])
neighbors_count = convolve(skel.astype(int), kernel, mode='constant', cval=0)
# Endpoints are skeleton points with only one neighbor
return (neighbors_count == 11) & skel
This works by checking each pixel in a skeleton image for neighbors. if there is only one neighbor, then you have an endpoint!
Note: if you have 2 neighbors, you would be part of a line and if you have 3+ neighbors you have a junction.