Intersection over Union
box_iou
def box_iou(box_true, box_detection)
box_true and box_detection. Both boxes are expected to be tuples in (x_min, y_min, x_max, y_max) format.
Args
-
box_true:
tuplerepresenting ground-truth bounding boxes. -
box_detection:
tuplerepresenting detection bounding boxes.
Returns
- iou:
floatvalue between 0 and 1.Noneif union is equal to 0.
Example usage
>>> from onemetric.cv.utils.iou import box_iou
>>> iou = box_iou_batch(
... boxes_true=(0., 0., 1., 1.),
... boxes_detection=(0.25, 0., 1.25, 1.)
... )
>>> iou
... 0.6
box_iou_batch
def box_iou_batch(boxes_true, boxes_detection)
boxes_true and boxes_detection. Both sets of boxes are expected to be in (x_min, y_min, x_max, y_max) format.
Args
-
boxes_true: 2d
np.ndarrayrepresenting ground-truth boxes.shape = (N, 4)where N is number of true objects. -
boxes_detection: 2d
np.ndarrayrepresenting detection boxes.shape = (M, 4)where M is number of detected objects.
Returns
- iou: 2d
np.ndarrayrepresenting pairwise IoU of boxes fromboxes_trueandboxes_detection.shape = (N, M)where N is number of true objects and M is number of detected objects.
Example usage
>>> import numpy as np
>>> from onemetric.cv.utils.iou import box_iou_batch
>>> boxes_true = np.array([
... [0., 0., 1., 1.],
... [2., 2., 2.5, 2.5]
... ])
>>> boxes_detection = np.array([
... [0., 0., 1., 1.],
... [2., 2., 2.5, 2.5]
... ])
>>> iou = box_iou_batch(boxes_true=boxes_true, boxes_detection=boxes_detection)
>>> iou
... np.array([
... [1., 0.],
... [0., 1.]
... ])
mask_iou
def mask_iou(mask_true, mask_detection)
np.uint8 type and contain binary values (0 or 1).
Args
-
mask_true: 2d
np.ndarrayrepresenting ground-truth mask. -
mask_detection: 2d
np.ndarrayrepresenting detection mask.
Returns
- iou:
floatvalue between 0 and 1.Noneif union is equal to 0.
Example usage
>>> import numpy as np
>>> from onemetric.cv.utils.iou import mask_iou
>>> full_mask = np.ones((10, 10)).astype('uint8')
>>> quarter_mask = np.zeros((10, 10)).astype('uint8')
>>> quarter_mask[0:5, 0:5] = 1
>>> iou = mask_iou(mask_true=full_mask, mask_detection=quarter_mask)
>>> iou
... 0.25