Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify branches pixels contaning endpoint #78

Open
valerianmeline opened this issue Oct 24, 2022 · 1 comment
Open

identify branches pixels contaning endpoint #78

valerianmeline opened this issue Oct 24, 2022 · 1 comment

Comments

@valerianmeline
Copy link

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

@gt8mar
Copy link

gt8mar commented Aug 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants