cellects.image.skeletonize
cellects.image.skeletonize
Medial-axis and Lee skeletonization for 2-D and 3-D binary images.
This module provides two public algorithms:
medial_axiscomputes the 2-D medial axis from a binary image.skeletonizecomputes a Lee skeleton of a 2-D or 3-D binary image.
Both functions accept array-like binary images. Nonzero values are treated as foreground, and returned arrays use boolean dtype.
Functions:
| Name | Description |
|---|---|
medial_axis : Compute a 2-D medial axis and optional distance transform. |
|
skeletonize : Compute a Lee skeleton of a 2-D or 3-D binary image. |
|
Notes
The medial-axis implementation targets scikit-image 0.26.0 with
mask=None and rng=0. The Lee implementation targets scikit-image
0.26.0's Lee method. Numba-compiled helpers are used for inner loops.
medial_axis(image, return_distance=False)
Summary
Compute the 2-D medial axis of a binary image.
Extended Description
The medial axis is obtained by deleting foreground pixels whose removal does not change local connectivity and whose 3x3 neighborhood contains at least three foreground pixels. Pixels are visited in order of increasing distance to background, then cornerness, then a fixed random tie-breaker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2-D binary image. Nonzero values are foreground. |
required |
return_distance
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
skeleton |
ndarray of bool
|
Medial axis with the same shape as |
distance |
ndarray of float64
|
Euclidean distance transform of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
This implementation targets scikit-image 0.26.0 with mask=None
and rng=0. The random tie-breaker is deterministic because the
random generator is seeded with 0. Numba-compiled helpers are used for
the corner score and deletion loop.
Examples:
>>> skeleton, distance = medial_axis(image, return_distance=True)
>>> skeleton = medial_axis(image)
>>> print(skeleton.shape)
# (3, 5)
Source code in src/cellects/image/skeletonize.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
skeletonize(image)
Summary
Skeletonize a 2-D or 3-D binary image using Lee thinning.
Extended Description
2-D images are promoted to a one-voxel-thick 3-D volume before thinning. The input is padded with a one-voxel zero border, thinned, and the padding is removed before the result is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2-D or 3-D binary image. Nonzero values are foreground. |
required |
Returns:
| Type | Description |
|---|---|
ndarray of bool
|
Lee skeleton with the same shape as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
This implementation targets scikit-image 0.26.0's Lee method. It uses Numba-compiled loops for directional sweeps, endpoint tests, Euler invariance tests, and N(v)-labeling simple-point tests.
Examples:
>>> image2d = [[0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]
>>> skeleton = skeletonize(image2d)
>>> print(skeleton.shape)
# (3, 4)
>>> image3d = [
>>> [[0, 1, 0], [0, 1, 0], [0, 0, 0]],
>>> [[0, 1, 0], [0, 1, 0], [0, 0, 0]],
>>> [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]
>>> skeleton = skeletonize(image3d)
>>> print(skeleton.shape)
# (3, 3, 3)
Source code in src/cellects/image/skeletonize.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 | |