|
9 | 9 | "# Install dependencies for this example\n", |
10 | 10 | "# Note: This does not include itkwidgets, itself\n", |
11 | 11 | "import sys\n", |
12 | | - "!{sys.executable} -m pip install -U itk itk-totalvariation" |
| 12 | + "!{sys.executable} -m pip install -U itk scikit-image" |
13 | 13 | ] |
14 | 14 | }, |
15 | 15 | { |
16 | 16 | "cell_type": "code", |
17 | | - "execution_count": 5, |
| 17 | + "execution_count": null, |
18 | 18 | "metadata": {}, |
19 | 19 | "outputs": [], |
20 | 20 | "source": [ |
|
23 | 23 | "\n", |
24 | 24 | "import itk\n", |
25 | 25 | "import numpy as np\n", |
| 26 | + "import skimage.io, skimage.filters, skimage.measure\n", |
26 | 27 | "\n", |
27 | 28 | "from itkwidgets import view\n", |
28 | 29 | "import itkwidgets" |
29 | 30 | ] |
30 | 31 | }, |
31 | 32 | { |
32 | 33 | "cell_type": "code", |
33 | | - "execution_count": 6, |
| 34 | + "execution_count": null, |
34 | 35 | "metadata": {}, |
35 | 36 | "outputs": [], |
36 | 37 | "source": [ |
|
44 | 45 | }, |
45 | 46 | { |
46 | 47 | "cell_type": "code", |
47 | | - "execution_count": 7, |
| 48 | + "execution_count": null, |
48 | 49 | "metadata": {}, |
49 | | - "outputs": [ |
50 | | - { |
51 | | - "data": { |
52 | | - "application/vnd.jupyter.widget-view+json": { |
53 | | - "model_id": "530d6f97e04e4dab86bbb00ddcc799bb", |
54 | | - "version_major": 2, |
55 | | - "version_minor": 0 |
56 | | - }, |
57 | | - "text/plain": [ |
58 | | - "Viewer(annotations=False, cmap=['BrBG'], geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=<…" |
59 | | - ] |
60 | | - }, |
61 | | - "metadata": {}, |
62 | | - "output_type": "display_data" |
63 | | - } |
64 | | - ], |
| 50 | + "outputs": [], |
65 | 51 | "source": [ |
66 | | - "image = itk.imread(file_name, itk.F)\n", |
| 52 | + "image = itk.imread(file_name)\n", |
67 | 53 | "\n", |
68 | 54 | "view(image, cmap=itkwidgets.cm.BrBG, annotations=False, vmax=800, ui_collapsed=True)" |
69 | 55 | ] |
70 | 56 | }, |
71 | 57 | { |
72 | 58 | "cell_type": "code", |
73 | | - "execution_count": 17, |
| 59 | + "execution_count": null, |
74 | 60 | "metadata": {}, |
75 | 61 | "outputs": [], |
76 | 62 | "source": [ |
77 | 63 | "# Segment the cells\n", |
78 | | - "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", |
79 | 65 | "\n", |
80 | | - "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", |
81 | 69 | "\n", |
82 | | - "threshold_filter = itk.MomentsThresholdImageFilter[type(smoothed), LabelMapType].New(smoothed)\n", |
83 | | - "threshold_filter.SetInsideValue(0)\n", |
84 | | - "threshold_filter.SetOutsideValue(1)\n", |
85 | | - "threshold_filter.Update()\n", |
86 | | - "threshold = threshold_filter.GetThreshold()\n", |
87 | | - "thresholded = threshold_filter.GetOutput()" |
88 | | - ] |
89 | | - }, |
90 | | - { |
91 | | - "cell_type": "code", |
92 | | - "execution_count": 19, |
93 | | - "metadata": {}, |
94 | | - "outputs": [ |
95 | | - { |
96 | | - "data": { |
97 | | - "application/vnd.jupyter.widget-view+json": { |
98 | | - "model_id": "69dfe9c8df3d41a889e9c7b63f114284", |
99 | | - "version_major": 2, |
100 | | - "version_minor": 0 |
101 | | - }, |
102 | | - "text/plain": [ |
103 | | - "Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_label_image=<itk.itkIm…" |
104 | | - ] |
105 | | - }, |
106 | | - "metadata": {}, |
107 | | - "output_type": "display_data" |
108 | | - } |
109 | | - ], |
110 | | - "source": [ |
111 | | - "view(label_image=thresholded)" |
| 70 | + "connected_components = itk.connected_component_image_filter(thresholded)" |
112 | 71 | ] |
113 | 72 | }, |
114 | 73 | { |
115 | 74 | "cell_type": "code", |
116 | | - "execution_count": 20, |
| 75 | + "execution_count": null, |
117 | 76 | "metadata": {}, |
118 | | - "outputs": [ |
119 | | - { |
120 | | - "data": { |
121 | | - "application/vnd.jupyter.widget-view+json": { |
122 | | - "model_id": "33c0cb1ad92241a49728735b67d1f83f", |
123 | | - "version_major": 2, |
124 | | - "version_minor": 0 |
125 | | - }, |
126 | | - "text/plain": [ |
127 | | - "Viewer(geometries=[], gradient_opacity=0.22, interpolation=False, point_sets=[], rendered_label_image=<itk.itkIm…" |
128 | | - ] |
129 | | - }, |
130 | | - "metadata": {}, |
131 | | - "output_type": "display_data" |
132 | | - } |
133 | | - ], |
| 77 | + "outputs": [], |
134 | 78 | "source": [ |
135 | | - "connected_components = itk.connected_component_image_filter(thresholded)\n", |
136 | | - "\n", |
137 | 79 | "view(label_image=connected_components)" |
138 | 80 | ] |
139 | 81 | }, |
140 | 82 | { |
141 | 83 | "cell_type": "code", |
142 | | - "execution_count": 22, |
| 84 | + "execution_count": null, |
143 | 85 | "metadata": { |
144 | 86 | "scrolled": true |
145 | 87 | }, |
146 | | - "outputs": [ |
147 | | - { |
148 | | - "data": { |
149 | | - "application/vnd.jupyter.widget-view+json": { |
150 | | - "model_id": "94c8055aff1a4cb89923c78072fa305b", |
151 | | - "version_major": 2, |
152 | | - "version_minor": 0 |
153 | | - }, |
154 | | - "text/plain": [ |
155 | | - "Viewer(geometries=[], gradient_opacity=0.5, interpolation=False, label_image_names=[(0, 'Background'), (1, 'Firs…" |
156 | | - ] |
157 | | - }, |
158 | | - "metadata": {}, |
159 | | - "output_type": "display_data" |
160 | | - } |
161 | | - ], |
| 88 | + "outputs": [], |
162 | 89 | "source": [ |
163 | 90 | "# We can combine the label map with the intensity image, add names for the labels, etc.\n", |
164 | 91 | "names = [(0, 'Background'), (1, 'First cell'), (2, 'Second cell')]\n", |
|
182 | 109 | }, |
183 | 110 | { |
184 | 111 | "cell_type": "code", |
185 | | - "execution_count": 27, |
| 112 | + "execution_count": null, |
186 | 113 | "metadata": {}, |
187 | 114 | "outputs": [], |
188 | 115 | "source": [ |
|
197 | 124 | "cell_type": "markdown", |
198 | 125 | "metadata": {}, |
199 | 126 | "source": [ |
200 | | - "We can also combine the intensity images, weighted and blended with the label maps, with iso-surface geometry." |
| 127 | + "The images and labels can, of course, also come from *scikit-image*." |
201 | 128 | ] |
202 | 129 | }, |
203 | 130 | { |
204 | 131 | "cell_type": "code", |
205 | 132 | "execution_count": null, |
206 | 133 | "metadata": {}, |
207 | 134 | "outputs": [], |
208 | | - "source": [] |
| 135 | + "source": [ |
| 136 | + "image = skimage.io.imread(file_name)\n", |
| 137 | + "\n", |
| 138 | + "view(image, cmap=itkwidgets.cm.BrBG, annotations=False, vmax=800, ui_collapsed=True)" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "# Segment the cells\n", |
| 148 | + "smoothed = skimage.filters.gaussian(image)\n", |
| 149 | + "\n", |
| 150 | + "threshold = skimage.filters.threshold_isodata(smoothed)\n", |
| 151 | + "thresholded = smoothed > threshold\n", |
| 152 | + "\n", |
| 153 | + "connected_components = skimage.measure.label(thresholded)" |
| 154 | + ] |
| 155 | + }, |
| 156 | + { |
| 157 | + "cell_type": "code", |
| 158 | + "execution_count": null, |
| 159 | + "metadata": {}, |
| 160 | + "outputs": [], |
| 161 | + "source": [ |
| 162 | + "view(label_image=connected_components)" |
| 163 | + ] |
209 | 164 | } |
210 | 165 | ], |
211 | 166 | "metadata": { |
|
0 commit comments