code: def filterRois(
      rects,
      img_w,
      img_h,
      roi_min_area,
      roi_max_area,
      roi_min_side,
      roi_max_side,
      roi_max_aspect_ratio,
  ):
      filteredRects = []
      filteredRectsSet = set()
      for rect in rects:
          if (
              tuple(rect) in filteredRectsSet
          ):  # excluding rectangles with same co-ordinates
              continue
  
          x, y, x2, y2 = rect
          w = x2 - x
          h = y2 - y
          assert w >= 0 and h >= 0
  
          # apply filters
          if (
              h == 0
              or w == 0
              or x2 > img_w
              or y2 > img_h
              or w < roi_min_side
              or h < roi_min_side
              or w > roi_max_side
              or h > roi_max_side
              or w * h < roi_min_area
              or w * h > roi_max_area
              or w / h > roi_max_aspect_ratio
              or h / w > roi_max_aspect_ratio
          ):
              continue
          filteredRects.append(rect)
          filteredRectsSet.add(tuple(rect))
  
      # could combine rectangles using non-maximum surpression or with similar co-ordinates
      # groupedRectangles, weights = cv2.groupRectangles(np.asanyarray(rectsInput, np.float).tolist(), 1, 0.3)
      # groupedRectangles = nms_python(np.asarray(rectsInput, np.float), 0.5)
      assert len(filteredRects) > 0
      return filteredRects
  
imports: import os, sys
  import numpy
  import cv2
  from utils.rpn.bbox_transform import bbox_transform
  from utils.cython_modules.cython_bbox import bbox_overlaps
label_desc: Use image node_id 3 for calling a global function with example usage: filterRois(rects, img_w, img_h, roi_min_area, roi_max_area, roi_min_side, roi_max_side, roi_max_aspect_ratio) and returns: filteredRects