class_docstr: Region extractor for AI-VAD.
  
  Args:
      box_score_thresh (float): Confidence threshold for bounding box predictions.
      persons_only (bool): When enabled, only regions labeled as person are included.
      min_bbox_area (int): Minimum bounding box area. Regions with a surface area lower than this value are excluded.
      max_bbox_overlap (float): Maximum allowed overlap between bounding boxes.
      enable_foreground_detections (bool): Add additional foreground detections based on pixel difference between
          consecutive frames.
      foreground_kernel_size (int): Gaussian kernel size used in foreground detection.
      foreground_binary_threshold (int): Value between 0 and 255 which acts as binary threshold in foreground
          detection.
class_docstr_tok: ["Region","extractor","for","AI-VAD",".","Args",":","box_score_thresh","(","float",")",":","Confidence","threshold","for","bounding","box","predictions",".","persons_only","(","bool",")",":","When","enabled",",","only","regions","labeled","as","person","are","included",".","min_bbox_area","(","int",")",":","Minimum","bounding","box","area",".","Regions","with","a","surface","area","lower","than","this","value","are","excluded",".","max_bbox_overlap","(","float",")",":","Maximum","allowed","overlap","between","bounding","boxes",".","enable_foreground_detections","(","bool",")",":","Add","additional","foreground","detections","based","on","pixel","difference","between","consecutive","frames",".","foreground_kernel_size","(","int",")",":","Gaussian","kernel","size","used","in","foreground","detection",".","foreground_binary_threshold","(","int",")",":","Value","between","0","and","255","which","acts","as","binary","threshold","in","foreground","detection","."]
docstr: Delete overlapping bounding boxes.
  
  For each bounding box, the overlap with all other bounding boxes relative to their own surface area is computed.
  When the relative overlap with any other box is higher than the specified threshold, the box is removed. when
  both boxes have a relative overlap higher than the threshold, only the smaller box is removed.
  
  Args:
      regions (dict[str, Tensor]): Region detections for a single image in the batch.
  
  Returns:
      dict[str, Tensor]: Region detections from which overlapping regions have been removed.
docstr_tok: ["Delete","overlapping","bounding","boxes",".","For","each","bounding","box",",","the","overlap","with","all","other","bounding","boxes","relative","to","their","own","surface","area","is","computed",".","When","the","relative","overlap","with","any","other","box","is","higher","than","the","specified","threshold",",","the","box","is","removed",".","when","both","boxes","have","a","relative","overlap","higher","than","the","threshold",",","only","the","smaller","box","is","removed",".","Args",":","regions","(","dict","[","str",",","Tensor","]",")",":","Region","detections","for","a","single","image","in","the","batch",".","Returns",":","dict","[","str",",","Tensor","]",":","Region","detections","from","which","overlapping","regions","have","been","removed","."]
code: def _delete_overlapping_boxes(
      self, regions: dict[str, Tensor], threshold: float
  ) -> dict[str, Tensor]:
      """Delete overlapping bounding boxes.
  
      For each bounding box, the overlap with all other bounding boxes relative to their own surface area is computed.
      When the relative overlap with any other box is higher than the specified threshold, the box is removed. when
      both boxes have a relative overlap higher than the threshold, only the smaller box is removed.
  
      Args:
          regions (dict[str, Tensor]): Region detections for a single image in the batch.
  
      Returns:
          dict[str, Tensor]: Region detections from which overlapping regions have been removed.
      """
  
      # sort boxes by area
      areas = box_area(regions["boxes"])
      indices = areas.argsort()
  
      keep = []
      for idx in range(len(indices)):
          overlap_coords = torch.hstack(
              [
                  torch.max(
                      regions["boxes"][indices[idx], :2],
                      regions["boxes"][indices[idx + 1 :], :2],
                  ),  # x1, y1
                  torch.min(
                      regions["boxes"][indices[idx], 2:],
                      regions["boxes"][indices[idx + 1 :], 2:],
                  ),  # x2, y2
              ]
          )
          mask = torch.all(
              overlap_coords[:, :2] < overlap_coords[:, 2:], dim=1
          )  # filter non-overlapping
          overlap = box_area(overlap_coords) * mask.int()
          overlap_ratio = overlap / areas[indices[idx]]
  
          if not any(overlap_ratio > threshold):
              keep.append(indices[idx])
  
      return self.subsample_regions(regions, torch.stack(keep))
  
file_path: anomalib/src/anomalib/models/ai_vad/regions.py
imports: from __future__ import annotations
  import torch
  from torch import Tensor, nn
  from torchvision.models.detection import MaskRCNN_ResNet50_FPN_V2_Weights, maskrcnn_resnet50_fpn_v2
  from torchvision.ops import box_area, clip_boxes_to_image
  from torchvision.transforms.functional import gaussian_blur, rgb_to_grayscale
  from anomalib.data.utils.boxes import boxes_to_masks, masks_to_boxes
label_desc: Use image node_id 7 for calling the RegionExtractor obj's underlying member method code with example usage: obj._delete_overlapping_boxes(regions, threshold) and returns: self