[英]How to determine bounding rectangles of multiple elements?
我想实现一个算法,它将找到轮廓的边界矩形(已经由另一个算法确定)。 我唯一拥有的是二值化图像(如下图所示)。 基本想法是:
采取这样的事情 - 预处理的二值化图像
并产生这样的东西
查看连接组件标签: http : //en.wikipedia.org/wiki/Connected-component_labeling 。 在这种情况下,您可以找到白色像素或黑色像素的连接组件(由于图像中的白点较少,白色在计算上更容易)。
我可以建议一个天真的方法开始:
在图像中,对图像中的中间点(x,y)进行二维二分搜索。 从那时起,执行洪水填充。
如果填充图形的边界不是图像的边界,那么您找到了一个封闭的图形,因此找到了它的边界框。
如果它填满整个图像,那么你什么也没有,所以将图像分成四个cuadrants并递归地执行相同的操作。 (您不需要检查落在先前找到的边界框图内的点,在此过程中切断搜索空间)。
对于每个元素:
They highest y - 1 is the top of the rectangle.
The leftmost x - 1 is the left of the rectangle.
The lowest y + 1 is the bottom of the rectangle.
The rightmost x + 1 is the right of the rectangle.
注意最高我的意思是最接近屏幕顶部而不是最大值。
看起来OpenCV有一些算法可以找到已经实现的轮廓的边界框。 因此,研究他们的功能如何运作可能是一个很好的开始。 http://opencv.itseez.com/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
您可以计算最小生成树并删除最长边。 然后你可以计算k均值。 删除另一条长边并计算k均值。 冲洗并重复,直到N = 10。 我相信这个算法被命名为单链路k-means,集群类似于voronoi图:
“单链路k聚类算法......正是Kruskal的算法......相当于找到MST并删除k-1最昂贵的边缘。”
例如,请参阅: https : //stats.stackexchange.com/questions/1475/visualization-software-for-clustering
然后,对于每个群集,您应用此规则:
They highest y - 1 is the top of the rectangle.
The leftmost x - 1 is the left of the rectangle.
The lowest y + 1 is the bottom of the rectangle.
The rightmost x + 1 is the right of the rectangle.
注意最高我的意思是最接近屏幕顶部而不是最大值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.