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 [5]:
import tubetk
from tubetk.numpy import tubes_from_file
import os
filepath = os.path.join(os.path.dirname(tubetk.__file__),
'..', '..', '..',
'MIDAS_Data', 'VascularNetwork.tre')
tubes = tubes_from_file(filepath)
The result is a NumPy Record Array where the fields of the array correspond to the properties of a VesselTubeSpatialObjectPoint.
In [6]:
print(type(tubes))
print(tubes.dtype)
The length of the array corresponds to the number of points that make up the tubes.
In [7]:
print(len(tubes))
print(tubes.shape)
Individual points can be sliced, or views can be created on individual fields.
In [8]:
print('Entire points 0, 2:')
print(tubes[:4:2])
print('\nPosition of points 0, 2')
print(tubes['Position'][:4:2])
We can easily create a histogram of the radii or visualize the point positions.
In [9]:
%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['Radius'], bins=100)
ax.set_xlabel('Radius')
ax.set_ylabel('Count')
ax = fig.add_subplot(1, 2, 2, projection='3d')
subsample = 100
position = tubes['Position'][::subsample]
radius = tubes['Radius'][::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 [ ]: