0
votes

I am doing medical image segmentation and working on 3D images, and have two images one is ground truth (gt), and one the segmentation prediction results (segm), I need to calculate two other metrics

  • average absolute surface distance (AvgD) in mm,
  • the average root mean square surface distance (RMSD) in mm,
  • the volumetric overlap error (VOE) in percent,
  • the relative volume difference (VD) in percent.

enter image description here enter image description here

Where R is gt and S is segm. In python, the intersection can be calculated np.logical_and(segm, gt). But I have no idea how these four evaluation metrics can be calculated. Your help is really appreciated.

2
The intersection in matlab can be computed as 'logical_and=segm & gt' in Matlab. But I think you are more interested in Python than in Matlab, eventhough you put matlab as a keyword? - BayesianMonk

2 Answers

0
votes

Assuming segm and gt are binary ndarrays, you can compute VOE and VD:

voe = 100 * (1. - np.logical_and(segm, gt).sum() / float(np.logical_or(segm, gt)))
vd = 100 * (segm.sum() - gt.sum()) / float(gt.sum())

Note that you can use .sum() of a binary mask in order to compute its "size", that is |S| = segm.sum().

0
votes

Yes, there are some surface distance based metrics.

  • Hausdorff distance
  • Hausdorff distance 95% percentile
  • Mean (Average) surface distance
  • Median surface distance
  • Standard deviation of surface distance

https://pypi.org/project/seg-metrics/

This is a simple package to compute different metrics for Medical image segmentation(images with suffix .mhd, .mha, .nii, .nii.gz or .nrrd), and write them to csv file.

An example:

Install this package at first. pip install seg-metrics

import seg_metrics.seg_metrics as sg

labels = [0, 4, 5 ,6 ,7 , 8]
gdth_file = 'data/gdth.mhd'  # ground truth image full path
pred_file = 'data/pred.mhd'  # prediction image full path
csv_file = 'metrics.csv'

metrics = sg.write_metrics(labels=labels[1:],  # exclude background
                  gdth_path=gdth_file,
                  pred_path=pred_file,
                  csv_file=csv_file, 
                  metrics=['hd', 'msd'])