我希望实现一个算法,该算法将找到轮廓的边界矩形(已由另一个算法确定)。我只有一张二值化图像(如下所示)。基本思路是:
取这样的东西 - 预处理的二值化图像
并生成这样的东西
取这样的东西 - 预处理的二值化图像
并生成这样的东西
查看连通组件标记:http://en.wikipedia.org/wiki/Connected-component_labeling。在此情况下,您可以查找白色像素或黑色像素的连接组件(由于图像中白点较少,因此白色更易于计算)。
我可以建议一个简单的方法来开始:
在图像中,进行二维二分搜索以找到图像中间点(x,y)。 从该点开始执行泛洪填充。
如果填充图形的边界不是图像的边界,则找到了一个封闭图形,因此找到了其边界框。
如果它填充整个图像,则表示未找到任何内容,因此将图像分成四个象限并递归执行相同操作。(您无需检查落在先前找到的边界框图形内的点,从而缩小搜索空间)。
看起来OpenCV已经实现了一些用于查找轮廓边界框的算法。因此,研究他们的函数如何工作可能是一个很好的开始方式。 http://opencv.itseez.com/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
对于每个元素:
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.
请注意,我所说的“最高”是指靠近屏幕顶部的位置,而不是最大值。
“单链接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.
注意,我所说的“最高”是指靠近屏幕顶部而不是最大值。