FilFinder icon indicating copy to clipboard operation
FilFinder copied to clipboard

identify branches pixels contaning endpoint

Open valerianmeline opened this issue 3 years ago • 1 comments

Hello, thank you for this great package Is there a way to identify the pixels of branches that contain an endpoint? best valerian

valerianmeline avatar Oct 24 '22 13:10 valerianmeline

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.

gt8mar avatar Aug 28 '23 22:08 gt8mar