In [2]:
import skelet3d
import numpy as np
# Create donut shape
volume_data = np.zeros([3, 7, 9], dtype=np.int)
volume_data [:, :, 1:3] = 1
volume_data [:, 5, 2:9] = 1
volume_data [:, 0:7, 5] = 1
skelet = skelet3d.skelet3d(volume_data)

skan = skelet3d.SkeletonAnalyser(skelet, volume_data=volume_data, voxelsize_mm=[1,1,1])
stats = skan.skeleton_analysis()
edge_number = 1
print(stats[edge_number]['radius_mm'])

# Get np.ndarray with labeled skeletonized image
skan.sklabel


1.082842712474619
C:\Users\Jirik\Miniconda3\envs\skelet3d\lib\site-packages\skelet3d\skeleton_analyser.py:608: RuntimeWarning: invalid value encountered in double_scalars
  np.dot(vect, norm) / np.linalg.norm(norm) ** 2) * np.array(norm)
C:\Users\Jirik\Miniconda3\envs\skelet3d\lib\site-packages\skelet3d\skeleton_analyser.py:539: RuntimeWarning: invalid value encountered in true_divide
  v1u = v1 / np.linalg.norm(v1)
Out[2]:
array([[[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0, -1,  0,  0,  0, -2,  0,  0,  0],
        [ 0,  1,  0,  0,  0,  2,  0,  0,  0],
        [ 0,  1,  0,  0,  0, -3,  0,  0,  0],
        [ 0,  0,  1,  1,  1,  0,  3, -4,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]]])

In [3]:
stats


Out[3]:
{1: {'id': 1,
  'nodeIdA': -3,
  'nodeIdB': -1,
  'connectedEdgesA': [2, 3],
  'connectedEdgesB': [],
  'nodeA_ZYX': [1.0, 4.0, 5.0],
  'nodeB_ZYX': [1.0, 2.0, 1.0],
  'nodeA_ZYX_mm': [1.0, 4.0, 5.0],
  'nodeB_ZYX_mm': [1.0, 2.0, 1.0],
  'orderedPoints_mm_X': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
  'orderedPoints_mm_Y': [4.0, 5.0, 5.0, 5.0, 4.0, 3.0, 2.0],
  'orderedPoints_mm_Z': [5.0, 4.0, 3.0, 2.0, 1.0, 1.0, 1.0],
  'orderedPoints_mm': [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
   [4.0, 5.0, 5.0, 5.0, 4.0, 3.0, 2.0],
   [5.0, 4.0, 3.0, 2.0, 1.0, 1.0, 1.0]],
  'lengthEstimationPixel': 6.82842712474619,
  'curve_params': {'start': [1.0, 4.0, 5.0],
   'vector': [0.0, -2.0, -4.0],
   'fitParamsX': [1.942189750390592e-15,
    -1.0037522676626678e-15,
    1.0000000000000004],
   'fitParamsY': [-7.285714285714276, 4.92857142857142, 4.1666666666666705],
   'fitParamsZ': [4.28571428571428, -8.571428571428571, 5.1666666666666705],
   'fitCurveStrX': '           2\n1.942e-15 x - 1.004e-15 x + 1',
   'fitCurveStrY': '        2\n-7.286 x + 4.929 x + 4.167',
   'fitCurveStrZ': '       2\n4.286 x - 8.571 x + 5.167'},
  'lengthEstimationPoly': 6.72826015607308,
  'lengthEstimationSpline': 6.8573174262952215,
  'lengthEstimation': 6.8573174262952215,
  'nodesDistance': 4.47213595499958,
  'tortuosity': 1.5333427908490018,
  'vectorA': [0.0, 0.5, 1.0],
  'vectorB': [0.0, -0.5, -1.0],
  'radius_mm': 1.082842712474619,
  'phiAa': 116.56505117707799,
  'phiAb': 8.537736462515939e-07,
  'phiAc': 121.717474411461,
  'vectorA0': [0.0, 0.5, 0.0],
  'vectorA1': [0.0, -0.25, -0.5]},
 2: {'id': 2,
  'nodeIdA': -3,
  'nodeIdB': -2,
  'connectedEdgesA': [1, 3],
  'connectedEdgesB': [],
  'nodeA_ZYX': [1.0, 4.0, 5.0],
  'nodeB_ZYX': [1.0, 2.0, 5.0],
  'nodeA_ZYX_mm': [1.0, 4.0, 5.0],
  'nodeB_ZYX_mm': [1.0, 2.0, 5.0],
  'orderedPoints_mm_X': [1.0, 1.0, 1.0],
  'orderedPoints_mm_Y': [4.0, 3.0, 2.0],
  'orderedPoints_mm_Z': [5.0, 5.0, 5.0],
  'orderedPoints_mm': [[1.0, 1.0, 1.0], [4.0, 3.0, 2.0], [5.0, 5.0, 5.0]],
  'lengthEstimationPixel': 2.0,
  'curve_params': {'start': [1.0, 4.0, 5.0],
   'vector': [0.0, -2.0, 0.0],
   'fitParamsX': [8.965859755596919e-16,
    -9.038488777343346e-16,
    0.9999999999999998],
   'fitParamsY': [8.965859755596919e-16,
    -2.0000000000000004,
    3.999999999999999],
   'fitParamsZ': [7.172687804477535e-16, -7.701611931955105e-16, 5.0],
   'fitCurveStrX': '           2\n8.966e-16 x - 9.038e-16 x + 1',
   'fitCurveStrY': '           2\n8.966e-16 x - 2 x + 4',
   'fitCurveStrZ': '           2\n7.173e-16 x - 7.702e-16 x + 5'},
  'lengthEstimationPoly': 1.9999999999999996,
  'lengthEstimationSpline': None,
  'lengthEstimation': 2.0,
  'nodesDistance': 2.0,
  'tortuosity': 1.0,
  'vectorA': [0.0, 0.5, 0.0],
  'vectorB': [0.0, -0.5, 0.0],
  'radius_mm': 1.0,
  'phiAa': 179.99999914622634,
  'phiAb': nan,
  'phiAc': nan,
  'vectorA0': [0.0, 0.5, 1.0],
  'vectorA1': [0.0, -0.25, -0.5]},
 3: {'id': 3,
  'nodeIdA': -4,
  'nodeIdB': -3,
  'connectedEdgesA': [],
  'connectedEdgesB': [1, 2],
  'nodeA_ZYX': [1.0, 5.0, 7.0],
  'nodeB_ZYX': [1.0, 4.0, 5.0],
  'nodeA_ZYX_mm': [1.0, 5.0, 7.0],
  'nodeB_ZYX_mm': [1.0, 4.0, 5.0],
  'orderedPoints_mm_X': [1.0, 1.0, 1.0],
  'orderedPoints_mm_Y': [5.0, 5.0, 4.0],
  'orderedPoints_mm_Z': [7.0, 6.0, 5.0],
  'orderedPoints_mm': [[1.0, 1.0, 1.0], [5.0, 5.0, 4.0], [7.0, 6.0, 5.0]],
  'lengthEstimationPixel': 2.414213562373095,
  'curve_params': {'start': [1.0, 5.0, 7.0],
   'vector': [0.0, -1.0, -2.0],
   'fitParamsX': [8.965859755596919e-16,
    -9.038488777343346e-16,
    0.9999999999999998],
   'fitParamsY': [-1.9999999999999996, 0.9999999999999996, 5.0],
   'fitParamsZ': [5.0208814631342755e-15,
    -2.000000000000002,
    6.999999999999999],
   'fitCurveStrX': '           2\n8.966e-16 x - 9.038e-16 x + 1',
   'fitCurveStrY': '    2\n-2 x + 1 x + 5',
   'fitCurveStrZ': '           2\n5.021e-15 x - 2 x + 7'},
  'lengthEstimationPoly': 2.466942252649898,
  'lengthEstimationSpline': None,
  'lengthEstimation': 2.414213562373095,
  'nodesDistance': 2.23606797749979,
  'tortuosity': 1.0796691275336336,
  'vectorA': [0.0, 0.25, 0.5],
  'vectorB': [0.0, -0.25, -0.5],
  'radius_mm': 1.0,
  'phiBa': 63.43494882292201,
  'phiBb': 8.537736462515939e-07,
  'phiBc': 148.282525588539,
  'vectorB0': [0.0, 0.5, 1.0],
  'vectorB1': [0.0, 0.5, 0.0]}}

Export to TIFF


In [17]:
import io3d

img = ((skan.sklabel + 5) * 10).astype(np.uint8)
img[img==50] = 0
io3d.write(img, "fn2.tiff")
np.min(skan.sklabel)


Out[17]:
-4

In [18]:
img


Out[18]:
array([[[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0, 40,  0,  0,  0, 30,  0,  0,  0],
        [ 0, 60,  0,  0,  0, 70,  0,  0,  0],
        [ 0, 60,  0,  0,  0, 20,  0,  0,  0],
        [ 0,  0, 60, 60, 60,  0, 80, 10,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0,  0]]], dtype=uint8)