Skip to main content

Utility for calculating the Dice Similarity Coefficient (DSC) for 3D segmentation masks.

Project description

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.

Installation

pip install --upgrade dice-score-3d

Usage

Simple usage (Python):

from dice_score_3d import dice_metrics


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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dice_score_3d-1.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

dice_score_3d-1.0.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file dice_score_3d-1.0.1.tar.gz.

File metadata

  • Download URL: dice_score_3d-1.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for dice_score_3d-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e434a1a04789756023ee50ca07f700fb08caeeab61b884977f762b647048dbaf
MD5 2e977a917dca9f968bfcc64bfc0c355c
BLAKE2b-256 82ee2327093b87ce31375bad8d4898f8fb115fd992ae24d9be79b55ae044a9de

See more details on using hashes here.

File details

Details for the file dice_score_3d-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dice_score_3d-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e15e545cf81efedd7118cb5ce2a75da30ffa8592d20ba298d4f87663622f221c
MD5 834e8e516fed885edb47e231dcbc91f9
BLAKE2b-256 0bcc0b8d9989c09ada6a9e498689e3a9424cbae19c51f957ed0744c17192ec69

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page