Created
July 22, 2017 12:14
-
-
Save jamjar919/05a76cf21035cef3cc86ac1979588d6d to your computer and use it in GitHub Desktop.
Skeleton intersection code for
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getSkeletonIntersection(skeleton): | |
""" Given a skeletonised image, it will give the coordinates of the intersections of the skeleton. | |
Keyword arguments: | |
skeleton -- the skeletonised image to detect the intersections of | |
Returns: | |
List of 2-tuples (x,y) containing the intersection coordinates | |
""" | |
# A biiiiiig list of valid intersections 2 3 4 | |
# These are in the format shown to the right 1 C 5 | |
# 8 7 6 | |
validIntersection = [[0,1,0,1,0,0,1,0],[0,0,1,0,1,0,0,1],[1,0,0,1,0,1,0,0], | |
[0,1,0,0,1,0,1,0],[0,0,1,0,0,1,0,1],[1,0,0,1,0,0,1,0], | |
[0,1,0,0,1,0,0,1],[1,0,1,0,0,1,0,0],[0,1,0,0,0,1,0,1], | |
[0,1,0,1,0,0,0,1],[0,1,0,1,0,1,0,0],[0,0,0,1,0,1,0,1], | |
[1,0,1,0,0,0,1,0],[1,0,1,0,1,0,0,0],[0,0,1,0,1,0,1,0], | |
[1,0,0,0,1,0,1,0],[1,0,0,1,1,1,0,0],[0,0,1,0,0,1,1,1], | |
[1,1,0,0,1,0,0,1],[0,1,1,1,0,0,1,0],[1,0,1,1,0,0,1,0], | |
[1,0,1,0,0,1,1,0],[1,0,1,1,0,1,1,0],[0,1,1,0,1,0,1,1], | |
[1,1,0,1,1,0,1,0],[1,1,0,0,1,0,1,0],[0,1,1,0,1,0,1,0], | |
[0,0,1,0,1,0,1,1],[1,0,0,1,1,0,1,0],[1,0,1,0,1,1,0,1], | |
[1,0,1,0,1,1,0,0],[1,0,1,0,1,0,0,1],[0,1,0,0,1,0,1,1], | |
[0,1,1,0,1,0,0,1],[1,1,0,1,0,0,1,0],[0,1,0,1,1,0,1,0], | |
[0,0,1,0,1,1,0,1],[1,0,1,0,0,1,0,1],[1,0,0,1,0,1,1,0], | |
[1,0,1,1,0,1,0,0]]; | |
image = skeleton.copy(); | |
image = image/255; | |
intersections = list(); | |
for x in range(1,len(image)-1): | |
for y in range(1,len(image[x])-1): | |
# If we have a white pixel | |
if image[x][y] == 1: | |
neighbours = zs.neighbours(x,y,image); | |
valid = True; | |
if neighbours in validIntersection: | |
intersections.append((y,x)); | |
# Filter intersections to make sure we don't count them twice or ones that are very close together | |
for point1 in intersections: | |
for point2 in intersections: | |
if (((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) < 10**2) and (point1 != point2): | |
intersections.remove(point2); | |
# Remove duplicates | |
intersections = list(set(intersections)); | |
return intersections; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'm very new to python. I need to use the function getSkeletonIntersection(skeleton) for junction points. But when i add neighbours(x,y,image) in the file like
https://stackoverflow.com/questions/41705405/finding-intersections-of-a-skeletonised-image-in-python-opencv/41708407#41708407
as stated here- it shows UnboundLocalError: local variable referenced before assignment
when I add neighbours(x,y,image) inside of getSkeletonIntersection(skeleton) it shows
TypeError: 'list' object is not callable while trying to access a list
Could you please help here?