segauge 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- segauge-0.1.0/.github/workflows/ci.yml +28 -0
- segauge-0.1.0/.github/workflows/docs.yml +22 -0
- segauge-0.1.0/.gitignore +29 -0
- segauge-0.1.0/CITATION.cff +18 -0
- segauge-0.1.0/LICENSE +201 -0
- segauge-0.1.0/PKG-INFO +117 -0
- segauge-0.1.0/README.md +85 -0
- segauge-0.1.0/benchmarks/mesh_vs_grid.py +65 -0
- segauge-0.1.0/docs/api.md +23 -0
- segauge-0.1.0/docs/compute-hd95-in-python.md +37 -0
- segauge-0.1.0/docs/confidence-intervals.md +39 -0
- segauge-0.1.0/docs/evaluate-dicom-seg.md +44 -0
- segauge-0.1.0/docs/index.md +33 -0
- segauge-0.1.0/docs/normalized-surface-dice-nsd.md +30 -0
- segauge-0.1.0/docs/per-lesion-detection-f1.md +29 -0
- segauge-0.1.0/docs/quickstart.md +54 -0
- segauge-0.1.0/docs/vs-monai-metrics-reloaded.md +33 -0
- segauge-0.1.0/examples/evaluate_nifti.py +40 -0
- segauge-0.1.0/examples/single_pair.py +33 -0
- segauge-0.1.0/mkdocs.yml +55 -0
- segauge-0.1.0/pyproject.toml +99 -0
- segauge-0.1.0/src/segauge/__init__.py +56 -0
- segauge-0.1.0/src/segauge/cli.py +170 -0
- segauge-0.1.0/src/segauge/core.py +189 -0
- segauge-0.1.0/src/segauge/io.py +161 -0
- segauge-0.1.0/src/segauge/metrics/__init__.py +27 -0
- segauge-0.1.0/src/segauge/metrics/detection.py +110 -0
- segauge-0.1.0/src/segauge/metrics/distance.py +245 -0
- segauge-0.1.0/src/segauge/metrics/overlap.py +52 -0
- segauge-0.1.0/src/segauge/report.py +162 -0
- segauge-0.1.0/src/segauge/stats.py +65 -0
- segauge-0.1.0/src/segauge/types.py +15 -0
- segauge-0.1.0/tests/conftest.py +30 -0
- segauge-0.1.0/tests/data/README.md +11 -0
- segauge-0.1.0/tests/data/seg_image_ct_binary.dcm +0 -0
- segauge-0.1.0/tests/test_cli.py +88 -0
- segauge-0.1.0/tests/test_core.py +65 -0
- segauge-0.1.0/tests/test_detection.py +65 -0
- segauge-0.1.0/tests/test_dicom.py +99 -0
- segauge-0.1.0/tests/test_distance.py +84 -0
- segauge-0.1.0/tests/test_io.py +48 -0
- segauge-0.1.0/tests/test_oracle.py +71 -0
- segauge-0.1.0/tests/test_overlap.py +58 -0
- segauge-0.1.0/tests/test_report.py +20 -0
- segauge-0.1.0/tests/test_stats.py +51 -0
- segauge-0.1.0/uv.lock +1916 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- name: Install uv
|
|
18
|
+
uses: astral-sh/setup-uv@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python-version }}
|
|
21
|
+
- name: Sync dependencies
|
|
22
|
+
run: uv sync --extra dicom
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: |
|
|
25
|
+
uv run ruff check .
|
|
26
|
+
uv run ruff format --check .
|
|
27
|
+
- name: Test
|
|
28
|
+
run: uv run pytest -q
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
- name: Build and deploy docs
|
|
20
|
+
run: |
|
|
21
|
+
uv sync --group docs
|
|
22
|
+
uv run mkdocs gh-deploy --force
|
segauge-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
|
|
11
|
+
# Tooling
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.coverage
|
|
16
|
+
htmlcov/
|
|
17
|
+
coverage.xml
|
|
18
|
+
|
|
19
|
+
# Editors / OS
|
|
20
|
+
.vscode/
|
|
21
|
+
.idea/
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Local artifacts
|
|
25
|
+
*.html
|
|
26
|
+
!src/segauge/report/templates/*.html
|
|
27
|
+
scratch/
|
|
28
|
+
tasks/
|
|
29
|
+
site/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use segauge in your research, please cite it."
|
|
3
|
+
title: "segauge: geometrically-correct, DICOM-native evaluation metrics for medical image segmentation"
|
|
4
|
+
authors:
|
|
5
|
+
- family-names: Haisma
|
|
6
|
+
given-names: Ruben
|
|
7
|
+
type: software
|
|
8
|
+
license: Apache-2.0
|
|
9
|
+
repository-code: "https://github.com/RubenHaisma/segauge"
|
|
10
|
+
url: "https://rubenhaisma.github.io/segauge/"
|
|
11
|
+
keywords:
|
|
12
|
+
- medical image segmentation
|
|
13
|
+
- evaluation metrics
|
|
14
|
+
- Hausdorff distance
|
|
15
|
+
- HD95
|
|
16
|
+
- normalized surface dice
|
|
17
|
+
- DICOM
|
|
18
|
+
- Python
|
segauge-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ruben Haisma
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
segauge-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: segauge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The honest, geometrically-correct, DICOM-native evaluation harness for medical image segmentation.
|
|
5
|
+
Project-URL: Homepage, https://github.com/RubenHaisma/segauge
|
|
6
|
+
Project-URL: Repository, https://github.com/RubenHaisma/segauge
|
|
7
|
+
Project-URL: Issues, https://github.com/RubenHaisma/segauge/issues
|
|
8
|
+
Author: Ruben Haisma
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: assd,computer-vision,confidence-interval,dice,dicom,dicom-seg,evaluation,hausdorff,hd95,image-segmentation,iou,jaccard,medical-image-analysis,medical-imaging,metrics,monai,nifti,nnunet,nsd,radiology,rtstruct,segmentation,surface-dice,surface-distance,totalsegmentator
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: jinja2>=3.1
|
|
21
|
+
Requires-Dist: nibabel>=5.0
|
|
22
|
+
Requires-Dist: numpy>=1.24
|
|
23
|
+
Requires-Dist: rtree>=1.0
|
|
24
|
+
Requires-Dist: scikit-image>=0.21
|
|
25
|
+
Requires-Dist: scipy>=1.10
|
|
26
|
+
Requires-Dist: trimesh>=4.0
|
|
27
|
+
Provides-Extra: dicom
|
|
28
|
+
Requires-Dist: highdicom>=0.22; extra == 'dicom'
|
|
29
|
+
Requires-Dist: pydicom>=2.4; extra == 'dicom'
|
|
30
|
+
Requires-Dist: rt-utils>=1.2; extra == 'dicom'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# segauge
|
|
34
|
+
|
|
35
|
+
**DICOM-native evaluation for medical image segmentation: surface-mesh distance metrics, per-lesion detection, fairness slices, and a confidence interval on every number.**
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/segauge/)
|
|
38
|
+
[](https://pypi.org/project/segauge/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
segauge computes Dice, IoU, Hausdorff distance (HD), **HD95**, average symmetric surface distance (**ASSD**), **Normalized Surface Dice (NSD)**, and **per-lesion detection F1** for 3D medical image segmentation, and puts a **bootstrap confidence interval** on every number. It reads **NIfTI, DICOM-SEG, RTSTRUCT, and NumPy** directly, so you can evaluate the output of nnU-Net, MONAI, or TotalSegmentator without a lossy conversion.
|
|
42
|
+
|
|
43
|
+
It exists because the metrics you report should be the metrics that are true, and today they often aren't.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install segauge
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import segauge as sg
|
|
51
|
+
|
|
52
|
+
result = sg.evaluate([
|
|
53
|
+
sg.Case("patient_001", pred="pred.nii.gz", gt="gt.nii.gz", metadata={"scanner": "siemens"}),
|
|
54
|
+
sg.Case("patient_002", pred="pred2.dcm", gt="gt2.dcm", metadata={"scanner": "ge"}),
|
|
55
|
+
])
|
|
56
|
+
|
|
57
|
+
print(result.summary()) # every metric with a 95% CI
|
|
58
|
+
print(result.by_subgroup("scanner")) # where does the model quietly fail?
|
|
59
|
+
result.to_html("report.html") # one self-contained report
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or from the command line:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
segauge eval --pred preds/ --gt labels/ --metadata cases.csv --report report.html
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Why not just use MONAI or Metrics Reloaded?
|
|
69
|
+
|
|
70
|
+
segauge bundles four things no incumbent provides together: a **confidence interval** on every metric, **per-lesion detection**, **subgroup/fairness slicing**, and **native DICOM-SEG/RTSTRUCT** input.
|
|
71
|
+
|
|
72
|
+
It also computes distance metrics on a surface mesh rather than the voxel grid: it extracts the object surface with marching cubes **at true voxel spacing** and integrates over the surface, following the [MeshMetrics](https://arxiv.org/abs/2509.05670) method (Podobnik & Vrtovec, 2025). In our own benchmark (`benchmarks/mesh_vs_grid.py`) this measurably reduces **HD95** error under anisotropic, thick-slice spacing, where grid rasterization hurts most; for mean distance (ASSD) on smooth shapes the two methods are comparable. A formal validation suite against the MeshMetrics reference is in progress; we report what the benchmark shows, not more.
|
|
73
|
+
|
|
74
|
+
| | segauge | MONAI | Metrics Reloaded | seg-metrics | DeepMind surface-distance |
|
|
75
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
76
|
+
| Surface-mesh distances (vs voxel grid) | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
77
|
+
| Confidence intervals | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
78
|
+
| Per-lesion detection F1 | ✅ | partial | ✅ | ❌ | ❌ |
|
|
79
|
+
| Subgroup / fairness slicing | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
80
|
+
| DICOM-SEG / RTSTRUCT native | ✅ | partial | ❌ | ❌ | ❌ |
|
|
81
|
+
| `pip install` | ✅ | ✅ | ❌ | ✅ | ✅ |
|
|
82
|
+
|
|
83
|
+
## Metrics
|
|
84
|
+
|
|
85
|
+
- **Overlap:** Dice (DSC), IoU (Jaccard) — exact, integer-counted.
|
|
86
|
+
- **Surface distance:** Hausdorff (HD), HD95, ASSD, MASD, Normalized Surface Dice (NSD) — mesh-based, spacing-aware, area-weighted.
|
|
87
|
+
- **Per-lesion detection:** precision, recall, F1 via connected-component matching, so you can answer "did it find the tumor?" not just "how much voxel overlap?"
|
|
88
|
+
- Every aggregate carries a deterministic **bootstrap confidence interval**.
|
|
89
|
+
|
|
90
|
+
## Inputs
|
|
91
|
+
|
|
92
|
+
NIfTI (`.nii`, `.nii.gz`), DICOM-SEG, RTSTRUCT, NumPy arrays, and `.npy`. Voxel spacing is read from the file header and used for the distance metrics, so a segmentation from a clinical pipeline is evaluated as-is.
|
|
93
|
+
|
|
94
|
+
## FAQ
|
|
95
|
+
|
|
96
|
+
**How do I compute HD95 correctly in Python?** `segauge.surface_metrics(pred, gt, spacing)` returns HD, HD95, ASSD, MASD, and NSD computed on the surface mesh, not the voxel grid.
|
|
97
|
+
|
|
98
|
+
**Can it evaluate DICOM-SEG / RTSTRUCT directly?** Yes. `pip install segauge[dicom]` and pass a `.dcm` SEG, or use `segauge.load_rtstruct(series_dir, rtstruct, roi_name)`.
|
|
99
|
+
|
|
100
|
+
**Does it work with nnU-Net / TotalSegmentator / MONAI outputs?** Yes. Point it at the NIfTI (or DICOM) they produce.
|
|
101
|
+
|
|
102
|
+
**Why a confidence interval?** A Dice of 0.85 on 12 cases is not the same claim as 0.85 on 1200. segauge makes the difference visible.
|
|
103
|
+
|
|
104
|
+
**2D images?** Overlap and detection metrics work in any dimension; surface-distance metrics are 3D in v0.1 (2D is planned for v0.2).
|
|
105
|
+
|
|
106
|
+
## Status
|
|
107
|
+
|
|
108
|
+
Pre-release (`0.1.0.dev`), built in the open. segauge is an evaluation tool for developers and researchers. It is **not a medical device** and produces no diagnosis.
|
|
109
|
+
|
|
110
|
+
## References
|
|
111
|
+
|
|
112
|
+
- Maier-Hein, Reinke et al. *Metrics Reloaded.* Nature Methods (2024). https://www.nature.com/articles/s41592-023-02151-z
|
|
113
|
+
- Podobnik & Vrtovec. *MeshMetrics.* arXiv:2509.05670 (2025). https://arxiv.org/abs/2509.05670
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
Apache-2.0.
|
segauge-0.1.0/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# segauge
|
|
2
|
+
|
|
3
|
+
**DICOM-native evaluation for medical image segmentation: surface-mesh distance metrics, per-lesion detection, fairness slices, and a confidence interval on every number.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/segauge/)
|
|
6
|
+
[](https://pypi.org/project/segauge/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
segauge computes Dice, IoU, Hausdorff distance (HD), **HD95**, average symmetric surface distance (**ASSD**), **Normalized Surface Dice (NSD)**, and **per-lesion detection F1** for 3D medical image segmentation, and puts a **bootstrap confidence interval** on every number. It reads **NIfTI, DICOM-SEG, RTSTRUCT, and NumPy** directly, so you can evaluate the output of nnU-Net, MONAI, or TotalSegmentator without a lossy conversion.
|
|
10
|
+
|
|
11
|
+
It exists because the metrics you report should be the metrics that are true, and today they often aren't.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install segauge
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import segauge as sg
|
|
19
|
+
|
|
20
|
+
result = sg.evaluate([
|
|
21
|
+
sg.Case("patient_001", pred="pred.nii.gz", gt="gt.nii.gz", metadata={"scanner": "siemens"}),
|
|
22
|
+
sg.Case("patient_002", pred="pred2.dcm", gt="gt2.dcm", metadata={"scanner": "ge"}),
|
|
23
|
+
])
|
|
24
|
+
|
|
25
|
+
print(result.summary()) # every metric with a 95% CI
|
|
26
|
+
print(result.by_subgroup("scanner")) # where does the model quietly fail?
|
|
27
|
+
result.to_html("report.html") # one self-contained report
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or from the command line:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
segauge eval --pred preds/ --gt labels/ --metadata cases.csv --report report.html
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Why not just use MONAI or Metrics Reloaded?
|
|
37
|
+
|
|
38
|
+
segauge bundles four things no incumbent provides together: a **confidence interval** on every metric, **per-lesion detection**, **subgroup/fairness slicing**, and **native DICOM-SEG/RTSTRUCT** input.
|
|
39
|
+
|
|
40
|
+
It also computes distance metrics on a surface mesh rather than the voxel grid: it extracts the object surface with marching cubes **at true voxel spacing** and integrates over the surface, following the [MeshMetrics](https://arxiv.org/abs/2509.05670) method (Podobnik & Vrtovec, 2025). In our own benchmark (`benchmarks/mesh_vs_grid.py`) this measurably reduces **HD95** error under anisotropic, thick-slice spacing, where grid rasterization hurts most; for mean distance (ASSD) on smooth shapes the two methods are comparable. A formal validation suite against the MeshMetrics reference is in progress; we report what the benchmark shows, not more.
|
|
41
|
+
|
|
42
|
+
| | segauge | MONAI | Metrics Reloaded | seg-metrics | DeepMind surface-distance |
|
|
43
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
44
|
+
| Surface-mesh distances (vs voxel grid) | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
45
|
+
| Confidence intervals | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
46
|
+
| Per-lesion detection F1 | ✅ | partial | ✅ | ❌ | ❌ |
|
|
47
|
+
| Subgroup / fairness slicing | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
48
|
+
| DICOM-SEG / RTSTRUCT native | ✅ | partial | ❌ | ❌ | ❌ |
|
|
49
|
+
| `pip install` | ✅ | ✅ | ❌ | ✅ | ✅ |
|
|
50
|
+
|
|
51
|
+
## Metrics
|
|
52
|
+
|
|
53
|
+
- **Overlap:** Dice (DSC), IoU (Jaccard) — exact, integer-counted.
|
|
54
|
+
- **Surface distance:** Hausdorff (HD), HD95, ASSD, MASD, Normalized Surface Dice (NSD) — mesh-based, spacing-aware, area-weighted.
|
|
55
|
+
- **Per-lesion detection:** precision, recall, F1 via connected-component matching, so you can answer "did it find the tumor?" not just "how much voxel overlap?"
|
|
56
|
+
- Every aggregate carries a deterministic **bootstrap confidence interval**.
|
|
57
|
+
|
|
58
|
+
## Inputs
|
|
59
|
+
|
|
60
|
+
NIfTI (`.nii`, `.nii.gz`), DICOM-SEG, RTSTRUCT, NumPy arrays, and `.npy`. Voxel spacing is read from the file header and used for the distance metrics, so a segmentation from a clinical pipeline is evaluated as-is.
|
|
61
|
+
|
|
62
|
+
## FAQ
|
|
63
|
+
|
|
64
|
+
**How do I compute HD95 correctly in Python?** `segauge.surface_metrics(pred, gt, spacing)` returns HD, HD95, ASSD, MASD, and NSD computed on the surface mesh, not the voxel grid.
|
|
65
|
+
|
|
66
|
+
**Can it evaluate DICOM-SEG / RTSTRUCT directly?** Yes. `pip install segauge[dicom]` and pass a `.dcm` SEG, or use `segauge.load_rtstruct(series_dir, rtstruct, roi_name)`.
|
|
67
|
+
|
|
68
|
+
**Does it work with nnU-Net / TotalSegmentator / MONAI outputs?** Yes. Point it at the NIfTI (or DICOM) they produce.
|
|
69
|
+
|
|
70
|
+
**Why a confidence interval?** A Dice of 0.85 on 12 cases is not the same claim as 0.85 on 1200. segauge makes the difference visible.
|
|
71
|
+
|
|
72
|
+
**2D images?** Overlap and detection metrics work in any dimension; surface-distance metrics are 3D in v0.1 (2D is planned for v0.2).
|
|
73
|
+
|
|
74
|
+
## Status
|
|
75
|
+
|
|
76
|
+
Pre-release (`0.1.0.dev`), built in the open. segauge is an evaluation tool for developers and researchers. It is **not a medical device** and produces no diagnosis.
|
|
77
|
+
|
|
78
|
+
## References
|
|
79
|
+
|
|
80
|
+
- Maier-Hein, Reinke et al. *Metrics Reloaded.* Nature Methods (2024). https://www.nature.com/articles/s41592-023-02151-z
|
|
81
|
+
- Podobnik & Vrtovec. *MeshMetrics.* arXiv:2509.05670 (2025). https://arxiv.org/abs/2509.05670
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
Apache-2.0.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Mesh-correct vs grid-based surface distance: the thesis, with numbers.
|
|
2
|
+
|
|
3
|
+
Grid-based tools (MONAI, seg-metrics, pymia, MedPy, DeepMind surface-distance)
|
|
4
|
+
measure distances between voxel surfaces. segauge measures them on a marching-
|
|
5
|
+
cubes surface mesh at true spacing. On geometry with a *known* answer, the gap
|
|
6
|
+
shows up, and it widens with anisotropic spacing, exactly where it matters
|
|
7
|
+
clinically (thick-slice CT/MR).
|
|
8
|
+
|
|
9
|
+
Run: uv run python benchmarks/mesh_vs_grid.py
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
from scipy import ndimage
|
|
16
|
+
|
|
17
|
+
from segauge.metrics.distance import surface_metrics
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def sphere(shape, center, radius, spacing):
|
|
21
|
+
grids = np.ogrid[tuple(slice(0, s) for s in shape)]
|
|
22
|
+
dist2 = sum(
|
|
23
|
+
((g - c) * sp) ** 2 for g, c, sp in zip(grids, center, spacing, strict=True)
|
|
24
|
+
)
|
|
25
|
+
return dist2 <= radius**2
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _surface(mask):
|
|
29
|
+
return mask & ~ndimage.binary_erosion(mask)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def grid_metrics(pred, gt, spacing, tol):
|
|
33
|
+
"""Classic grid surface-distance, the way incumbent tools compute it."""
|
|
34
|
+
sa, sb = _surface(pred), _surface(gt)
|
|
35
|
+
dt_to_b = ndimage.distance_transform_edt(~sb, sampling=spacing)
|
|
36
|
+
dt_to_a = ndimage.distance_transform_edt(~sa, sampling=spacing)
|
|
37
|
+
d_ab, d_ba = dt_to_b[sa], dt_to_a[sb]
|
|
38
|
+
allv = np.concatenate([d_ab, d_ba])
|
|
39
|
+
nsd = ((d_ab <= tol).sum() + (d_ba <= tol).sum()) / (len(d_ab) + len(d_ba))
|
|
40
|
+
return {
|
|
41
|
+
"hd95": float(np.percentile(allv, 95)),
|
|
42
|
+
"assd": float(allv.mean()),
|
|
43
|
+
"nsd": float(nsd),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def run(label, shape, spacing, r_inner, r_outer):
|
|
48
|
+
center = tuple(s / 2 for s in shape)
|
|
49
|
+
inner = sphere(shape, center, r_inner, spacing)
|
|
50
|
+
outer = sphere(shape, center, r_outer, spacing)
|
|
51
|
+
truth = r_outer - r_inner # true symmetric surface distance, in physical units
|
|
52
|
+
mesh = surface_metrics(inner, outer, spacing=spacing, nsd_tolerance=1.0)
|
|
53
|
+
grid = grid_metrics(inner, outer, spacing, tol=1.0)
|
|
54
|
+
print(f"\n{label} (spacing {spacing}, true ASSD = {truth:.1f})")
|
|
55
|
+
print(f" {'metric':6} {'mesh':>10} {'grid':>10} {'truth':>10}")
|
|
56
|
+
for m, t in [("assd", truth), ("hd95", truth)]:
|
|
57
|
+
print(f" {m:6} {mesh[m]:>10.3f} {grid[m]:>10.3f} {t:>10.3f}")
|
|
58
|
+
err_mesh = abs(mesh["assd"] - truth)
|
|
59
|
+
err_grid = abs(grid["assd"] - truth)
|
|
60
|
+
print(f" ASSD abs error: mesh {err_mesh:.3f} vs grid {err_grid:.3f}")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
run("isotropic 1mm", (90, 90, 90), (1.0, 1.0, 1.0), 30, 33)
|
|
65
|
+
run("anisotropic 1x1x3mm", (90, 90, 34), (1.0, 1.0, 3.0), 30, 33)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
## Top-level
|
|
4
|
+
|
|
5
|
+
::: segauge.evaluate
|
|
6
|
+
|
|
7
|
+
::: segauge.Case
|
|
8
|
+
|
|
9
|
+
::: segauge.surface_metrics
|
|
10
|
+
|
|
11
|
+
::: segauge.dice
|
|
12
|
+
|
|
13
|
+
::: segauge.iou
|
|
14
|
+
|
|
15
|
+
::: segauge.detection_scores
|
|
16
|
+
|
|
17
|
+
::: segauge.bootstrap_ci
|
|
18
|
+
|
|
19
|
+
## Loaders
|
|
20
|
+
|
|
21
|
+
::: segauge.load_mask
|
|
22
|
+
|
|
23
|
+
::: segauge.load_rtstruct
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# How to compute HD95 (95th-percentile Hausdorff distance) in Python
|
|
2
|
+
|
|
3
|
+
**HD95** is the 95th percentile of the symmetric surface distances between a predicted and a ground-truth segmentation. It is preferred over the maximum Hausdorff distance (HD) because it is far less sensitive to a single outlier voxel, which is why Metrics Reloaded recommends it for most segmentation tasks.
|
|
4
|
+
|
|
5
|
+
With segauge:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import segauge as sg
|
|
9
|
+
|
|
10
|
+
metrics = sg.surface_metrics(pred_mask, gt_mask, spacing=(1.0, 1.0, 3.0))
|
|
11
|
+
print(metrics["hd95"]) # 95th-percentile Hausdorff distance, in mm
|
|
12
|
+
print(metrics["hd"]) # maximum Hausdorff distance
|
|
13
|
+
print(metrics["assd"]) # average symmetric surface distance
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`pred_mask` and `gt_mask` are boolean (or 0/1) 3D NumPy arrays. `spacing` is the physical voxel size in the same axis order as the arrays; it matters, because HD95 is a physical distance.
|
|
17
|
+
|
|
18
|
+
## Why segauge's HD95 is different
|
|
19
|
+
|
|
20
|
+
Most libraries compute Hausdorff distance on the **voxel grid**: they take the surface voxels and measure distances between voxel centres. That bakes in discretization error, which is largest for thick-slice (anisotropic) data.
|
|
21
|
+
|
|
22
|
+
segauge extracts the object surface with marching cubes at the true voxel spacing and measures distances over that surface, following the [MeshMetrics](https://arxiv.org/abs/2509.05670) method. In benchmarking on data with a known answer, this reduces HD95 error under anisotropic spacing.
|
|
23
|
+
|
|
24
|
+
## From files (NIfTI / DICOM-SEG)
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import segauge as sg
|
|
28
|
+
|
|
29
|
+
result = sg.evaluate([sg.Case("p1", pred="pred.nii.gz", gt="gt.nii.gz")])
|
|
30
|
+
print(result.summary()["hd95"]) # HD95 with a bootstrap confidence interval
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Confidence intervals
|
|
34
|
+
|
|
35
|
+
When you evaluate more than one case, every metric (including HD95) comes back with a [bootstrap confidence interval](confidence-intervals.md), so you can report HD95 honestly.
|
|
36
|
+
|
|
37
|
+
See also: [Normalized Surface Dice](normalized-surface-dice-nsd.md), [the API reference](api.md).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Segmentation Dice (and HD95) with confidence intervals
|
|
2
|
+
|
|
3
|
+
A mean Dice of 0.85 over 12 cases is a very different claim from 0.85 over 1200 cases, but papers usually report just the number. segauge attaches a **bootstrap confidence interval** to every aggregate metric so the reader can tell the difference, and so you can report results honestly.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
import segauge as sg
|
|
7
|
+
|
|
8
|
+
result = sg.evaluate([
|
|
9
|
+
sg.Case("p1", pred="p1.nii.gz", gt="g1.nii.gz"),
|
|
10
|
+
sg.Case("p2", pred="p2.nii.gz", gt="g2.nii.gz"),
|
|
11
|
+
# ...
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
for name, est in result.summary().items():
|
|
15
|
+
print(f"{name}: {est.value:.3f} [{est.ci_low:.3f}, {est.ci_high:.3f}]")
|
|
16
|
+
# dice: 0.910 [0.882, 0.937]
|
|
17
|
+
# hd95: 3.20 [2.10, 4.80]
|
|
18
|
+
# ...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Every metric, Dice and IoU and HD95 and ASSD and NSD and detection F1, comes with a 95% interval. The interval is **deterministic** given a seed, because a tool you trust to report results must be reproducible.
|
|
22
|
+
|
|
23
|
+
## Confidence interval for your own values
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import segauge as sg
|
|
27
|
+
|
|
28
|
+
per_case_dice = [0.88, 0.91, 0.79, 0.93, 0.85]
|
|
29
|
+
est = sg.bootstrap_ci(per_case_dice)
|
|
30
|
+
print(est) # 0.872 [0.812, 0.918]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configure it
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
result = sg.evaluate(cases, confidence=0.95, n_resamples=2000, seed=0)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
See also: [Per-lesion detection F1](per-lesion-detection-f1.md), [the API reference](api.md).
|