Skip to content

Commit 9ead17c

Browse files
committed
fix: spacing->f64
1 parent 6fc658c commit 9ead17c

File tree

11 files changed

+302
-333
lines changed

11 files changed

+302
-333
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mikan-rs"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A medical image kit for segmentation metrics evaluation, native Rust support, and Python bindings for cross-language performance."

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A **m**edical **i**mage **k**it for segment**a**tion metrics evaluatio**n**, nat
88

99
- 🎯 **Simple**: The API is so intuitive that you can start using it immediately while reading the [documentation](https://github.com/Plasma-Blue/mikan-rs/blob/master/examples/tutorial.ipynb) in just one minute!
1010

11-
- 🧮 **Comprehensive Metrics**: Easily to compute almost all of segmentation metrics:
11+
- 🧮 **Comprehensive Metrics**: Easily to compute almost all of segmentation metrics, **results are consistent with medpy**:
1212

1313
- **Confusion Matrix Based:**
1414

@@ -28,9 +28,18 @@ A **m**edical **i**mage **k**it for segment**a**tion metrics evaluatio**n**, nat
2828

2929
## 🔨 Install
3030

31-
`cargo add mikan-rs` for rust project.
31+
For Rust projects, add the following to your `Cargo.toml`:
3232

33-
`pip install mikan-rs` for python.
33+
```toml
34+
[dependencies]
35+
mikan-rs = "*"
36+
```
37+
38+
For Python, install via pip:
39+
40+
```sh
41+
pip install mikan-rs
42+
```
3443

3544
## 🥒 Develop
3645

@@ -46,7 +55,7 @@ gt = sitk.ReadImage("gt.nii.gz", sitk.sitkUInt8)
4655
pred = sitk.ReadImage("pred.nii.gz", sitk.sitkUInt8)
4756

4857
e = mikan.Evaluator(gt, pred)
49-
e.labels(1).metrics("dice")
58+
e.labels([1, 2, 3]).metrics(["dice", "hd", "hd95", "assd"])
5059
```
5160

5261
For details, please refer to the [python examples](https://github.com/Plasma-Blue/mikan-rs/blob/master/examples/tutorial.ipynb) and [rust examples](https://github.com/Plasma-Blue/mikan-rs/blob/master/examples/tutorial.rs).
@@ -73,9 +82,9 @@ A: They are wrong. Of course, we might be wrong too. PRs to fix issues are welco
7382
Licensed under either of the following licenses, at your choice:
7483

7584
Apache License, Version 2.0
76-
(See LICENSE-APACHE or visit http://www.apache.org/licenses/LICENSE-2.0)
85+
(See LICENSE-APACHE or visit <http://www.apache.org/licenses/LICENSE-2.0>)
7786

7887
MIT License
79-
(See LICENSE-MIT or visit http://opensource.org/licenses/MIT)
88+
(See LICENSE-MIT or visit <http://opensource.org/licenses/MIT>)
8089

8190
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project, as defined by the Apache License 2.0, will be dual-licensed under the above licenses without any additional terms or conditions.

examples/benchmark.ipynb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
},
102102
{
103103
"cell_type": "code",
104-
"execution_count": 3,
104+
"execution_count": 2,
105105
"metadata": {
106106
"id": "cxVnoqqEYd6F"
107107
},
@@ -125,14 +125,14 @@
125125
},
126126
{
127127
"cell_type": "code",
128-
"execution_count": 4,
128+
"execution_count": null,
129129
"metadata": {
130130
"id": "E3lZFPFNYiSK"
131131
},
132132
"outputs": [],
133133
"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",
136136
"\n",
137137
"gt_arr = sitk.GetArrayFromImage(gt)\n",
138138
"pred_arr = sitk.GetArrayFromImage(pred)\n",
@@ -154,7 +154,7 @@
154154
},
155155
{
156156
"cell_type": "code",
157-
"execution_count": 8,
157+
"execution_count": 13,
158158
"metadata": {
159159
"colab": {
160160
"base_uri": "https://localhost:8080/"
@@ -167,9 +167,9 @@
167167
"name": "stdout",
168168
"output_type": "stream",
169169
"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"
173173
]
174174
}
175175
],
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"cell_type": "code",
204-
"execution_count": 9,
204+
"execution_count": 10,
205205
"metadata": {
206206
"colab": {
207207
"base_uri": "https://localhost:8080/"
@@ -214,27 +214,31 @@
214214
"name": "stdout",
215215
"output_type": "stream",
216216
"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",
218219
"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"
220222
]
221223
}
222224
],
223225
"source": [
224226
"# mikan: HD\n",
225227
"t = time.time()\n",
226228
"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",
228232
"mikan_costs = time.time() - t\n",
229233
"print(f\"Mikan has calculated Hausdorff distance and cost {mikan_costs:.2f} s.\")\n",
230234
"print(f\"Let's waiting for medpy, be patient for a while...\")\n",
231235
"\n",
232236
"# medpy: HD\n",
233237
"t = time.time()\n",
234-
"for i in (1,2,3,4,5):\n",
238+
"for i in (1, 2, 3, 4, 5):\n",
235239
" hausdorff_distance = hd(pred_arr == i, gt_arr == i, voxelspacing=gt.GetSpacing()[::-1])\n",
236240
"medpy_costs = time.time() - t\n",
237-
"\n",
241+
"print(hausdorff_distance)\n",
238242
"print(f\"HD: {medpy_costs / mikan_costs :.2f}x faster\")"
239243
]
240244
},
@@ -249,7 +253,7 @@
249253
},
250254
{
251255
"cell_type": "code",
252-
"execution_count": 10,
256+
"execution_count": 9,
253257
"metadata": {
254258
"colab": {
255259
"base_uri": "https://localhost:8080/"
@@ -262,11 +266,11 @@
262266
"name": "stdout",
263267
"output_type": "stream",
264268
"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",
267271
"Let's waiting for medpy, be patient for a while...\n",
268272
"{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"
270274
]
271275
}
272276
],
@@ -307,7 +311,15 @@
307311
"name": "python3"
308312
},
309313
"language_info": {
314+
"codemirror_mode": {
315+
"name": "ipython",
316+
"version": 3
317+
},
318+
"file_extension": ".py",
319+
"mimetype": "text/x-python",
310320
"name": "python",
321+
"nbconvert_exporter": "python",
322+
"pygments_lexer": "ipython3",
311323
"version": "3.12.3"
312324
}
313325
},

0 commit comments

Comments
 (0)