简体   繁体   中英

Grouping/Clustering Rectangles

I have a list of shapes (list of points) eg rectangles which I want to group/cluster together.

This is what I have:

在此处输入图像描述

And this is what I want to achieve.

在此处输入图像描述

How to do it?

I already looked at some clustering techniques, eg, kmeans but it seems there must be a better way.

Thanks!

  1. Select a 'clustering distance' CD , ie the maximum distance between 2 rectangles at which they would be considered a cluster
  2. 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]
  3. Sort all xmin' -s and xmax' -s and select all pairs of rectangles where either xmin' or xmax' of the first is within (xmin', xmax') range of the second; these are the potential clustering targets
  4. Sort all ymin' -s and ymax' -s and check if the pairs from the previous step do indeed intersect; form clusters
  5. Iteratively merge clusters that intersect on at least 1 of the rects they contain; eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM