{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ch1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import importlib\n", "from distutils.version import LooseVersion\n", "\n", "# check that all packages are installed (see requirements.txt file)\n", "required_packages = {'jupyter', \n", " 'numpy',\n", " 'matplotlib',\n", " 'ipywidgets',\n", " 'scipy',\n", " 'pandas',\n", " 'numba',\n", " 'multiprocess',\n", " 'SimpleITK'\n", " }\n", "\n", "problem_packages = list()\n", "# Iterate over the required packages: If the package is not installed\n", "# ignore the exception. \n", "for package in required_packages:\n", " try:\n", " p = importlib.import_module(package) \n", " except ImportError:\n", " problem_packages.append(package)\n", " \n", "if len(problem_packages) == 0:\n", " print('All is well.')\n", "else:\n", " print('The following packages are required but not installed: ' \\\n", " + ', '.join(problem_packages))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import SimpleITK as sitk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = sitk.Image(256, 128, 64, sitk.sitkInt16)\n", "image_2D = sitk.Image(64, 64, sitk.sitkFloat32)\n", "image_2D = sitk.Image([32,32], sitk.sitkUInt32)\n", "image_RGB = sitk.Image([128,128], sitk.sitkVectorUInt8, 3)\n", "nda = sitk.GetArrayFromImage(image)\n", "plt.imshow(nda[:,:,0])" ] } ], "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.9.5" } }, "nbformat": 4, "nbformat_minor": 4 }