From 555d45c5c2fee83ce3e8745fa9ab4171f23dbb55 Mon Sep 17 00:00:00 2001 From: Ramtin Gharleghi Date: Fri, 18 Sep 2020 22:21:24 +1000 Subject: [PATCH] Change Hausdorff distance to mm --- evaluation.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/evaluation.py b/evaluation.py index d876b85..b76e82e 100644 --- a/evaluation.py +++ b/evaluation.py @@ -8,12 +8,12 @@ from evalutils.validators import ( NumberOfCasesValidator, UniquePathIndicesValidator, UniqueImagesValidator ) -def hausdorff_95(submission,groundtruth): +def hausdorff_95(submission,groundtruth, spacing): # There are more efficient algorithms for hausdorff distance than brute force, however, brute force is sufficient for datasets of this size. - submission_points = np.array(np.where(submission), dtype=np.uint16).T + submission_points = spacing*np.array(np.where(submission), dtype=np.uint16).T submission_kdtree = cKDTree(submission_points) - groundtruth_points = np.array(np.where(groundtruth), dtype=np.uint16).T + groundtruth_points = spacing*np.array(np.where(groundtruth), dtype=np.uint16).T groundtruth_kdtree = cKDTree(groundtruth_points) distances1,_ = submission_kdtree.query(groundtruth_points) @@ -61,6 +61,8 @@ def score_case(self, *, idx, case): pred_path = case["path_prediction"] submission = Loader.load_image(pred_path) truth, truth_header = nrrd.read(gt_path) + spacing = np.diag(truth_header['space directions']) + submission = submission>0.5 if np.count_nonzero(submission)==0: raise ValueError(f" Submission {pred_path.name} is empty") @@ -69,7 +71,7 @@ def score_case(self, *, idx, case): raise ValueError(f" Expected image with dimensions {truth.shape}, got {submission.shape} in {pred_path.name}") truth = truth>0.5 dice=dice_score(submission, truth) - hausdorff = hausdorff_95(submission=submission, groundtruth=truth) + hausdorff = hausdorff_95(submission=submission, groundtruth=truth, spacing=spacing) return {