Skip to content

Commit

Permalink
add min overlap ratio as an arg for lesion-wise metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
naga-karthik committed Dec 9, 2024
1 parent 28f684a commit e7bfea7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions MetricsReloaded/metrics/pairwise_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def __init__(
pixdim=None,
empty=False,
dict_args={},
overlap_ratio=0.1,
):

self.measures_dict = {
Expand Down Expand Up @@ -300,6 +301,7 @@ def __init__(
self.connectivity = connectivity_type
self.pixdim = pixdim
self.dict_args = dict_args
self.overlap_ratio = overlap_ratio

def __fp_map(self):
"""
Expand Down Expand Up @@ -1178,7 +1180,9 @@ def measured_hausdorff_distance_perc(self):
def lesion_wise_tp_fp_fn(self, truth, prediction):
"""
Computes the true positives, false positives, and false negatives two masks. Masks are considered true positives
if at least one voxel overlaps between the truth and the prediction.
if there is at least `self.overlap_ratio` overlap between the truth and the prediction.
i.e. if self.overlap_ratio = 0.1, then at least 10% of the lesion voxels should overlap between the truth and
the prediction to be considered as true positive.
Adapted from: https://github.com/npnl/atlas2_grand_challenge/blob/main/isles/scoring.py#L341
Parameters
Expand Down Expand Up @@ -1215,7 +1219,7 @@ def lesion_wise_tp_fp_fn(self, truth, prediction):
num_truth_lesion_voxels = np.sum(lesion) # Total number of voxels in the GT lesion
overlapping_voxels = np.sum(lesion * prediction) # Number of GT voxels that overlap with the prediction
# Check if at least 10% of the lesion voxels overlap with the prediction
if overlapping_voxels / num_truth_lesion_voxels >= 0.1:
if overlapping_voxels / num_truth_lesion_voxels >= self.overlap_ratio:
tp += 1
else:
fn += 1
Expand All @@ -1226,7 +1230,7 @@ def lesion_wise_tp_fp_fn(self, truth, prediction):
lesion = labeled_prediction == idx_lesion
# num_pred_lesion_voxels = np.sum(lesion)
# overlapping_voxels = np.sum(lesion & truth)
# if overlapping_voxels / num_pred_lesion_voxels < 0.1:
# if overlapping_voxels / num_pred_lesion_voxels < self.overlap_ratio:
# fp += 1
lesion_pred_sum = lesion + truth
if(np.max(lesion_pred_sum) <= 1): # No overlap
Expand Down

0 comments on commit e7bfea7

Please sign in to comment.