Skan
raw JSON → 0.13.1 verified Sat May 09 auth: no python
Skeleton analysis in Python. Current version 0.13.1, released 2024-08-26. Active development, irregular releases.
pip install skan Common errors
error ModuleNotFoundError: No module named 'skan' ↓
cause skan is not installed.
fix
Run
pip install skan. error ImportError: cannot import name 'Skeleton' from 'skan' ↓
cause Old version of skan (pre-0.9) where Skeleton was in a submodule.
fix
Upgrade skan to at least v0.9.0:
pip install -U skan. Then use from skan import Skeleton. error ValueError: The truth value of an array with more than one element is ambiguous ↓
cause Passing a multi-channel image instead of a single binary skeleton.
fix
Ensure the input to
Skeleton or summarise is a 2D or 3D binary array. Warnings
breaking In skan v0.10.0, the junction resolution algorithm changed to always use a minimum spanning tree. The `uniquify_junctions` and `junction_mode` arguments to `Skeleton` are deprecated and will be removed in a future version. ↓
fix Remove these arguments from your `Skeleton` calls. If you relied on the old behaviour, contact the maintainers.
deprecated Column names in the summary dataframe used `-` as separator; as of v0.12.0, they use `_`. The old names are deprecated and will be removed. ↓
fix Update code to use new column names (e.g. 'branch-type' -> 'branch_type'). Use `skan.summarise(..., separator='_')` to force new style.
gotcha Skan expects binary skeleton images where skeleton pixels are 1 (True) and background is 0 (False). If you pass a skeleton with 0 for skeleton and 1 for background, results will be incorrect. ↓
fix Ensure your skeleton image has 1 for skeleton pixels (foreground) and 0 for background.
gotcha When working with float32 images, skan v0.12.2 and earlier could crash due to a numba issue. This was fixed in v0.12.2, but upgrading to v0.13+ is recommended. ↓
fix Update to skan >=0.12.2.
Imports
- Skeleton wrong
import skan.Skeletoncorrectfrom skan import Skeleton - summarise wrong
from skan.csr import summarisecorrectfrom skan import summarise - draw_overlay wrong
from skan.visualise import draw_overlaycorrectfrom skan import draw_overlay
Quickstart
import numpy as np
from skimage.morphology import skeletonize
from skan import Skeleton, summarise
# Create a binary skeleton (example)
image = np.array([[0,0,0,0,0],
[0,1,1,1,0],
[0,0,0,1,0],
[0,1,1,1,0],
[0,0,0,0,0]], dtype=bool)
skel = skeletonize(image)
# Analyse skeleton
branch_data = summarise(skel)
print(branch_data.head())