@@ -41,6 +41,20 @@ def pair_coordinates(
41
41
- :class:`numpy.ndarray` - Unpaired B:
42
42
Indices of unpaired points in set B.
43
43
44
+
45
+ Examples:
46
+ >>> from tiatoolbox.utils.metrics import pair_coordinates
47
+ >>> # Generate two random example sets; replace with your own data
48
+ >>> import numpy as np
49
+ >>> np.random.seed(6)
50
+ >>> set_a_num_points = np.random.randint(low=10, high=30)
51
+ >>> set_b_num_points = np.random.randint(low=10, high=30)
52
+ >>> set_a = np.random.randint(low=0, high=25, size=(set_a_num_points, 2))
53
+ >>> set_b = np.random.randint(low=0, high=25, size=(set_b_num_points, 2))
54
+ >>> radius = 2.0
55
+ >>> # Example usage of pair_coordinates
56
+ >>> pairing, unpaired_a, unpaired_b = pair_coordinates(set_a, set_b, radius)
57
+
44
58
"""
45
59
# * Euclidean distance as the cost matrix
46
60
pair_distance = distance .cdist (set_a , set_b , metric = "euclidean" )
@@ -65,7 +79,22 @@ def pair_coordinates(
65
79
66
80
67
81
def f1_detection (true : np .ndarray , pred : np .ndarray , radius : float ) -> float :
68
- """Calculate the F1-score for predicted set of coordinates."""
82
+ """Calculate the F1-score for predicted set of coordinates.
83
+
84
+ Examples:
85
+ >>> from tiatoolbox.utils.metrics import f1_detection
86
+ >>> # Generate two random example sets; replace with your own data
87
+ >>> import numpy as np
88
+ >>> np.random.seed(6)
89
+ >>> true_num_points = np.random.randint(low=10, high=30)
90
+ >>> pred_num_points = np.random.randint(low=10, high=30)
91
+ >>> true = np.random.randint(low=0, high=25, size=(true_num_points, 2))
92
+ >>> pred = np.random.randint(low=0, high=25, size=(pred_num_points, 2))
93
+ >>> radius = 2.0
94
+ >>> # Example usage of f1_detection
95
+ >>> f1_score = f1_detection(true, pred, radius)
96
+
97
+ """
69
98
(paired_true , unpaired_true , unpaired_pred ) = pair_coordinates (true , pred , radius )
70
99
71
100
tp = len (paired_true )
@@ -94,6 +123,16 @@ def dice(gt_mask: np.ndarray, pred_mask: np.ndarray) -> float:
94
123
:class:`float`:
95
124
An estimate of Sørensen-Dice coefficient value.
96
125
126
+ Examples:
127
+ >>> from tiatoolbox.utils.metrics import dice
128
+ >>> # Generate two random example masks; replace with your own data
129
+ >>> import numpy as np
130
+ >>> np.random.seed(6)
131
+ >>> gt_mask = (np.random.rand(256, 256) > 0.8).astype(np.uint8)
132
+ >>> pred_mask = (np.random.rand(256, 256) > 0.8).astype(np.uint8)
133
+ >>> # Example usage of dice
134
+ >>> dice_score = dice(gt_mask, pred_mask)
135
+
97
136
"""
98
137
if gt_mask .shape != pred_mask .shape :
99
138
msg = f"{ 'Shape mismatch between the two masks.' } "
0 commit comments