Skip to content

Instantly share code, notes, and snippets.

@thewtex
Created January 25, 2019 16:57
Show Gist options
  • Save thewtex/2fdd0c0d65ef9eb2290938ee83478ce6 to your computer and use it in GitHub Desktop.
Save thewtex/2fdd0c0d65ef9eb2290938ee83478ce6 to your computer and use it in GitHub Desktop.
itk-phasesymmetry on 3D ultrasoun
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting itk-phasesymmetry\n",
" Using cached https://files.pythonhosted.org/packages/c3/17/998b66d78289fd83a6a4db77b56f0088312bfc7dd00c61fe7ae4ac2b640e/itk_phasesymmetry-1.0.2-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting itk-anisotropicdiffusionlbr\n",
" Using cached https://files.pythonhosted.org/packages/cb/6a/5006bbfb97a4b122c47cb244aa9d0ea22d30f1c4a446c341f2396f6d8ea4/itk_anisotropicdiffusionlbr-1.0.1-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting plotly\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/3e/77/905effe9361395d3e094ffd2b54b4085d339a7b7de9c2c91fa55ec257422/plotly-3.5.0-py2.py3-none-any.whl (38.3MB)\n",
"\u001b[K 100% |████████████████████████████████| 38.4MB 891kB/s ta 0:00:011\n",
"\u001b[?25hCollecting itk>=5.0b01 (from itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/d3/9d/ff1f2bed6c07f7a54cc9b8baff4b1098a32350b2258a6fd58b43c9119e5e/itk-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting requests (from plotly)\n",
" Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl\n",
"Requirement already satisfied: six in ./lib/python3.6/site-packages (from plotly) (1.12.0)\n",
"Requirement already satisfied: nbformat>=4.2 in ./lib/python3.6/site-packages (from plotly) (4.4.0)\n",
"Collecting retrying>=1.3.3 (from plotly)\n",
"Requirement already satisfied: decorator>=4.0.6 in ./lib/python3.6/site-packages (from plotly) (4.3.2)\n",
"Collecting pytz (from plotly)\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/61/28/1d3920e4d1d50b19bc5d24398a7cd85cc7b9a75a490570d5a30c57622d34/pytz-2018.9-py2.py3-none-any.whl (510kB)\n",
"\u001b[K 100% |████████████████████████████████| 512kB 3.6MB/s ta 0:00:01\n",
"\u001b[?25hCollecting itk-segmentation>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/e0/25/2986f9cc438f4ed51e9b438e195802c45ba5bafeaf69d1e8949da6ac6f8f/itk_segmentation-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Requirement already satisfied: numpy in ./lib/python3.6/site-packages (from itk>=5.0b01->itk-phasesymmetry) (1.16.0)\n",
"Collecting itk-io>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/05/42/f045e39af147e7b6a1d033aaaad4d3f7e67380a8a22a67c0be15e4e75512/itk_io-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting itk-core>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/bd/0e/88a28d841895c56e9941d6ea5a10de702199902399f49e508aa51e806863/itk_core-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting itk-filtering>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/e4/2a/274d186d7d501d435226052005d5993ad7be0ed431c74f2c3fb0e7eab533/itk_filtering-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting itk-numerics>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/dc/1d/a60e341fd9624feddfbedbe7787a5f2c18b1e2fe3d68119ebe4a53dff455/itk_numerics-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting itk-registration>=5.0b3 (from itk>=5.0b01->itk-phasesymmetry)\n",
" Using cached https://files.pythonhosted.org/packages/93/f3/b20041964c1652213f5b1e9d621b4818d9fe5cb38b448d1ac379b2080fc8/itk_registration-5.0b3-cp36-cp36m-manylinux1_x86_64.whl\n",
"Collecting certifi>=2017.4.17 (from requests->plotly)\n",
" Using cached https://files.pythonhosted.org/packages/9f/e0/accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a/certifi-2018.11.29-py2.py3-none-any.whl\n",
"Collecting urllib3<1.25,>=1.21.1 (from requests->plotly)\n",
" Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl\n",
"Collecting chardet<3.1.0,>=3.0.2 (from requests->plotly)\n",
" Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl\n",
"Collecting idna<2.9,>=2.5 (from requests->plotly)\n",
" Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl\n",
"Requirement already satisfied: ipython-genutils in ./lib/python3.6/site-packages (from nbformat>=4.2->plotly) (0.2.0)\n",
"Requirement already satisfied: jupyter-core in ./lib/python3.6/site-packages (from nbformat>=4.2->plotly) (4.4.0)\n",
"Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in ./lib/python3.6/site-packages (from nbformat>=4.2->plotly) (2.6.0)\n",
"Requirement already satisfied: traitlets>=4.1 in ./lib/python3.6/site-packages (from nbformat>=4.2->plotly) (4.3.2)\n",
"Installing collected packages: itk-core, itk-numerics, itk-filtering, itk-segmentation, itk-io, itk-registration, itk, itk-phasesymmetry, itk-anisotropicdiffusionlbr, certifi, urllib3, chardet, idna, requests, retrying, pytz, plotly\n",
" Found existing installation: itk-core 4.13.1.post1\n",
" Uninstalling itk-core-4.13.1.post1:\n",
" Successfully uninstalled itk-core-4.13.1.post1\n",
" Found existing installation: itk-numerics 4.13.1.post1\n",
" Uninstalling itk-numerics-4.13.1.post1:\n",
" Successfully uninstalled itk-numerics-4.13.1.post1\n",
" Found existing installation: itk-filtering 4.13.1.post1\n",
" Uninstalling itk-filtering-4.13.1.post1:\n",
" Successfully uninstalled itk-filtering-4.13.1.post1\n",
"Successfully installed certifi-2018.11.29 chardet-3.0.4 idna-2.8 itk-5.0b3 itk-anisotropicdiffusionlbr-1.0.1 itk-core-5.0b3 itk-filtering-5.0b3 itk-io-5.0b3 itk-numerics-5.0b3 itk-phasesymmetry-1.0.2 itk-registration-5.0b3 itk-segmentation-5.0b3 plotly-3.5.0 pytz-2018.9 requests-2.21.0 retrying-1.3.3 urllib3-1.24.1\n"
]
}
],
"source": [
"# Note: `pip install itkwidgets` before starting the notebook\n",
"import sys\n",
"!{sys.executable} -m pip install itk-phasesymmetry itk-anisotropicdiffusionlbr plotly"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import itk\n",
"from itkwidgets import view, line_profile\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"image = itk.imread('./input.nrrd', itk.ctype('float'))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2bc91ca18a4d45ed8f392721aa8819ad",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Viewer(gradient_opacity=0.22, rendered_image=<itkImagePython.itkImageF3; proxy of <Swig Object of type 'itkIma…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"viewer = view(image, ui_collapsed=True)\n",
"viewer"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b7ad13bcee18452cb9460c423c5f664a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(LineProfiler(interpolation=False, mode='z', rendered_image=<itkImagePython.itkImageF3; proxy of…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"diffusion_filter = itk.CoherenceEnhancingDiffusionImageFilter.New(image)\n",
"diffusion_filter.SetEnhancement(3)\n",
"diffusion_filter.SetDiffusionTime(5.0)\n",
"diffusion_filter.SetLambda(0.5)\n",
"diffusion_filter.SetNoiseScale(1.5)\n",
"diffusion_filter.SetFeatureScale(3.0)\n",
"diffusion_filter.Update()\n",
"\n",
"line_profile(diffusion_filter.GetOutput(), interpolation=False)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"dimension = image.GetImageDimension()\n",
"\n",
"phase_symmetry_filter = itk.PhaseSymmetryImageFilter.New(diffusion_filter.GetOutput())\n",
"#phase_symmetry_filter = itk.PhaseSymmetryImageFilter.New(image)\n",
"\n",
"phase_symmetry_filter.SetSigma(0.45)\n",
"phase_symmetry_filter.SetPolarity(1)\n",
"phase_symmetry_filter.SetNoiseThreshold(5.0)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f6b76533a3174e6ca4afae4cf410bbb3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Viewer(gradient_opacity=0.22, rendered_image=<itkImagePython.itkImageF3; proxy of <Swig Object of type 'itkIma…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"wavelengths = [4, 4, 4, 8, 8, 8, 12, 12, 12]\n",
"#wavelengths = [2, 2, 4, 4, 6, 6]\n",
"dimension = image.GetImageDimension()\n",
"\n",
"scales = len(wavelengths) / dimension\n",
"wavelength_matrix = itk.Array2D[itk.D](int(scales), dimension)\n",
"np_array = np.array(wavelengths, dtype=np.float64)\n",
"vnl_vector = itk.GetVnlVectorFromArray(np_array)\n",
"wavelength_matrix.copy_in(vnl_vector.data_block())\n",
"phase_symmetry_filter.SetWavelengths(wavelength_matrix)\n",
"\n",
"phase_symmetry_filter.Initialize()\n",
"phase_symmetry_filter.Update()\n",
"view(phase_symmetry_filter, ui_collapsed=True)"
]
},
{
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment