{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipyvolume as ipv\n", "import numpy as np\n", "from matplotlib.pyplot import cm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# download the dataset\n", "!wget -q https://www.dropbox.com/s/eqht79b7j4jqit2/petct.npz?dl=1 -O petct.npz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We show a CT scan and overlay the PET scan" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "full_scan = {k: v.swapaxes(0, 1)[::-1] for k,v in np.load('petct.npz').items()}\n", "print(list(full_scan.keys()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table_ct = cm.gray_r(np.linspace(0, 1, 255))\n", "table_ct[:50, 3] = 0 # make the lower values transparent\n", "table_ct[50:, 3] = np.linspace(0, 0.05, table_ct[50:].shape[0])\n", "tf_ct = ipv.TransferFunction(rgba=table_ct)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "ct_vol = ipv.quickvolshow(full_scan['ct_data'], \n", " tf=tf_ct, lighting=False, \n", " data_min=-1000, data_max=1000)\n", "ct_vol" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Zoom\n", "Zoom in by clicking the magnifying icon, or keep the alt/option key pressed. After zooming in, the higher resolution verion cutout will be displayed. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multivolume rendering\n", "Since version 0.5, ipyvolume supports multivolume rendering, so we can render two volumetric datasets at the same time." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table_pet = cm.hot(np.linspace(0, 1, 255))\n", "table_pet[:50, 3] = 0 # make the lower values transparent\n", "table_pet[50:, 3] = np.linspace(0, 1, table_pet[50:].shape[0])\n", "tf_pet = ipv.TransferFunction(rgba=table_pet)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pet_vol = ipv.volshow(full_scan['pet_data'], \n", " tf=tf_pet, \n", " data_min=0, \n", " data_max=10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pet_vol.rendering_method='MAX_INTENSITY'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table_lab = np.array([\n", " [0,0,0,0],\n", " [0,1,0,1]\n", "])\n", "tf_lab = ipv.TransferFunction(rgba=table_lab)\n", "lab_vol = ipv.volshow(full_scan['label_data']>0, \n", " tf=tf_lab, \n", " data_min=0, \n", " data_max=1)" ] } ], "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 }