Skip to content

Commit 71b28a2

Browse files
committed
v1.2.6 fix vs
1 parent 9b287c2 commit 71b28a2

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/.idea/
22
*.pyc
33
*__pycache__**
4-
*docs/build*
4+
*docs/build*
5+
/build/
6+
/seg_metrics.egg-info

seg_metrics/seg_metrics.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def computeQualityMeasures(lP: np.ndarray,
3131
lT: np.ndarray,
3232
spacing: np.ndarray,
3333
metrics_names: Union[Sequence, set, None] = None,
34-
fullyConnected=True):
34+
fullyConnected=True,
35+
label: int = 0):
3536
"""
3637
3738
:param lP: prediction, shape (x, y, z)
@@ -81,7 +82,7 @@ def computeQualityMeasures(lP: np.ndarray,
8182
# smooth = 0.001
8283

8384
if (gdth_sum + pred_sum) == 0:
84-
logging.warning(f'Note: Both ground truth and prediction of the image are 0, dice, jaccard, precision and recall are regarded as 1, FPR and FNR are 0')
85+
logging.warning(f'Note: Both ground truth and prediction of the image for label {label} are all 0, dice, jaccard, precision and recall are regarded as 1, FPR and FNR are 0')
8586
dice, jaccard, precision, recall = 1, 1, 1, 1
8687
fpr, fnr = 0, 0
8788

@@ -91,17 +92,17 @@ def computeQualityMeasures(lP: np.ndarray,
9192

9293

9394
if pred_sum == 0: # no positive prediction
94-
logging.warning(f'Note: The prediction results of this image are all 0 while ground truth is not 0, so the precision is 0, recall is regarded as 0')
95+
logging.warning(f'Note: The prediction results of this image for label {label} are all 0 while ground truth is not 0, so the precision is 0, recall is regarded as 0')
9596
precision, recall = 0, 0 # 0
9697
fnr = 1
9798
fpr = 0
9899
elif gdth_sum == 0:
99-
logging.warning(f'Note: The ground truth of this image are all 0 while the prediction results are not 0, so the recall and FPR are 0, precision and FNR are regarded as 0')
100+
logging.warning(f'Note: The ground truth of this image for label {label} are all 0 while the prediction results are not 0, so the recall and FPR are 0, precision and FNR are regarded as 0')
100101
precision, recall = 0, 0 # 0
101102
fnr, fpr = 0, 0
102103
else:
103104
if (fp + tn) == 0:
104-
logging.warning(f'Note: The ground truth of this image are all 1, so FPR is 0')
105+
logging.warning(f'Note: The ground truth of this image for label {label} are all 1, so FPR is 0')
105106
fpr = 0
106107
else:
107108
fpr = fp / (fp + tn)
@@ -168,15 +169,20 @@ def computeQualityMeasures(lP: np.ndarray,
168169
ref2seg_distances = ref2seg_distances + list(np.zeros(num_ref_surface_pixels - len(ref2seg_distances))) #
169170

170171
all_surface_distances = seg2ref_distances + ref2seg_distances
171-
quality["msd"] = np.mean(all_surface_distances)
172-
quality["mdsd"] = np.median(all_surface_distances)
173-
quality["stdsd"] = np.std(all_surface_distances)
172+
174173
if len(all_surface_distances) == 0:
175174
quality["hd95"] = 0
176175
quality["hd"] = 0
176+
quality["msd"] = 0
177+
quality["mdsd"] = 0
178+
quality["stdsd"] = 0
179+
quality["vs"] = 1
177180
else:
178181
quality["hd95"] = np.percentile(all_surface_distances, 95)
179182
quality["hd"] = np.max(all_surface_distances)
183+
quality["msd"] = np.mean(all_surface_distances)
184+
quality["mdsd"] = np.median(all_surface_distances)
185+
quality["stdsd"] = np.std(all_surface_distances)
180186
return quality
181187

182188

@@ -245,7 +251,7 @@ def get_metrics_dict_all_labels(labels: Sequence,
245251
metrics = computeQualityMeasures(pred_per, gdth_per,
246252
spacing=spacing,
247253
metrics_names=metrics_names,
248-
fullyConnected=fullyConnected)
254+
fullyConnected=fullyConnected, label=label)
249255

250256
for k, v in metrics_dict_all_labels.items():
251257
if k in metrics_names:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setuptools.setup(
2626
name="seg_metrics", # Replace with your own username
27-
version="1.2.5",
27+
version="1.2.6",
2828
author="Jingnan Jia",
2929
author_email="jiajingnan2222@gmail.com",
3030
description="A package to compute different segmentation metrics for 2D/3D medical images.",

0 commit comments

Comments
 (0)