{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Multi-view Volume Plot\n\nPlot various views of a structural MRI.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom vispy import io, plot as vp\n\nfig = vp.Fig(bgcolor='k', size=(800, 800), show=False)\n\nvol_data = np.load(io.load_data_file('brain/mri.npz'))['data']\nvol_data = np.flipud(np.rollaxis(vol_data, 1))\nvol_data = vol_data.astype(np.float32)\n\nclim = [32, 192]\ntexture_format = \"auto\" # None for CPUScaled, \"auto\" for GPUScaled\n\nvol_pw = fig[0, 0]\nv = vol_pw.volume(vol_data, clim=clim, texture_format=texture_format)\nvol_pw.view.camera.elevation = 30\nvol_pw.view.camera.azimuth = 30\nvol_pw.view.camera.scale_factor /= 1.5\n\nshape = vol_data.shape\nfig[1, 0].image(vol_data[:, :, shape[2] // 2], cmap='grays', clim=clim,\n fg_color=(0.5, 0.5, 0.5, 1), texture_format=texture_format)\nfig[0, 1].image(vol_data[:, shape[1] // 2, :], cmap='grays', clim=clim,\n fg_color=(0.5, 0.5, 0.5, 1), texture_format=texture_format)\nfig[1, 1].image(vol_data[shape[0] // 2, :, :].T, cmap='grays', clim=clim,\n fg_color=(0.5, 0.5, 0.5, 1), texture_format=texture_format)\n\nif __name__ == '__main__':\n fig.show(run=True)" ] } ], "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.19" } }, "nbformat": 4, "nbformat_minor": 0 }