I have a set of rectangles, usually parallel with each other (but it is not guaranteed). These rectangles usually do not overlap. I have attached an example below. It is actually a byproduct of OCR output, where the detected text has been replaced by bounding boxes.
I would like to consolidate these rectangles into bigger rectangles. The resulting rectangle could not overlap. The grouping could look as follows:
What is the best way to do it? I could not find previous answers on Stackoverflow:
- Group rectangles in a grid does not apply here
- Find k rectangles so that they cover the maximum number of points. I am not sure it applies in my case.
- Intersection of N rectangles mentions R-Trees. But not sure R-Trees can solve the problem.