Skip to content

Commit

Permalink
Change Hausdorff distance to mm
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtingh committed Sep 18, 2020
1 parent 515a9e8 commit 555d45c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down

0 comments on commit 555d45c

Please sign in to comment.