dice¶
tiatoolbox.utils.metrics.dice
- dice(gt_mask, pred_mask)[source]¶
Compute the Sørensen-Dice coefficient.
This function computes Sørensen-Dice coefficient, between the two masks.
\[DSC = 2 * |X ∩ Y| / |X| + |Y|\]- Parameters:
gt_mask (
np.ndarray) – A binary ground truth maskpred_mask (
np.ndarray) – A binary predicted mask
- Returns:
An estimate of Sørensen-Dice coefficient value.
- Return type:
Examples
>>> from tiatoolbox.utils.metrics import dice >>> # Generate two random example masks; replace with your own data >>> import numpy as np >>> np.random.seed(6) >>> gt_mask = (np.random.rand(256, 256) > 0.8).astype(np.uint8) >>> pred_mask = (np.random.rand(256, 256) > 0.8).astype(np.uint8) >>> # Example usage of dice >>> dice_score = dice(gt_mask, pred_mask)