skan.Skeleton returning integer (not skeleton object)

108 Views Asked by At

Sorry, this might turn out to be a very basic problem but I'm stumped:

I'm trying to get the lengths of skeleton branches. I'm able to skeletonize my image and can see the skeleton with draw.overlay_skeleton_2d() but when I try to get any statistics on the skeleton back I get an error:

TypeError                                 Traceback (most recent call last)
<ipython-input-3-5924e1b8ffc8> in <module>
      4 # fig, ax = plt.subplots()
      5 # draw.overlay_skeleton_2d(img, skeleton0, dilate=1, axes=ax)
----> 6 branch_data = summarize(Skeleton(skeleton0))
      7 branch_data.head()

~\AppData\Roaming\Python\Python38\site-packages\skan\csr.py in __init__(self, skeleton_image, spacing, source_image, _buffer_size_offset, keep_images, junction_mode, unique_junctions)
    383         self.nbgraph = csr_to_nbgraph(graph, pixel_values)
    384         self.coordinates = coords
--> 385         self.paths = _build_skeleton_path_graph(
    386                 self.nbgraph, _buffer_size_offset=_buffer_size_offset
    387                 )

~\AppData\Roaming\Python\Python38\site-packages\skan\csr.py in _build_skeleton_path_graph(graph, _buffer_size_offset)
    259 def _build_skeleton_path_graph(graph, *, _buffer_size_offset=None):
    260     if _buffer_size_offset is None:
--> 261         max_num_cycles = graph.indices.size // 4
    262         _buffer_size_offset = max_num_cycles
    263     degrees = np.diff(graph.indptr)

TypeError: expected dtype object, got 'numpy.dtype[int32]'

Any tips would be great. I'm still a Python beginner so, like I said, the mistake might be a very basic one.

Rgds,

Olie

*Edits included

This is my code:


import cv2
from skan import draw, skeleton_to_csgraph, Skeleton, summarize
from skimage import morphology
# import numpy as np

from matplotlib import pyplot as plt
%matplotlib notebook

# load image and convert to bool
img = cv2.imread(save_p + "\\" + img_name + ".png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = img.astype(bool)

# skeletonize
skeleton0 = morphology.skeletonize(img)

### check skeleton
# fig, ax = plt.subplots()
# draw.overlay_skeleton_2d(img, skeleton0, dilate=1, axes=ax)

### from Documentation (linked below)
branch_data = summarize(Skeleton(skeleton0))      # ignoring scaling for now
branch_data.head()

# Skel_obj = Skeleton(skeleton0)        # testing this but same problem
# Skel_obj.path_lengths(0)

I have attempted to follow a couple of posts (e.g. this but for that particular case the module wont install and anyway... it seems like skan.summarize is exactly what I need - documentation

Name: numpy Version: 1.23.4

Name: scikit-image Version: 0.19.3

Name: pandas Version: 1.3.4

Name: skan Version: 0.10.0

Name: numba Version: 0.50.1

Windows 10 PC

binary image

0

There are 0 best solutions below