Image-Py/sknw

Missing points from the skeleton

Opened this issue · 0 comments

Hello,

I am using your library on big 3D skeleton, and there are some behavior I don't understand.

My original skeleton has one connected component only (I compute the Betti0 to know the number of connected components which is equal to 1). But when I manipulate my graph I notice that some pixels are missing (Betti0 is equal to 5).

To visualize the missing point, I wrote back all the points in the edges and the nodes into a nifti image with something similar to:

img = nib.load(skeleton_path)
skeleton_data = img.get_fdata()
graph_sknw = sknw.build_sknw(skeleton_data, multi=False, iso=False, ring=False, full=False)

skeleton = np.zeros_like(skeleton_data)
for (s,e) in graph_sknw.edges:
    centerline = self.graph_sknw.edges[(s,e)]['pts']
    for point in centerline:
        skeleton[point[0], point[1], point[2]] = 1
for node_id in self.graph_sknw.nodes:
    pos = self.graph_sknw.nodes[node_id]['pts'][0].tolist()
        skeleton[pos[0], pos[1], pos[2]] = 1
new_skeleton_path = skeleton_path.replace(".nii.gz", "_from_graph.nii.gz")
new_skeleton_mask = nib.Nifti1Image(skeleton, skeleton_data.affine)
nib.save(new_skeleton_mask, new_skeleton_path)

In the following 3D view we can see in grey/purple the superposition of the original skeleton (in red) and the recreated one (in blue). Close to the centre, we can see a pixel in red that is not present in the skeleton recreated from the graph.
image

I thought it might come from the option so I tried full=True, but I have even more missing pixels (Betti0 = 47).

I don't know why I lose information, and I don't know if it is related but I noticed that the coordinates of the first and last point in the edge do not necessarily correspond to the coordinates of the first or last node of said edge. A few examples :

Edge from node 1 to 7
End node 7 is not at the end of the centerline: pos: [79, 140, 152], centerline end: [79, 141, 152]
Centerline : [[58, 154, 127], [58, 154, 128], [59, 154, 129], [60, 153, 130], [60, 153, 131], [61, 152, 132], [61, 152, 133], [62, 151, 134], [62, 151, 135], [63, 150, 136], [64, 150, 137], [65, 149, 138], [65, 149, 139], [66, 149, 140], [67, 148, 141], [68, 148, 142], [69, 147, 143], [70, 146, 144], [71, 146, 145], [72, 145, 146], [73, 145, 147], [74, 144, 148], [75, 144, 149], [76, 144, 150], [77, 143, 151], [78, 142, 152], [79, 141, 152]]

Edge from node 7 to 21
Start node 7 is not at the start of the centerline: pos: [79, 140, 152], start centerline: [80, 140, 153]
Centerline : [[80, 140, 153], [80, 140, 154], [81, 140, 155], [82, 139, 155], [83, 139, 156], [84, 139, 157], [85, 139, 158], [85, 139, 159], [86, 139, 160], [86, 139, 161], [87, 139, 162], [88, 139, 163], [89, 139, 164], [90, 139, 165], [91, 139, 166], [92, 138, 166], [93, 138, 167], [94, 138, 168], [95, 137, 169], [96, 137, 170], [97, 137, 171], [98, 137, 172], [99, 136, 173], [100, 136, 174], [101, 135, 174], [102, 134, 175], [102, 133, 176], [103, 132, 177], [104, 132, 178], [104, 132, 179], [105, 132, 180], [106, 132, 181]]

The examples come from the skeleton attached.
skeleton.nii.gz
skeleton_from_graph.nii.gz

I would appreciate it if you have any insight on what could be happening because I have no clue. If you need more information, I will do my best to complete it. Thank you in advance.