|
101 | 101 | }, |
102 | 102 | { |
103 | 103 | "cell_type": "code", |
104 | | - "execution_count": 3, |
| 104 | + "execution_count": 2, |
105 | 105 | "metadata": { |
106 | 106 | "id": "cxVnoqqEYd6F" |
107 | 107 | }, |
|
125 | 125 | }, |
126 | 126 | { |
127 | 127 | "cell_type": "code", |
128 | | - "execution_count": 4, |
| 128 | + "execution_count": null, |
129 | 129 | "metadata": { |
130 | 130 | "id": "E3lZFPFNYiSK" |
131 | 131 | }, |
132 | 132 | "outputs": [], |
133 | 133 | "source": [ |
134 | | - "gt = sitk.ReadImage(\"patients_26_ground_truth.nii.gz\", sitk.sitkUInt8)\n", |
135 | | - "pred = sitk.ReadImage(\"patients_26_segmentation.nii.gz\", sitk.sitkUInt8)\n", |
| 134 | + "gt = sitk.ReadImage(rf\"patients_26_ground_truth.nii.gz\", sitk.sitkUInt8)\n", |
| 135 | + "pred = sitk.ReadImage(rf\"patients_26_segmentation.nii.gz\", sitk.sitkUInt8)\n", |
136 | 136 | "\n", |
137 | 137 | "gt_arr = sitk.GetArrayFromImage(gt)\n", |
138 | 138 | "pred_arr = sitk.GetArrayFromImage(pred)\n", |
|
154 | 154 | }, |
155 | 155 | { |
156 | 156 | "cell_type": "code", |
157 | | - "execution_count": 8, |
| 157 | + "execution_count": 13, |
158 | 158 | "metadata": { |
159 | 159 | "colab": { |
160 | 160 | "base_uri": "https://localhost:8080/" |
|
167 | 167 | "name": "stdout", |
168 | 168 | "output_type": "stream", |
169 | 169 | "text": [ |
170 | | - "Mikan cost 0.12 s.\n", |
171 | | - "medpy costs 0.19 s.\n", |
172 | | - "DSC: 1.54x faster\n" |
| 170 | + "Mikan cost 0.03 s.\n", |
| 171 | + "medpy costs 0.27 s.\n", |
| 172 | + "DSC: 8.05x faster\n" |
173 | 173 | ] |
174 | 174 | } |
175 | 175 | ], |
|
201 | 201 | }, |
202 | 202 | { |
203 | 203 | "cell_type": "code", |
204 | | - "execution_count": 9, |
| 204 | + "execution_count": 10, |
205 | 205 | "metadata": { |
206 | 206 | "colab": { |
207 | 207 | "base_uri": "https://localhost:8080/" |
|
214 | 214 | "name": "stdout", |
215 | 215 | "output_type": "stream", |
216 | 216 | "text": [ |
217 | | - "Mikan has calculated Hausdorff distance and cost 4.47 s.\n", |
| 217 | + "[3.8066796490554484, 5.875891921349948, 7.18959419428273, 55.03783156368531, 46.23897571237574]\n", |
| 218 | + "Mikan has calculated Hausdorff distance and cost 0.93 s.\n", |
218 | 219 | "Let's waiting for medpy, be patient for a while...\n", |
219 | | - "HD: 11.14x faster\n" |
| 220 | + "46.23897571237574\n", |
| 221 | + "HD: 71.22x faster\n" |
220 | 222 | ] |
221 | 223 | } |
222 | 224 | ], |
223 | 225 | "source": [ |
224 | 226 | "# mikan: HD\n", |
225 | 227 | "t = time.time()\n", |
226 | 228 | "evaluator = mikan.ArrayEvaluator(gt_arr, pred_arr, spacing=gt.GetSpacing())\n", |
227 | | - "hausdorff_distance = evaluator.labels([1,2,3,4,5]).metrics(\"HD\")\n", |
| 229 | + "hausdorff_distance = evaluator.labels([1, 2, 3, 4, 5]).metrics(\"HD\")\n", |
| 230 | + "print(hausdorff_distance)\n", |
| 231 | + "\n", |
228 | 232 | "mikan_costs = time.time() - t\n", |
229 | 233 | "print(f\"Mikan has calculated Hausdorff distance and cost {mikan_costs:.2f} s.\")\n", |
230 | 234 | "print(f\"Let's waiting for medpy, be patient for a while...\")\n", |
231 | 235 | "\n", |
232 | 236 | "# medpy: HD\n", |
233 | 237 | "t = time.time()\n", |
234 | | - "for i in (1,2,3,4,5):\n", |
| 238 | + "for i in (1, 2, 3, 4, 5):\n", |
235 | 239 | " hausdorff_distance = hd(pred_arr == i, gt_arr == i, voxelspacing=gt.GetSpacing()[::-1])\n", |
236 | 240 | "medpy_costs = time.time() - t\n", |
237 | | - "\n", |
| 241 | + "print(hausdorff_distance)\n", |
238 | 242 | "print(f\"HD: {medpy_costs / mikan_costs :.2f}x faster\")" |
239 | 243 | ] |
240 | 244 | }, |
|
249 | 253 | }, |
250 | 254 | { |
251 | 255 | "cell_type": "code", |
252 | | - "execution_count": 10, |
| 256 | + "execution_count": 9, |
253 | 257 | "metadata": { |
254 | 258 | "colab": { |
255 | 259 | "base_uri": "https://localhost:8080/" |
|
262 | 266 | "name": "stdout", |
263 | 267 | "output_type": "stream", |
264 | 268 | "text": [ |
265 | | - "{'1': {'hd': 3.8066790103912354, 'hd95': 0.7410011291503906, 'assd': 0.24823972582817078}, '2': {'hd': 5.875893592834473, 'hd95': 0.8939142823219299, 'assd': 0.30189621448516846}, '3': {'hd': 7.1895952224731445, 'hd95': 0.7410049438476562, 'assd': 0.29092279076576233}, '4': {'hd': 55.0378303527832, 'hd95': 0.7410011291503906, 'assd': 0.2536499500274658}, '5': {'hd': 46.238975524902344, 'hd95': 0.7410125732421875, 'assd': 0.27448806166648865}}\n", |
266 | | - "Mikan has calculated distance and cost 3.80 s.\n", |
| 269 | + "{'1': {'hd': 3.8066796490554484, 'hd95': 0.7409999966621399, 'assd': 0.2482734556966591}, '2': {'hd': 5.875891921349948, 'hd95': 0.893913303991663, 'assd': 0.30188703831217684}, '3': {'hd': 7.18959419428273, 'hd95': 0.7409999966621399, 'assd': 0.29096373483885757}, '4': {'hd': 55.03783156368531, 'hd95': 0.7409999966621399, 'assd': 0.25367831066384994}, '5': {'hd': 46.23897571237574, 'hd95': 0.7409999966621399, 'assd': 0.27452537658032045}}\n", |
| 270 | + "Mikan has calculated distance and cost 0.96 s.\n", |
267 | 271 | "Let's waiting for medpy, be patient for a while...\n", |
268 | 272 | "{1: {'hd': 3.8066796490554484, 'hd95': 0.7409999966621399, 'assd': 0.24827345569665876}, 2: {'hd': 5.875891921349948, 'hd95': 0.893913303991663, 'assd': 0.3018870383121832}, 3: {'hd': 7.18959419428273, 'hd95': 0.7409999966621399, 'assd': 0.2909637348388582}, 4: {'hd': 55.03783156368531, 'hd95': 0.7409999966621399, 'assd': 0.25367831066385055}, 5: {'hd': 46.23897571237574, 'hd95': 0.7409999966621399, 'assd': 0.2745253765803193}}\n", |
269 | | - "Distances: 39.67x faster\n" |
| 273 | + "Distances: 210.35x faster\n" |
270 | 274 | ] |
271 | 275 | } |
272 | 276 | ], |
|
307 | 311 | "name": "python3" |
308 | 312 | }, |
309 | 313 | "language_info": { |
| 314 | + "codemirror_mode": { |
| 315 | + "name": "ipython", |
| 316 | + "version": 3 |
| 317 | + }, |
| 318 | + "file_extension": ".py", |
| 319 | + "mimetype": "text/x-python", |
310 | 320 | "name": "python", |
| 321 | + "nbconvert_exporter": "python", |
| 322 | + "pygments_lexer": "ipython3", |
311 | 323 | "version": "3.12.3" |
312 | 324 | } |
313 | 325 | }, |
|
0 commit comments