Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relative Volume Error metric #2

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion MetricsReloaded/metrics/pairwise_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def __init__(
"masd": (self.measured_masd, "MASD"),
"nsd": (self.normalised_surface_distance, "NSD"),
"vol_diff": (self.vol_diff, "VolDiff"),
"rel_vol_error": (self.rel_vol_error, "RelVolError"),
}

self.pred = pred
Expand Down Expand Up @@ -886,6 +887,25 @@ def vol_diff(self):
"""
return np.abs(self.n_pos_ref() - self.n_pos_pred()) / self.n_pos_ref()

def rel_vol_error(self):
"""
This function calculates the relative volume error (RVE) in % between the prediction and the reference.
If the prediction is smaller than the reference, the relative volume difference is negative.
If the prediction is larger than the reference, the relative volume difference is positive.

:return: rel_vol_error
"""
if self.flag_empty_ref and self.flag_empty_pred:
# Both reference and prediction are empty --> model learned correctly --> setting 0 representing no over-
# or under-segmentation
return 0
elif self.flag_empty_ref and not self.flag_empty_pred:
# Reference is empty, prediction is not empty --> model did not learn correctly --> setting positive value
# representing overestimation
return 100
else:
return ((self.n_pos_pred() - self.n_pos_ref()) / self.n_pos_ref()) * 100

@CacheFunctionOutput
def skeleton_versions(self):
"""
Expand Down Expand Up @@ -1072,7 +1092,7 @@ def measured_distance(self):
ref_border,
pred_border,
) = self.border_distance()
print(ref_border_dist)
#print(ref_border_dist)
average_distance = (np.sum(ref_border_dist) + np.sum(pred_border_dist)) / (
np.sum(pred_border + ref_border)
)
Expand Down