Skip to content

Instantly share code, notes, and snippets.

@thewtex
Last active August 27, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewtex/e2336c47c2de57524b5b8f0009ad0470 to your computer and use it in GitHub Desktop.
Save thewtex/e2336c47c2de57524b5b8f0009ad0470 to your computer and use it in GitHub Desktop.
JupyterLab record an itk-jupyter-widgets bonsai tree volume video
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Install dependencies for this example\n",
"# Note: This does not include itk-jupyter-widgets, itself\n",
"# The page may need to be reloaded after ipywebrtc is installed\n",
"import sys\n",
"!{sys.executable} -m pip install itk-io itkwidgets ipywebrtc>=0.4.0"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" from urllib.request import urlretrieve\n",
"except ImportError:\n",
" from urllib import urlretrieve\n",
"import os\n",
"\n",
"import itk\n",
"\n",
"from itkwidgets import view\n",
"import itkwidgets\n",
"import ipywebrtc as webrtc"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Download data\n",
"file_name = 'bonsai.nrrd'\n",
"if not os.path.exists(file_name):\n",
" url = 'https://data.kitware.com/api/v1/file/5b8439a98d777f43cc8d4d05/download'\n",
" urlretrieve(url, file_name)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e1503a473f34011a2266bd3c9eacd17",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Viewer(annotations=False, cmap='GBBr', rendered_image=<itkImagePython.itkImageUS3; proxy of <Swig Object of ty…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"image = itk.imread(file_name, pixelType=itk.US)\n",
"viewer = view(image, cmap=itkwidgets.cm.GBBr, annotations=False)\n",
"viewer"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "75580566edd8429f9a622b37a925403c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VideoRecorder(autosave=True, filename='widget_video.webm', stream=Viewer(annotations=False, cmap='GBBr', gradi…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"recorder = webrtc.VideoRecorder(stream=viewer, filename='widget_video.webm', autosave=True)\n",
"recorder"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In addition to recording, playing back, and downloading videos (shown above), it is possible to take and save screenshots."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5b8952da189d41be93f5949d1527e3f4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"ImageRecorder(autosave=True, filename='widget_image', image=Image(value=b''), stream=Viewer(annotations=False,…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"image_recorder = webrtc.ImageRecorder(stream=viewer, filename='widget_image', autosave=True)\n",
"image_recorder"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"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