{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook illustrates the [TubeTK](http://tubetk.org) tube NumPy array data structure and how to create histograms of the properties of a [VesselTube](https://www.itk.org/Doxygen/html/classitk_1_1VesselTubeSpatialObject.html).\n", "\n", "First, import the function for reading a tube file in as a NumPy array, and read in the file." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "ename": "ImportError", "evalue": "cannot import name 'tubes_from_file' from 'itk' (unknown location)", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mitk\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtubes_from_file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mtubes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtubes_from_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"data/Normal071-VascularNetwork.tre\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mImportError\u001b[0m: cannot import name 'tubes_from_file' from 'itk' (unknown location)" ] } ], "source": [ "from itk import tubes_from_file\n", "\n", "tubes = tubes_from_file(\"data/Normal071-VascularNetwork.tre\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The result is a [NumPy Record Array](https://docs.scipy.org/doc/numpy/user/basics.rec.html) where the fields of the array correspond to the properties of a [VesselTubeSpatialObjectPoint](https://www.itk.org/Doxygen/html/classitk_1_1VesselTubeSpatialObjectPoint.html)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "[('Id', '" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "%pylab inline\n", "from mpl_toolkits.mplot3d import Axes3D\n", "import matplotlib.pyplot as plt\n", "\n", "fig = plt.figure(figsize=(16, 6))\n", "\n", "ax = fig.add_subplot(1, 2, 1)\n", "ax.hist(tubes['RadiusInWorldSpace'], bins=100)\n", "ax.set_xlabel('Radius')\n", "ax.set_ylabel('Count')\n", "\n", "ax = fig.add_subplot(1, 2, 2, projection='3d')\n", "subsample = 100\n", "position = tubes['PositionInWorldSpace'][::subsample]\n", "radius = tubes['RadiusInWorldSpace'][::subsample]\n", "ax.scatter(position[:,0], position[:,1], position[:,2], s=(2*radius)**2)\n", "ax.set_title('Point Positions')\n", "ax.set_xlabel('X')\n", "ax.set_ylabel('Y')\n", "ax.set_zlabel('Z');" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 1 }