'Grouping/Clustering Rectangles
Solution 1:[1]
- Select a 'clustering distance'
CD, i.e. the maximum distance between 2 rectangles at which they would be considered a cluster - Compute a second set of rects, each of which correspond to their source rects as follows:
[xmin', ymin', xmax', ymax'] = [xmin - CD/2, ymin - CD/2, xmax + CD/2, ymax + CD/2] - Sort all
xmin'-s andxmax'-s and select all pairs of rectangles where eitherxmin'orxmax'of the first is within(xmin', xmax')range of the second; these are the potential clustering targets - Sort all
ymin'-s andymax'-s and check if the pairs from the previous step do indeed intersect; form clusters - Iteratively merge clusters that intersect on at least 1 of the rects they contain; e.g. cluster
(rect #3, rect #10)and cluster(rect #10, rect #7)are to be merged, thus becoming a(rect #3, rect #7, rect #10)cluster
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


