This notebook illustrates the TubeTK tube NumPy array data structure and how to create histograms of the properties of a VesselTube.
First, import the function for reading a tube file in as a NumPy array, and read in the file.
In [1]:
import os
import sys
In [2]:
from _tubetk_numpy import tubes_from_file
tubes = tubes_from_file("data/Normal071-VascularNetwork.tre")
The result is a NumPy Record Array where the fields of the array correspond to the properties of a VesselTubeSpatialObjectPoint.
In [3]:
print(type(tubes))
print(tubes.dtype)
The length of the array corresponds to the number of points that make up the tubes.
In [4]:
print(len(tubes))
print(tubes.shape)
Individual points can be sliced, or views can be created on individual fields.
In [5]:
print('Entire points 0, 2:')
print(tubes[:4:2])
print('\nPosition of points 0, 2')
print(tubes['PositionInWorldSpace'][:4:2])
We can easily create a histogram of the radii or visualize the point positions.
In [6]:
%pylab inline
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(16, 6))
ax = fig.add_subplot(1, 2, 1)
ax.hist(tubes['RadiusInWorldSpace'], bins=100)
ax.set_xlabel('Radius')
ax.set_ylabel('Count')
ax = fig.add_subplot(1, 2, 2, projection='3d')
subsample = 100
position = tubes['PositionInWorldSpace'][::subsample]
radius = tubes['RadiusInWorldSpace'][::subsample]
ax.scatter(position[:,0], position[:,1], position[:,2], s=(2*radius)**2)
ax.set_title('Point Positions')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z');
In [ ]: