def image_box_region_area(img_cumsum, bbox):
    'check a 2d voxel is contained by a box. used to filter empty\n    anchors.\n    Summed-area table algorithm:\n    ==> W\n    ------------------\n    |      |         |\n    |------A---------B\n    |      |         |\n    |      |         |\n    |----- C---------D\n    Iabcd = ID-IB-IC+IA\n    Args:\n        img_cumsum: [M, H, W](yx) cumsumed image.\n        bbox: [N, 4](xyxy) bounding box,\n    '
    N = bbox.shape[0]
    M = img_cumsum.shape[0]
    ret = np.zeros([N, M], dtype=img_cumsum.dtype)
    ID = img_cumsum[:, bbox[:, 3], bbox[:, 2]]
    IA = img_cumsum[:, bbox[:, 1], bbox[:, 0]]
    IB = img_cumsum[:, bbox[:, 3], bbox[:, 0]]
    IC = img_cumsum[:, bbox[:, 1], bbox[:, 2]]
    ret = (((ID - IB) - IC) + IA)
    return ret
check a 2d voxel is contained by a box. used to filter empty
anchors.
Summed-area table algorithm:
==> W
------------------
|      |         |
|------A---------B
|      |         |
|      |         |
|----- C---------D
Iabcd = ID-IB-IC+IA
Args:
    img_cumsum: [M, H, W](yx) cumsumed image.
    bbox: [N, 4](xyxy) bounding box,
def image_box_region_area(img_cumsum, bbox):
    'check a 2d voxel is contained by a box. used to filter empty\n    anchors.\n    Summed-area table algorithm:\n    ==> W\n    ------------------\n    |      |         |\n    |------A---------B\n    |      |         |\n    |      |         |\n    |----- C---------D\n    Iabcd = ID-IB-IC+IA\n    Args:\n        img_cumsum: [M, H, W](yx) cumsumed image.\n        bbox: [N, 4](xyxy) bounding box,\n    '
    N = bbox.shape[0]
    M = img_cumsum.shape[0]
    ret = np.zeros([N, M], dtype=img_cumsum.dtype)
    ID = img_cumsum[:, bbox[:, 3], bbox[:, 2]]
    IA = img_cumsum[:, bbox[:, 1], bbox[:, 0]]
    IB = img_cumsum[:, bbox[:, 3], bbox[:, 0]]
    IC = img_cumsum[:, bbox[:, 1], bbox[:, 2]]
    ret = (((ID - IB) - IC) + IA)
    return ret