M
madrigal
8a66860d33
All checks were successful
Build Sphinx Docs Set / Build Docs (pull_request) Successful in 15m51s
Build Project / Build Project (3.10) (pull_request) Successful in 16m14s
Build Project / Build Project (3.11) (pull_request) Successful in 17m9s
Build Project / Build Project (3.12) (pull_request) Successful in 2m29s
Test with tox / Test with tox (3.12) (pull_request) Successful in 21m28s
Test with tox / Test with tox (3.10) (pull_request) Successful in 22m50s
Test with tox / Test with tox (3.11) (pull_request) Successful in 23m18s
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from ria_toolkit_oss.data.annotation import Annotation
|
|
|
|
# TODO figure out how to transfer labels in the merge case
|
|
|
|
|
|
def remove_contained_boxes(annotations: list[Annotation]):
|
|
"""
|
|
Remove all annotations (bounding boxes) that are entirely contained within other boxes in the list.
|
|
|
|
:param annotations: A list of Annotation objects.
|
|
:type annotations: list[Annotation]
|
|
|
|
:returns: A new list of Annotation objects.
|
|
:rtype: list[Annotation]"""
|
|
|
|
output_boxes = []
|
|
|
|
for i in range(len(annotations)):
|
|
contained = False
|
|
for j in range(len(annotations)):
|
|
if i != j and is_annotation_contained(annotations[i], annotations[j]):
|
|
contained = True
|
|
break
|
|
|
|
if not contained:
|
|
output_boxes.append(annotations[i])
|
|
|
|
return output_boxes
|
|
|
|
|
|
def is_annotation_contained(inner: Annotation, outer: Annotation) -> bool:
|
|
"""
|
|
Check if an annotation box is entirely contained within another annotation bounding box.
|
|
|
|
:param inner: The inner box.
|
|
:type inner: Annotation.
|
|
:param outer: The outer box.
|
|
:type outer: Annotation.
|
|
|
|
:returns: True if inner is within outer, false otherwise.
|
|
:rtype: bool
|
|
"""
|
|
|
|
inner_sample_stop = inner.sample_start + inner.sample_count
|
|
outer_sample_stop = outer.sample_start + outer.sample_count
|
|
|
|
if inner.sample_start > outer.sample_start and inner_sample_stop < outer_sample_stop:
|
|
if inner.freq_lower_edge > outer.freq_lower_edge and inner.freq_upper_edge < outer.freq_upper_edge:
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
def merge_annotations(annotations: list[Annotation], overlap_threshold) -> list[Annotation]:
|
|
raise NotImplementedError
|