Skip to content

Commit fba096b

Browse files
committed
DOC: Add LabelMap example
1 parent 4dcff8c commit fba096b

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

examples/LabelMap.ipynb

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Requirement already satisfied: itk-io in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (5.1.0.post1)\r\n",
13+
"Requirement already satisfied: itk-core==5.1.0.post1 in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (from itk-io) (5.1.0.post1)\r\n"
14+
]
15+
}
16+
],
17+
"source": [
18+
"# Install dependencies for this example\n",
19+
"# Note: This does not include itkwidgets, itself\n",
20+
"import sys\n",
21+
"!{sys.executable} -m pip install itk-io"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 2,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"from urllib.request import urlretrieve\n",
31+
"import os\n",
32+
"\n",
33+
"import itk\n",
34+
"\n",
35+
"from itkwidgets import view\n",
36+
"import itkwidgets"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 3,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"# Download data\n",
46+
"image_file_name = 'cells.nrrd'\n",
47+
"if not os.path.exists(image_file_name):\n",
48+
" url = 'https://data.kitware.com/api/v1/file/5ecc803b9014a6d84e8ac8e2/download'\n",
49+
" urlretrieve(url, image_file_name)\n",
50+
"label_map_file_name = 'cell_labels.nrrd'\n",
51+
"if not os.path.exists(label_map_file_name):\n",
52+
" url = 'https://data.kitware.com/api/v1/file/5ecc803c9014a6d84e8ac8ea/download'\n",
53+
" urlretrieve(url, label_map_file_name)"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 4,
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"image = itk.imread(image_file_name)\n",
63+
"label_map = itk.imread(label_map_file_name)"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": 6,
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"data": {
73+
"application/vnd.jupyter.widget-view+json": {
74+
"model_id": "7416595a86114b29b9cdd40676af0e84",
75+
"version_major": 2,
76+
"version_minor": 0
77+
},
78+
"text/plain": [
79+
"Viewer(cmap='Grayscale', geometries=[], gradient_opacity=0.8, interpolation=False, point_sets=[], rendered_ima…"
80+
]
81+
},
82+
"metadata": {},
83+
"output_type": "display_data"
84+
}
85+
],
86+
"source": [
87+
"view(image, label_map=label_map, rotate=True, gradient_opacity=0.8)"
88+
]
89+
}
90+
],
91+
"metadata": {
92+
"kernelspec": {
93+
"display_name": "Python 3",
94+
"language": "python",
95+
"name": "python3"
96+
},
97+
"language_info": {
98+
"codemirror_mode": {
99+
"name": "ipython",
100+
"version": 3
101+
},
102+
"file_extension": ".py",
103+
"mimetype": "text/x-python",
104+
"name": "python",
105+
"nbconvert_exporter": "python",
106+
"pygments_lexer": "ipython3",
107+
"version": "3.7.6"
108+
}
109+
},
110+
"nbformat": 4,
111+
"nbformat_minor": 4
112+
}

0 commit comments

Comments
 (0)