Empty Graph returned for circular skeletons without branches
Quasimondo opened this issue · 8 comments
I am not sure if this is on purpose, but it looks like there is no graph returned for skeletons that result in a single chain that connects back to itself - I tried both multi=False and True but the result is aways an empty graph:
img = loadImg(path)>127
ske = skeletonize(~img).astype(np.uint16)
graph = sknw.build_sknw(ske)
print("\n".join(nx.generate_gml(graph)))`
Result:
graph [ ]
sknw follow these steps:
- detect the node end junction (which has 1 neighbour or more than 2neighbours)
- trace from one node to another through the path (which has 2 neighbours)
so a pure ring without any branch would not be detected now.
If you need detect pure ring or isolate point, we can try to add some features.
Thanks for the quick response! I am looking at the source right now and will see if I can patch it to my needs. I am thinking of adding one random start node if there are 0 nodes, but the skeleton image has non-zero entries.
I think this might do for my purposes:
def build_sknw(ske, multi=False):
buf = buffer(ske)
nbs = neighbors(buf.shape)
acc = np.cumprod((1,)+buf.shape[::-1][:-1])[::-1]
mark(buf, nbs)
pts = np.array(np.where(buf.ravel()==2))[0]
if len(pts)==0 and np.sum(ske)>0:
print("ring detected")
pts = np.where(ske.ravel())[0]
buf[np.array(np.unravel_index(pts, ske.shape))+1] = 2
nodes, edges = parse_struc(buf, pts, nbs, acc)
return build_graph(nodes, edges, multi)
- np.where did not make sure the ring series. (it is in row and columns series)
- it did not treat when (both pure ring and branch exist)
I learn np.unravel_index from you, thanks.
i would give a update soon
Oh yes - thanks for checking the code and finding the issues with it - I just needed it for a very simple example so I did miss the other possible cases.
add isolate and ring parameter, have a try.
ps: if you only need the ring's coordinates, you can try skimage.regionprops