The Skeletonize function output wrong figure.
Description:
Hi, I tried to extract the skeleton figures of some artificial conducts using the original code posted on the web: https://scikit-image.org/docs/stable/auto_examples/edges/plot_skeleton.html#sphx-glr-download-auto-examples-edges-plot-skeleton-py But there was always a wrong hint: ValueError: arrays must be of dtype byte, short, float32 or float64.
So, I transformed the image datatype into float as below. Unfortunately, the output skeleton figure is wrong. I post it at the end of the code. I thought maybe the ball.png cannot be recognized by the skeletonize function, since it was colorful and a screenshot. So, I tried the sample horse picture using the revised code. As you see, the skeleton of horse was still wrong.
Is there anyone could tell me how to get the wright skeleton picture using the Skeletonize function?
Thanks a lot. Huizhong
Way to reproduce:
from skimage.morphology import skeletonize from skimage import data import matplotlib.pyplot as plt from skimage.util import invert, img_as_float
Invert the ball image
path = 'C:/Users/63517/anaconda3/pkgs/scikit-image-0.20.0-py311h3513d60_0/Lib/site-packages/skimage/data/ball.png' image = plt.imread(path) img_f = img_as_float(image, force_copy=False)
perform skeletonization
skeleton = skeletonize(img_f) ske = img_as_float(skeleton, force_copy=False)
display results
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 4), sharex=True, sharey=True)
ax = axes.ravel()
ax[0].imshow(img_f, cmap=plt.cm.gray) ax[0].axis('off') ax[0].set_title('original', fontsize=20)
ax[1].imshow(ske, cmap=plt.cm.gray) ax[1].axis('off') ax[1].set_title('skeleton', fontsize=20)
fig.tight_layout()
plt.show()
Version information:
No response
@Huizhong-Wu hi, thanks for reporting! Could you provide the versions of your scikit-image, scipy, and numpy?
@soupault hi, the version of my scikit-image is 0.23.2, the scipy is 1.11.4, and the numpy is 1.26.2
I converted the color picture into gray-scale, but it still doesn't work.
I also binarized the picture value, but the results were still not so good.
Hi! Replying to all the messages above in their original order:
`ValueError: arrays must be of dtype byte, short, float32 or float64.``
I am not sure which particular function raised that error, but it definitely was not the one of scikit-image. Potentially, the failure happened at the preprocessing stage, or somewhere in numpy, yet it is difficult to say more.
Because of that issue, it is difficult to diagnose why exactly skeletonization failed for the examples in the original post.
For the histology example (https://github.com/scikit-image/scikit-image/issues/7417#issuecomment-2106006364), the result is expected, since all the non-0 pixels are treated as the foreground. Accordingly, one possible skeleton of a square is just a pixel in the middle, as in the provided visualization.
For the final set of examples (https://github.com/scikit-image/scikit-image/issues/7417#issuecomment-2106152380), the skeletons are somewhat normal. The first one is likely as good as it gets. For the second, I am getting a different result using the screenshot of the provided image:
All in all, I am not sure whether it is possible to reproduce the issue without the exact data and the code used to produce the results in the first post. @Huizhong-Wu if you still have them, please, consider sharing. Otherwise, I suggest to close the issue as "failed to reproduce".
Hello scikit-image core devs! There hasn't been any activity on this issue for more than 180 days. I have marked it as "dormant" to make it easy to find.
To our contributors, thank you for your contribution and apologies if this issue fell through the cracks! Hopefully this ping will help bring some fresh attention to the issue. If you need help, you can always reach out on our forum
If you think that this issue is no longer relevant, you may close it, or we may do it at some point (either way, it will be done manually).
I'm closing this for now since @soupault suggested so. Please feel very welcome to reopen this if you'd like to continue the discussion @Huizhong-Wu.
In any case, thanks for the reaching out! :blush: