{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from p2ch07.dsets import getNoduleInfoList, getCt\n", "noduleInfo_list = getNoduleInfoList(requireDataOnDisk_bool=False)\n", "malignantInfo_list = [x for x in noduleInfo_list if x[0]]\n", "diameter_list = [x[1] for x in malignantInfo_list]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1351\n", "(True, 32.27003025, '1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886', (67.61451718, 85.02525992, -109.8084416))\n" ] } ], "source": [ "print(len(malignantInfo_list))\n", "print(malignantInfo_list[0])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0 32.3 mm\n", " 100 17.7 mm\n", " 200 13.0 mm\n", " 300 10.0 mm\n", " 400 8.2 mm\n", " 500 7.0 mm\n", " 600 6.3 mm\n", " 700 5.7 mm\n", " 800 5.1 mm\n", " 900 4.7 mm\n", "1000 4.0 mm\n", "1100 0.0 mm\n", "1200 0.0 mm\n", "1300 0.0 mm\n" ] } ], "source": [ "for i in range(0, len(diameter_list), 100):\n", " print('{:4} {:4.1f} mm'.format(i, diameter_list[i]))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(True, 32.27003025, '1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886', (67.61451718, 85.02525992, -109.8084416))\n", "(True, 30.61040636, '1.3.6.1.4.1.14519.5.2.1.6279.6001.112740418331256326754121315800', (47.90350511, 37.60442008, -99.93417567))\n", "(True, 30.61040636, '1.3.6.1.4.1.14519.5.2.1.6279.6001.112740418331256326754121315800', (44.19, 37.79, -107.01))\n", "(True, 30.61040636, '1.3.6.1.4.1.14519.5.2.1.6279.6001.112740418331256326754121315800', (40.69, 32.19, -97.15))\n", "(True, 27.44242293, '1.3.6.1.4.1.14519.5.2.1.6279.6001.943403138251347598519939390311', (-45.29440163, 74.86925386, -97.52812481))\n", "(True, 27.07544345, '1.3.6.1.4.1.14519.5.2.1.6279.6001.481278873893653517789960724156', (-102.571208, -5.186558766, -205.1033412))\n", "(True, 26.83708074, '1.3.6.1.4.1.14519.5.2.1.6279.6001.487268565754493433372433148666', (121.152909372, 12.9136003304, -159.399497186))\n", "(True, 26.83708074, '1.3.6.1.4.1.14519.5.2.1.6279.6001.487268565754493433372433148666', (118.8539408, 11.54202797, -165.5042458))\n", "(True, 25.87269662, '1.3.6.1.4.1.14519.5.2.1.6279.6001.177086402277715068525592995222', (-66.628286875, 57.151972075, -110.12035075))\n", "(True, 25.41540526, '1.3.6.1.4.1.14519.5.2.1.6279.6001.219618492426142913407827034169', (-101.7504204, -95.65460516, -138.4943211))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.107109359065300889765026303943', (-100.57, -66.23, -218.76))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.106379658920626694402549886949', (-71.09, 68.3, -160.4))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.102681962408431413578140925249', (106.18, 12.61, -96.81))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.102681962408431413578140925249', (96.2846726653, 19.0348690723, -88.478440818))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (89.32, 190.84, -516.82))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (89.32, 143.23, -427.1))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (85.12, 152.33, -425.7))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (8.8, 174.74, -401.87))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (5.99, 171.94, -398.37))\n", "(True, 0.0, '1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016233746780170740405', (1.79, 166.34, -408.88))\n" ] } ], "source": [ "for nodule_tup in malignantInfo_list[:10]:\n", " print(nodule_tup)\n", "for nodule_tup in malignantInfo_list[-10:]:\n", " print(nodule_tup)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([323, 466, 248, 111, 71, 57, 37, 29, 5, 4], dtype=int64),\n", " array([ 0. , 3.22700302, 6.45400605, 9.68100907, 12.9080121 ,\n", " 16.13501512, 19.36201815, 22.58902117, 25.8160242 , 29.04302722,\n", " 32.27003025]))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.histogram(diameter_list)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2018-12-11 11:24:57,865 INFO pid:30236 p2ch07.dsets:201:__init__ : 551065 training samples\n" ] } ], "source": [ "from p2ch07.vis import findMalignantSamples, showNodule\n", "malignantSample_list = findMalignantSamples()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2018-12-11 11:25:01,788 INFO pid:30236 p2ch07.dsets:201:__init__ : 602 training samples\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "1.3.6.1.4.1.14519.5.2.1.6279.6001.183982839679953938397312236359 0 True [0, 1, 2, 3, 4, 5, 6]\n" ] } ], "source": [ "series_uid = malignantSample_list[11][2]\n", "showNodule(series_uid)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2018-12-11 11:25:08,042 INFO pid:30236 p2ch07.dsets:201:__init__ : 605 training samples\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "1.3.6.1.4.1.14519.5.2.1.6279.6001.126264578931778258890371755354 0 True [0]\n" ] } ], "source": [ "series_uid = '1.3.6.1.4.1.14519.5.2.1.6279.6001.126264578931778258890371755354'\n", "showNodule(series_uid)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\elis\\Miniconda3\\envs\\book\\lib\\site-packages\\ipyvolume\\serialize.py:81: RuntimeWarning: invalid value encountered in true_divide\n", " gradient = gradient / np.sqrt(gradient[0]**2 + gradient[1]**2 + gradient[2]**2)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "339fa8710d8b459182d9d3afeb08f720", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(VBox(children=(HBox(children=(Label(value='levels:'), FloatSlider(value=0.25, max=1.0, step=0.0…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import ipyvolume as ipv\n", "V = np.zeros((128,128,128)) # our 3d array\n", "# outer box\n", "V[30:-30,30:-30,30:-30] = 0.75\n", "V[35:-35,35:-35,35:-35] = 0.0\n", "# inner box\n", "V[50:-50,50:-50,50:-50] = 0.25\n", "V[55:-55,55:-55,55:-55] = 0.0\n", "ipv.quickvolshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\elis\\Miniconda3\\envs\\book\\lib\\site-packages\\ipyvolume\\widgets.py:179: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.\n", " data_view = self.data_original[view]\n", "C:\\Users\\elis\\Miniconda3\\envs\\book\\lib\\site-packages\\ipyvolume\\utils.py:204: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.\n", " data = (data[slices1] + data[slices2])/2\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "61e1eb24c53149d8bdc8bd6188257862", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(VBox(children=(HBox(children=(Label(value='levels:'), FloatSlider(value=0.25, max=1.0, step=0.0…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ct = getCt(series_uid)\n", "ipv.quickvolshow(ct.ary, level=[0.25, 0.5, 0.9], opacity=0.1, level_width=0.1, data_min=0, data_max=2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from p2ch10.dsets import getCt\n", "ct = getCt(series_uid)\n", "air_mask, lung_mask, dense_mask, denoise_mask, tissue_mask, body_mask = ct.build3dLungMask()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\elis\\Miniconda3\\envs\\book\\lib\\site-packages\\ipyvolume\\serialize.py:81: RuntimeWarning: invalid value encountered in sqrt\n", " gradient = gradient / np.sqrt(gradient[0]**2 + gradient[1]**2 + gradient[2]**2)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9c40dfe3a3cc4b49aebce4cbee8e3d62", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(VBox(children=(HBox(children=(Label(value='levels:'), FloatSlider(value=0.17, max=1.0, step=0.0…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bones = ct.ary * (ct.ary > 1.5)\n", "lungs = ct.ary * air_mask\n", "ipv.figure()\n", "ipv.pylab.volshow(bones + lungs, level=[0.17, 0.17, 0.23], data_min=0.1, data_max=0.9)\n", "ipv.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from mayavi import mlab\n", "mlab.init_notebook()\n", "mlab.test_plot3d()" ] } ], "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }