Skip to content

Commit 5bcdf42

Browse files
dani-lbnlthewtex
authored andcommitted
DOC: Add scikit-image example to LabelImages example
1 parent 5aab14e commit 5bcdf42

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

examples/LabelImages.ipynb

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"# Install dependencies for this example\n",
1010
"# Note: This does not include itkwidgets, itself\n",
1111
"import sys\n",
12-
"!{sys.executable} -m pip install -U itk itk-totalvariation"
12+
"!{sys.executable} -m pip install -U itk itk-totalvariation scikit-image"
1313
]
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 5,
17+
"execution_count": 1,
1818
"metadata": {},
1919
"outputs": [],
2020
"source": [
@@ -23,14 +23,15 @@
2323
"\n",
2424
"import itk\n",
2525
"import numpy as np\n",
26+
"import skimage.io, skimage.filters, skimage.measure\n",
2627
"\n",
2728
"from itkwidgets import view\n",
2829
"import itkwidgets"
2930
]
3031
},
3132
{
3233
"cell_type": "code",
33-
"execution_count": 6,
34+
"execution_count": 2,
3435
"metadata": {},
3536
"outputs": [],
3637
"source": [
@@ -44,13 +45,13 @@
4445
},
4546
{
4647
"cell_type": "code",
47-
"execution_count": 7,
48+
"execution_count": 3,
4849
"metadata": {},
4950
"outputs": [
5051
{
5152
"data": {
5253
"application/vnd.jupyter.widget-view+json": {
53-
"model_id": "530d6f97e04e4dab86bbb00ddcc799bb",
54+
"model_id": "436f06a0454f4e0abee8cbf15573015e",
5455
"version_major": 2,
5556
"version_minor": 0
5657
},
@@ -70,7 +71,7 @@
7071
},
7172
{
7273
"cell_type": "code",
73-
"execution_count": 17,
74+
"execution_count": null,
7475
"metadata": {},
7576
"outputs": [],
7677
"source": [
@@ -197,15 +198,73 @@
197198
"cell_type": "markdown",
198199
"metadata": {},
199200
"source": [
200-
"We can also combine the intensity images, weighted and blended with the label maps, with iso-surface geometry."
201+
"The images and labels can, of course, also come from *scikit-image*."
201202
]
202203
},
203204
{
204205
"cell_type": "code",
205-
"execution_count": null,
206+
"execution_count": 3,
207+
"metadata": {},
208+
"outputs": [
209+
{
210+
"data": {
211+
"application/vnd.jupyter.widget-view+json": {
212+
"model_id": "8327687db5c64422a16af110bb597b76",
213+
"version_major": 2,
214+
"version_minor": 0
215+
},
216+
"text/plain": [
217+
"Viewer(annotations=False, cmap=['BrBG'], geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<…"
218+
]
219+
},
220+
"metadata": {},
221+
"output_type": "display_data"
222+
}
223+
],
224+
"source": [
225+
"image = skimage.io.imread(file_name)\n",
226+
"\n",
227+
"view(image, cmap=itkwidgets.cm.BrBG, annotations=False, vmax=800, ui_collapsed=True)"
228+
]
229+
},
230+
{
231+
"cell_type": "code",
232+
"execution_count": 4,
206233
"metadata": {},
207234
"outputs": [],
208-
"source": []
235+
"source": [
236+
"# Segment the cells\n",
237+
"smoothed = skimage.filters.gaussian(image)\n",
238+
"\n",
239+
"threshold = skimage.filters.threshold_isodata(smoothed)\n",
240+
"thresholded = smoothed > threshold\n",
241+
"\n",
242+
"connected_components = skimage.measure.label(thresholded)"
243+
]
244+
},
245+
{
246+
"cell_type": "code",
247+
"execution_count": 5,
248+
"metadata": {},
249+
"outputs": [
250+
{
251+
"data": {
252+
"application/vnd.jupyter.widget-view+json": {
253+
"model_id": "cdc8480801bc4792b2053812febdf00f",
254+
"version_major": 2,
255+
"version_minor": 0
256+
},
257+
"text/plain": [
258+
"Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_label_image=<itk.itk…"
259+
]
260+
},
261+
"metadata": {},
262+
"output_type": "display_data"
263+
}
264+
],
265+
"source": [
266+
"view(label_image=connected_components)"
267+
]
209268
}
210269
],
211270
"metadata": {

0 commit comments

Comments
 (0)