synapse_net.ground_truth.matching

 1import numpy as np
 2
 3from elf.evaluation.matching import label_overlap, intersection_over_union
 4from skimage.segmentation import relabel_sequential
 5
 6
 7def find_additional_objects(
 8    ground_truth: np.ndarray,
 9    segmentation: np.ndarray,
10    matching_threshold: float = 0.5
11) -> np.ndarray:
12    """Compare ground-truth annotations with a segmentation to find objects not in the annotation.
13
14    Args:
15        ground_trut:
16        segmentation:
17        matching_threshold:
18
19    Returns:
20    """
21
22    segmentation = relabel_sequential(segmentation)[0]
23
24    # Match the objects in the segmentation to the ground-truth.
25    overlap, _ = label_overlap(segmentation, ground_truth)
26    overlap = intersection_over_union(overlap)
27
28    # Get the segmentation IDs.
29    seg_ids = np.unique(segmentation)
30
31    # Filter out IDs with a larger overlap than the matching threshold:
32    # These likely correspond to an object covered by the ground-truth.
33    filter_ids = []
34    for seg_id in seg_ids[1:]:
35        max_overlap = overlap[seg_id, :].max()
36        if max_overlap > matching_threshold:
37            filter_ids.append(seg_id)
38
39    # Get the additional objects by removing filtered objects.
40    additional_objects = segmentation.copy()
41    additional_objects[np.isin(segmentation, filter_ids)] = 0
42    additional_objects = relabel_sequential(additional_objects)[0]
43
44    return additional_objects
def find_additional_objects( ground_truth: numpy.ndarray, segmentation: numpy.ndarray, matching_threshold: float = 0.5) -> numpy.ndarray:
 8def find_additional_objects(
 9    ground_truth: np.ndarray,
10    segmentation: np.ndarray,
11    matching_threshold: float = 0.5
12) -> np.ndarray:
13    """Compare ground-truth annotations with a segmentation to find objects not in the annotation.
14
15    Args:
16        ground_trut:
17        segmentation:
18        matching_threshold:
19
20    Returns:
21    """
22
23    segmentation = relabel_sequential(segmentation)[0]
24
25    # Match the objects in the segmentation to the ground-truth.
26    overlap, _ = label_overlap(segmentation, ground_truth)
27    overlap = intersection_over_union(overlap)
28
29    # Get the segmentation IDs.
30    seg_ids = np.unique(segmentation)
31
32    # Filter out IDs with a larger overlap than the matching threshold:
33    # These likely correspond to an object covered by the ground-truth.
34    filter_ids = []
35    for seg_id in seg_ids[1:]:
36        max_overlap = overlap[seg_id, :].max()
37        if max_overlap > matching_threshold:
38            filter_ids.append(seg_id)
39
40    # Get the additional objects by removing filtered objects.
41    additional_objects = segmentation.copy()
42    additional_objects[np.isin(segmentation, filter_ids)] = 0
43    additional_objects = relabel_sequential(additional_objects)[0]
44
45    return additional_objects

Compare ground-truth annotations with a segmentation to find objects not in the annotation.

Arguments:
  • ground_trut:
  • segmentation:
  • matching_threshold:

Returns: