Skip to content

Commit 04b13c0

Browse files
committed
DOC: Simplify ITK LabelImages segmentation
Keep it the same as the scikit-image segmentation for clarity.
1 parent 5bcdf42 commit 04b13c0

File tree

1 file changed

+21
-125
lines changed

1 file changed

+21
-125
lines changed

examples/LabelImages.ipynb

Lines changed: 21 additions & 125 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 scikit-image"
12+
"!{sys.executable} -m pip install -U itk scikit-image"
1313
]
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 1,
17+
"execution_count": null,
1818
"metadata": {},
1919
"outputs": [],
2020
"source": [
@@ -31,7 +31,7 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": 2,
34+
"execution_count": null,
3535
"metadata": {},
3636
"outputs": [],
3737
"source": [
@@ -45,26 +45,11 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 3,
48+
"execution_count": null,
4949
"metadata": {},
50-
"outputs": [
51-
{
52-
"data": {
53-
"application/vnd.jupyter.widget-view+json": {
54-
"model_id": "436f06a0454f4e0abee8cbf15573015e",
55-
"version_major": 2,
56-
"version_minor": 0
57-
},
58-
"text/plain": [
59-
"Viewer(annotations=False, cmap=['BrBG'], geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<…"
60-
]
61-
},
62-
"metadata": {},
63-
"output_type": "display_data"
64-
}
65-
],
50+
"outputs": [],
6651
"source": [
67-
"image = itk.imread(file_name, itk.F)\n",
52+
"image = itk.imread(file_name)\n",
6853
"\n",
6954
"view(image, cmap=itkwidgets.cm.BrBG, annotations=False, vmax=800, ui_collapsed=True)"
7055
]
@@ -76,90 +61,31 @@
7661
"outputs": [],
7762
"source": [
7863
"# Segment the cells\n",
79-
"smoothed = itk.prox_tv_image_filter(image, weights=50, maximum_number_of_iterations=3)\n",
64+
"smoothed = itk.smoothing_recursive_gaussian_image_filter(image)\n",
8065
"\n",
81-
"LabelMapType = itk.Image[itk.UC, 3]\n",
66+
"thresholded = itk.moments_threshold_image_filter(smoothed,\n",
67+
" inside_value=0,\n",
68+
" outside_value=1)\n",
8269
"\n",
83-
"threshold_filter = itk.MomentsThresholdImageFilter[type(smoothed), LabelMapType].New(smoothed)\n",
84-
"threshold_filter.SetInsideValue(0)\n",
85-
"threshold_filter.SetOutsideValue(1)\n",
86-
"threshold_filter.Update()\n",
87-
"threshold = threshold_filter.GetThreshold()\n",
88-
"thresholded = threshold_filter.GetOutput()"
70+
"connected_components = itk.connected_component_image_filter(thresholded)"
8971
]
9072
},
9173
{
9274
"cell_type": "code",
93-
"execution_count": 19,
94-
"metadata": {},
95-
"outputs": [
96-
{
97-
"data": {
98-
"application/vnd.jupyter.widget-view+json": {
99-
"model_id": "69dfe9c8df3d41a889e9c7b63f114284",
100-
"version_major": 2,
101-
"version_minor": 0
102-
},
103-
"text/plain": [
104-
"Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_label_image=<itk.itkIm…"
105-
]
106-
},
107-
"metadata": {},
108-
"output_type": "display_data"
109-
}
110-
],
111-
"source": [
112-
"view(label_image=thresholded)"
113-
]
114-
},
115-
{
116-
"cell_type": "code",
117-
"execution_count": 20,
75+
"execution_count": null,
11876
"metadata": {},
119-
"outputs": [
120-
{
121-
"data": {
122-
"application/vnd.jupyter.widget-view+json": {
123-
"model_id": "33c0cb1ad92241a49728735b67d1f83f",
124-
"version_major": 2,
125-
"version_minor": 0
126-
},
127-
"text/plain": [
128-
"Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_label_image=<itk.itkIm…"
129-
]
130-
},
131-
"metadata": {},
132-
"output_type": "display_data"
133-
}
134-
],
77+
"outputs": [],
13578
"source": [
136-
"connected_components = itk.connected_component_image_filter(thresholded)\n",
137-
"\n",
13879
"view(label_image=connected_components)"
13980
]
14081
},
14182
{
14283
"cell_type": "code",
143-
"execution_count": 22,
84+
"execution_count": null,
14485
"metadata": {
14586
"scrolled": true
14687
},
147-
"outputs": [
148-
{
149-
"data": {
150-
"application/vnd.jupyter.widget-view+json": {
151-
"model_id": "94c8055aff1a4cb89923c78072fa305b",
152-
"version_major": 2,
153-
"version_minor": 0
154-
},
155-
"text/plain": [
156-
"Viewer(geometries=[], gradient_opacity=0.5, interpolation=False, label_image_names=[(0, 'Background'), (1, 'Firs…"
157-
]
158-
},
159-
"metadata": {},
160-
"output_type": "display_data"
161-
}
162-
],
88+
"outputs": [],
16389
"source": [
16490
"# We can combine the label map with the intensity image, add names for the labels, etc.\n",
16591
"names = [(0, 'Background'), (1, 'First cell'), (2, 'Second cell')]\n",
@@ -183,7 +109,7 @@
183109
},
184110
{
185111
"cell_type": "code",
186-
"execution_count": 27,
112+
"execution_count": null,
187113
"metadata": {},
188114
"outputs": [],
189115
"source": [
@@ -203,24 +129,9 @@
203129
},
204130
{
205131
"cell_type": "code",
206-
"execution_count": 3,
132+
"execution_count": null,
207133
"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-
],
134+
"outputs": [],
224135
"source": [
225136
"image = skimage.io.imread(file_name)\n",
226137
"\n",
@@ -229,7 +140,7 @@
229140
},
230141
{
231142
"cell_type": "code",
232-
"execution_count": 4,
143+
"execution_count": null,
233144
"metadata": {},
234145
"outputs": [],
235146
"source": [
@@ -244,24 +155,9 @@
244155
},
245156
{
246157
"cell_type": "code",
247-
"execution_count": 5,
158+
"execution_count": null,
248159
"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-
],
160+
"outputs": [],
265161
"source": [
266162
"view(label_image=connected_components)"
267163
]

0 commit comments

Comments
 (0)