RegionIoU

Compute pairwise Intersection over Union (IoU) values between two sets of ROIs, or between a set of ROIs and an arbitrary shape. For more information, check this article.

Parameters

  • roi_1: Reference to bounding box or polygon within the transaction

  • [optional] roi_2 Reference to bounding box or polygon within the transaction

  • [optional] rectangle: The coordinates of a bounding box RoI

  • [optional] polygons: The vertices of a polygon RoI

Details

Exactly one of roi_2, rectangle, or polygons must be specified.

Examples

Within in a specific image, find bounding boxes labeled “skateboard” and polygons labeled “dog”, and then return the IoU matrix between those sets of regions. Nonzero IoU values indicate pairs that overlap:

[ {
    "FindImage": {
        "_ref": 1,
        "blobs": false,
        "constraints": {
            "id": ["==", 1234]
        }
    }
}, {
    "FindBoundingBox": {
        "_ref": 2,
        "image_ref": 1,
        "with_label" : "skateboard",
        "uniqueids": True
    }
}, {
    "FindPolygon": {
        "_ref": 3,
        "image_ref": 1,
        "with_label" : "dog",
        "uniqueids": True
    }
}, {
    "RegionIoU": {
        "roi_1": 2
        "roi_2": 3
    }
}]

# Response:

[ {
    "FindImage": {
        "status": 0,
    }
}, {
    "FindPolygon": {
        "entities": [{"_uniqueid": 11}, {"_uniqueid": 12}],
        "returned": 2,
        "status": 0,
    }
}, {
    "FindPolygon": {
        "entities": [{"_uniqueid": 21}, {"_uniqueid": 22}, {"_uniqueid": 23}],
        "returned": 3,
        "status": 0,
    }
}, {
    "RegionIoU": {
        "status": 0,
        "IoU": [
            [0.0, 0.1875, 0.0],
            [0.2012, 0.0, 0.0]
        ]
    }
}]

# skateboard w/ uid 11 intersects dog w/ uid 22
# skateboard w/ uid 12 intersects dog w/ uid 21
# dog w/ uid 23 is not riding a skateboard

Find a Polygon with “id” property equal to 2342 and compute the Intersection Over Union (IoU) with a custom polygon:

[ {
    "FindPolygon": {
        "_ref": 1,
        "constraints" : {
            "id" : ["==", 2342],
        }
    }
}, {
    "RegionIoU": {
        "roi_1": 1,
        "polygons": [
            [
                [387.99, 176.5],
                [398.34, 164.68],
                [405.73, 156.55],
                [412.38, 141.77],
                ...
            ]
        ]
    }
}]

# Response:

[ {
    "FindPolygon": {
        "status": 0,
    }
}, {
    "RegionIoU": {
        "status": 0,
        "IoU": [[0.985432]],
    }
}]