Commit ed1665af authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): add docs for imgutils.detect.similarity

parent 6466e1d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ imgutils.detect
    head
    nudenet
    person
    similarity
    text
    visual
+30 −0
Original line number Diff line number Diff line
imgutils.detect.similarity
======================================

.. currentmodule:: imgutils.detect.similarity

.. automodule:: imgutils.detect.similarity



calculate_iou
------------------------------------------

.. autofunction:: calculate_iou



bboxes_similarity
------------------------------------------

.. autofunction:: bboxes_similarity



detection_similarity
------------------------------------------

.. autofunction:: detection_similarity


+24 −22
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ def calculate_iou(box1: BBoxTyping, box2: BBoxTyping) -> float:
    This function computes the IoU, which is a measure of the overlap between two bounding boxes.
    The IoU is calculated as the area of intersection divided by the area of union of the two boxes.

    Example usage:
    Example::
        >>> box1 = (0, 0, 2, 2)
        >>> box2 = (1, 1, 3, 3)
        >>> iou = calculate_iou(box1, box2)
@@ -74,11 +74,12 @@ def bboxes_similarity(bboxes1: List[BBoxTyping], bboxes2: List[BBoxTyping],

    This function computes the similarity between two lists of bounding boxes using the Hungarian algorithm
    to find the optimal assignment. It then returns the similarity based on the specified mode:
    - 'max': Returns the maximum IoU among all matched pairs.
    - 'mean': Returns the average IoU of all matched pairs.
    - 'raw': Returns a list of IoU values for all matched pairs.

    Example usage:
    - ``max``: Returns the maximum IoU among all matched pairs.
    - ``mean``: Returns the average IoU of all matched pairs.
    - ``raw``: Returns a list of IoU values for all matched pairs.

    Example::
        >>> bboxes1 = [(0, 0, 2, 2), (3, 3, 5, 5)]
        >>> bboxes2 = [(1, 1, 3, 3), (4, 4, 6, 6)]
        >>> similarity = bboxes_similarity(bboxes1, bboxes2, mode='mean')
@@ -125,13 +126,14 @@ def detection_similarity(detect1: List[BBoxWithScoreAndLabel], detect2: List[BBo
                        or if an unknown mode is specified.

    This function compares two lists of detections by:

    1. Grouping detections by their labels.
    2. For each label, calculating the similarity between the corresponding bounding boxes.
    3. Aggregating the similarities based on the specified mode.

    The function ensures that for each label, the number of bounding boxes matches between detect1 and detect2.

    Example usage:
    Example::
        >>> detect1 = [((0, 0, 2, 2), 'car', 0.9), ((3, 3, 5, 5), 'person', 0.8)]
        >>> detect2 = [((1, 1, 3, 3), 'car', 0.85), ((4, 4, 6, 6), 'person', 0.75)]
        >>> similarity = detection_similarity(detect1, detect2, mode='mean')