dice-score-3d
Utility for calculating the Dice Similarity Coefficient (DSC) for 3D segmentation masks. Writes the results in a csv or json file and can be used both from the terminal or from a Python script. Calculates per-case mean Dice and weighted mean Dice, and per-label mean Dice, weighted mean Dice and Global Dice. The Global Dice for a label is the Dice Score calculated as if all the cases are concatenated into a single big case, aiming to balance out cases in which the Dice Score is 0 but have very few FP voxels or cases in which the Dice Score is 1 but have no positive voxels.
Installation
pip install --upgrade dice-score-3d
Usage
Simple usage (Python):
from dice_score_3d import dice_metrics
results_dict = dice_metrics(gt_dir, pred_dir, output_path=None, indices={'lung': 1, 'heart': 2}, suffix='.nii.gz')
# Write to csv:
dice_metrics(gt_dir, pred_dir, output_path='results.csv', indices={'lung': 1, 'heart': 2}, suffix='.nii.gz', num_workers=8)
Simple usage (terminal):
dice_score_3d GT.nii.gz PRED.nii.gz -output results.json -indices "{'lung': 1, 'heart': 2}" --console
dice_score_3d GT.nii.gz PRED.nii.gz -output results.json -indices indices.json
Complete documentation:
usage: dice_score_3d [-h] -output OUTPUT -indices INDICES [--reorient] [-dtype {uint8,uint16}] [-prefix PREFIX] [-suffix SUFFIX] [-num_workers NUM_WORKERS] [--console]
ground_truths predictions
DICE Score 3D
positional arguments:
ground_truths Path to Ground Truth. Can be a single file or a folder with all the GT volumes. The number of GT files must match the number of predictions. When passing a
folder of GT files, the name of the GT files must match the name of the predictions. This is not applicable when passing a single file. Supported file
formats: .nii, .nii.gz, .nrrd, .mha, .gipl.
predictions Path to Ground Truth. Can be a single file or a folder with all the predicted volumes. The number of prediction files must match the number of GT files. When
passing a folder of prediction files, the name of the prediction files must match the name of the GT files. This is not applicable when passing a single file.
Supported file formats: .nii, .nii.gz, .nrrd, .mha, .gipl.
options:
-h, --help show this help message and exit
-output OUTPUT The output path to write the computed metrics. Can be a csv or json file, depending on extension. Example: "results.csv", "results.json".
-indices INDICES Path to the json file describing the indices used for calculating the Dice Similarity Coefficient. Can also be a json string. Only the indices present in the
json are considered when evaluating the Dice Score. Example: "{"lung_left": 1, "lung_right": 2}".
--reorient Reorients both the GT and the prediction to the default "LPS" orientation before calculating the Dice Score.
-dtype {uint8,uint16}
Must be either "uint8" when having less than 255 classes, or "uint16" otherwise. Default: uint8.
-prefix PREFIX This parameter is used when the ground truth path is a folder. It filters all the files in the folder and selects only the files with this prefix.
-suffix SUFFIX This parameter is used when the ground truth path is a folder. It filters all the files in the folder and selects only the files with this suffix. Default: .nii.gz.
-num_workers NUM_WORKERS
Number of parallel processes to be used to calculate the Dice Score in parallel. Default: 0.
--console Also prints the Dice metrics to console.
--ignore_gt_size Allows the presence of additional GT files in the GT folder.
Metadata
Release files for dice-score-3d 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dice_score_3d-1.1.2.tar.gz | 10.2 kB | Without provenance | Details for dice_score_3d-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dice_score_3d-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for dice_score_3d-1.1.2-py3-none-any.whl |
Total release size: 20.2 kB
Release files / dice_score_3d-1.1.2.tar.gz
| Download URL | dice_score_3d-1.1.2.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c2469959a95138aa89ba31e238659031428f2263d6e7d84e4358eb5e4ddde9c
|
|
BLAKE2b-256 checksum How to use checksums |
ddb5c70ff734a37f117d4e3cfe8765d6730e9f4412c8aa1c55b38fc8e6ab0112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.24
|
Release files / dice_score_3d-1.1.2-py3-none-any.whl
| Download URL | dice_score_3d-1.1.2-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c72662601972ace4f4e708bbf017c66cababfffb8eefd8ed8e034dfc37c49d34
|
|
BLAKE2b-256 checksum How to use checksums |
60416b75c21b74d8dfae06f97b1be2a9948028f40f61b543971500c532b265f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.24
|
Security for dice-score-3d 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.