Coverage for .tox/py39/lib/python3.9/site-packages/cows/filament.py: 100.00%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import numpy as np
2from ._filament import _label_skeleton, _find_filaments
5def label_skeleton(skel, periodic=False):
6 ''' Label the skeleton.
8 Label all skeleton cells with their respective number of neighbour
9 that they share a face, edge or vertex with (N_26).
11 Parameters
12 ----------
13 skel : ndarray, 3D
14 A binary image containing the skeletonized objects. Zeros
15 represent background, nonzero values are foreground.
16 periodic: bool
17 If True, the skeletonization uses periodic boundary conditions
18 for the input array. Input array must be 3D.
20 Returns
21 -------
22 result : ndarray
23 The labeled skeleton.
24 '''
25 assert skel.ndim == 3
27 return _label_skeleton(skel, periodic)
30def separate_skeleton(skel, periodic=False):
31 ''' Separate the skeleton.
33 Set all the skeleton cells with more than 2 neighbours to the
34 background value of zero. This results in a set of individual
35 objects of arbitrary length and 2 endpoints.
37 Parameters
38 ----------
39 skel : ndarray, 3D
40 A binary image containing the skeletonized objects. Zeros
41 represent background, nonzero values are foreground.
42 periodic: bool
43 If True, the skeletonization uses periodic boundary conditions
44 for the input array. Input array must be 3D.
46 Returns
47 -------
48 result : ndarray
49 The separated skeleton.
50 '''
51 assert skel.ndim == 3
53 # Label the skeleton
54 skel = _label_skeleton(skel, periodic)
56 # Remove all cells with more than two neighbours
57 data_shape = skel.shape
58 skel[skel>2] = 0
60 # Label the separated skeleton
61 skel = _label_skeleton(skel, periodic)
63 return skel
66def find_filaments(skel, periodic=False):
67 ''' Find individual filament.
69 Connects all cells that are neighbours within a 3x3x3 neihbourhood.
70 The set of connected cells are labled with a unique ID.
72 Parameters
73 ----------
74 skel : ndarray, 3D
75 An array containing the classified and separated skeleton. Zeros
76 represent background, ones are endpoints and twos are regular
77 cells.
78 periodic: bool
79 If True, the skeletonization uses periodic boundary conditions
80 for the input array. Input array must be 3D.
82 Returns
83 -------
84 result : ndarray, 3D
85 An array with skel.shape containing the sets of connected cells
86 (filaments) with their respective ID.
87 catalogue : ndarray, 2D
88 A catalogue containing, for each cell, a row of ID, X-, Y- and Z-
89 position.
90 '''
91 assert skel.ndim == 3
92 assert skel.shape[0] == skel.shape[1]
93 assert skel.shape[0] == skel.shape[2]
95 return _find_filaments(skel, periodic)