Skip to content

Commit

Permalink
ENH: Update ConvertTubes demos
Browse files Browse the repository at this point in the history
Fix path to input data for demos.
Add the ConverTubesToPolyData demo.
  • Loading branch information
aylward committed May 23, 2021
1 parent 61f1156 commit 3eb57bc
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 22 deletions.
70 changes: 48 additions & 22 deletions examples/Demo-ConvertTubesToImage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -47,12 +47,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialization"
"Load the tubes and a reference image which provides the size, spacing, origin, and orientation for the desired output image."
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -64,7 +64,7 @@
"TubeFileReaderType = itk.SpatialObjectReader[Dimension]\n",
" \n",
"tubeFileReader = TubeFileReaderType.New()\n",
"tubeFileReader.SetFileName(\"data/Normal071-VascularNetwork.tre\")\n",
"tubeFileReader.SetFileName(\"Data/MRI-Normals/Normal071-VascularNetwork.tre\")\n",
"tubeFileReader.Update()\n",
"\n",
"tubes = tubeFileReader.GetGroup()\n",
Expand All @@ -75,23 +75,30 @@
"TemplateImageReaderType = itk.ImageFileReader[TemplateImageType]\n",
" \n",
"templateImageReader = TemplateImageReaderType.New()\n",
"templateImageReader.SetFileName(\"data/Normal071-MRA.mha\")\n",
"templateImageReader.SetFileName(\"Data/MRI-Normals/Normal071-MRA.mha\")\n",
"templateImageReader.Update()\n",
"\n",
"templateImage = templateImageReader.GetOutput()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize the template image, just because it looks cool - the data in the image is actually irrelevant."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9895efe0a4ab4cdcbcd6b87f4e75319e",
"model_id": "e33543bccfa3480d8aaf4b5021abd21b",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -107,11 +114,29 @@
"view(templateImage)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a binary image that represents the spatial extent of the TubeSpatialObjects in the hierarchy of SpatialObjects in the variable \"tubes\" that was read-in above. If you only want to visualize centerlines of the tubes, set \"UseRadius\" to false."
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"itkImageF4 not loaded from module TubeTK because of exception:\n",
" module 'itk.TubeTKPython' has no attribute 'itkImageF4'\n",
"vectoritkImageF4 not loaded from module TubeTK because of exception:\n",
" module 'itk.TubeTKPython' has no attribute 'vectoritkImageF4'\n"
]
}
],
"source": [
"TubesToImageFilterType = ttk.ConvertTubesToImage[TemplateImageType]\n",
"tubesToImageFilter = TubesToImageFilterType.New()\n",
Expand All @@ -123,15 +148,23 @@
"outputImage = tubesToImageFilter.GetOutput()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize the results by blending the template and output images. Again, the content of the template image\n",
"doesn't actually matter, but since these tubes were generated from the content of the template image, blending them illustrates how well the binary tube image corresponds with their source image."
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c051bd290da24d6086df8ab87a014ad5",
"model_id": "7c11a4f6da5941af90e0bcd9cac1555f",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -151,20 +184,13 @@
"combinedImage = imMath.GetOutput()\n",
"view(combinedImage)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "WheelEnv",
"language": "python",
"name": "python3"
"name": "wheelenv"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -176,7 +202,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
132 changes: 132 additions & 0 deletions examples/Demo-ConvertTubesToPolyData.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Convert Tubes To PolyData"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook contains a few examples of how to call wrapped methods in itk and ITKTubeTK."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ITK and TubeTK must be installed on your system for this notebook to work. Typically, this is accomplished by\n",
" > python -m pip install itk-tubetk"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import numpy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import itk\n",
"from itk import TubeTK as ttk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the tubes"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"PixelType = itk.F\n",
"Dimension = 3\n",
"ImageType = itk.Image[PixelType, Dimension]\n",
" \n",
"# Read tre file\n",
"TubeFileReaderType = itk.SpatialObjectReader[Dimension]\n",
" \n",
"tubeFileReader = TubeFileReaderType.New()\n",
"tubeFileReader.SetFileName(\"Data/MRI-Normals/Normal071-VascularNetwork.tre\")\n",
"tubeFileReader.Update()\n",
"\n",
"tubes = tubeFileReader.GetGroup()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Generate the polydata representation of the tubes and save it to the file \"Tube.vtp\".\n",
"\n",
"The Tube.vtp file can be displayed by dragging-and-dropping it onto ParaView Glance:\n",
" https://kitware.github.io/paraview-glance/app/"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"itkImageF4 not loaded from module TubeTK because of exception:\n",
" module 'itk.TubeTKPython' has no attribute 'itkImageF4'\n",
"vectoritkImageF4 not loaded from module TubeTK because of exception:\n",
" module 'itk.TubeTKPython' has no attribute 'vectoritkImageF4'\n"
]
}
],
"source": [
"ttk.WriteTubesAsPolyData.New(Input=tubes, FileName=\"Tube.vtp\").Update()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "WheelEnv",
"language": "python",
"name": "wheelenv"
},
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit 3eb57bc

Please sign in to comment.