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 HD 95 metric #249

Merged
merged 2 commits into from
Feb 4, 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
13 changes: 6 additions & 7 deletions platipy/imaging/label/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def compute_surface_dsc(label_a, label_b, tau=3.0):

def compute_surface_metrics(label_a, label_b, verbose=False):
"""Compute surface distance metrics between two labels. Surface metrics computed are:
hausdorffDistance, meanSurfaceDistance, medianSurfaceDistance, maximumSurfaceDistance,
sigmaSurfaceDistance, surfaceDSC
hausdorffDistance, hausdorffDistance95, meanSurfaceDistance, medianSurfaceDistance,
maximumSurfaceDistance, sigmaSurfaceDistance, surfaceDSC

Args:
label_a (sitk.Image): A mask to compare
Expand All @@ -95,8 +95,7 @@ def compute_surface_metrics(label_a, label_b, verbose=False):
std_sd_list = []
median_sd_list = []
num_points = []
for (la, lb) in ((label_a, label_b), (label_b, label_a)):

for la, lb in ((label_a, label_b), (label_b, label_a)):
label_intensity_stat = sitk.LabelIntensityStatisticsImageFilter()
reference_distance_map = sitk.Abs(
sitk.SignedMaurerDistanceMap(
Expand All @@ -118,6 +117,7 @@ def compute_surface_metrics(label_a, label_b, verbose=False):

mean_surf_dist = np.dot(mean_sd_list, num_points) / np.sum(num_points)
max_surf_dist = np.max(max_sd_list)
hd_95 = np.percentile(max_sd_list, 95)
std_surf_dist = np.sqrt(
np.dot(
num_points,
Expand All @@ -131,6 +131,7 @@ def compute_surface_metrics(label_a, label_b, verbose=False):

result = {}
result["hausdorffDistance"] = hd
result["hausdorffDistance95"] = hd_95
result["meanSurfaceDistance"] = mean_surf_dist
result["medianSurfaceDistance"] = median_surf_dist
result["maximumSurfaceDistance"] = max_surf_dist
Expand Down Expand Up @@ -294,8 +295,7 @@ def compute_metric_masd(label_a, label_b, auto_crop=True):

mean_sd_list = []
num_points = []
for (la, lb) in ((label_a, label_b), (label_b, label_a)):

for la, lb in ((label_a, label_b), (label_b, label_a)):
label_intensity_stat = sitk.LabelIntensityStatisticsImageFilter()
reference_distance_map = sitk.Abs(
sitk.SignedMaurerDistanceMap(
Expand Down Expand Up @@ -364,7 +364,6 @@ def compute_apl(label_ref, label_test, distance_threshold_mm=3):

# iterate over each slice
for i in range(n_slices):

if (
sitk.GetArrayViewFromImage(label_ref)[i].sum()
+ sitk.GetArrayViewFromImage(label_test)[i].sum()
Expand Down
Loading