Compute Dice score, Hausdorff distance for Multi-Region segmentation

Hi,
I have NIFTI files of sizes (512 x 512 x 150) of auto-segmentation and manual segmentation. Each file/slice contains the segmentation of multiple regions (seven regions). I want to compute the dice score, Hausdorff distance, Jaccard index, and average surface distance.
Could you please suggest the easiest method for that purpose? I don’t want to convert NIFTI to PNGs/JPEGs. I tried the plastimatch dice. It seems that it doesn’t work for multi-region segmentation. Please find the command and relevant output of plastimatch. Please suggest if I am missing anything or if there is a better approach.

plastimatch dice --all manual_GT.nii Auto_seg.nii
CENTER_OF_MASS
ref 15.9689 -56.3064 -32.7915
cmp 16.4171 -56.3639 -35.121
TP: 194139
TN: 40941820
FN: 10594
FP: 10055
DICE: 0.949504
SE: 0.948255
SP: 0.999754
Hausdorff distance = 12.750913
Avg average Hausdorff distance = 0.131478
Max average Hausdorff distance = 0.160547
Percent (0.95) Hausdorff distance = 0.634766
Hausdorff distance (boundary) = 27.516542
Avg average Hausdorff distance (boundary) = 1.705389
Max average Hausdorff distance (boundary) = 1.814141
Percent (0.95) Hausdorff distance (boundary) = 5.156286

The Segment Comparison module in the SlicerRT extension allows you to compute Dice and Hausdorff on segmentations containing multiple labels. You’ll need to first convert the labelmap volumes to segmentation nodes (in Segmentations module Import/Export section, or in the Data module by right-clicking the labelmap volume).

@cpinter Thanks a lot! It worked. I love Slicer! Btw, some features can be improved and can be made more interactive by incorporating some sort of automation. For example, the “Segment Comparison” tool should have the Box/tick option for all segments rather than the drop-down menu.

1 Like

@cpinter Could you please point out where can I find the source code for Segment Comparison module (Version 5.2.2). I’m getting different values of dice score for 3D binary nifti masks when using 3D Slicer and Monai framework. This is the monai function I’m using:

def calculate_dice_score(predicted, ground_truth):
      dice_metric = monai.metrics.DiceMetric(include_background=False, reduction="mean")
      # Convert the predicted and ground truth masks to PyTorch tensors
      predicted_tensor = torch.from_numpy(predicted)
      ground_truth_tensor = torch.from_numpy(ground_truth)
      # Reshape tensors to have batch size and number of channels
      predicted_tensor = predicted_tensor.unsqueeze(0).unsqueeze(0)
      ground_truth_tensor = ground_truth_tensor.unsqueeze(0).unsqueeze(0)
      # Calculate the Dice score
      dice_score = dice_metric(y_pred =predicted_tensor, y = ground_truth_tensor)
      return dice_score.item()

Thanks!

Please create a new topic for this and I’ll answer there. If we keep reusing year-old topic nobidy will be able to find anything here. Thanks!

Noted. Thank you! Created a new topic: Dice score calculation of 3D binary masks using Segment Comparison module

@cpinter thank you. However I have trouble locating Dice and Hausdorff from SlicerRT extension. I’m using Slicer 5.6. Could you please point me where they are.

It’s in the Segment Comparison module. What operating system do you use? There have been issues on Mac lately with some extensions.

@cpinter , thanks for getting back to me. I use 14.2 (23C64) on an Apple M1 Pro. I couldn’t find this Segment Comparison module on Slicer 5.6 and Slicer 5.6.1. But I was able to find it on Slicer 5.2 after I revert it back.

3 posts were merged into an existing topic: Hausdorff Distance Interval