如何确定多个元素的边界矩形?
我想实现一种算法,该算法将找到轮廓的边界矩形(已由另一种算法确定)。我唯一拥有的是二值化图像(如下所示)。基本思想是:
采用这样的东西 - 预处理的二值化图像
并生成类似的内容
I would like to implement an algorithm which will find the bounding rectangles of contours (already determined by another algorithm). The only thing I have is a binarized image (as shown below). The basic idea would be to :
take something like this - a preprocessed binarized image
and produce something like this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看连接组件标签:http://en.wikipedia.org/wiki/Connected-component_labeling。在这种情况下,您可以找到白色像素或黑色像素的连通分量(白色在计算上更容易,因为图像中的白点较少)。
Check out connected component labeling: http://en.wikipedia.org/wiki/Connected-component_labeling . You can either find connected components of white pixels or black pixels in this case (White is computationally easier since you have fewer white points in the image).
我可以建议一个简单的开始方法:
在图像中,对图像中的中间点 (x,y) 进行 2D 二分搜索。
从那时起,执行洪水填充。
如果填充图形的边界不是图像的边界,那么您找到了一个闭合图形,因此找到了它的边界框。
如果它填满了整个图像,那么你什么也没击中,所以将图像分成四个象限并递归地执行相同的操作。 (您不需要检查落在先前找到的边界框图形内的点,从而在此过程中削减您的搜索空间)。
May I suggest a naive approach for a start:
In the image, do a 2D binary search for a middle point in the image (x,y).
From that point, perform a flood fill.
if the bounds of the filled figure are not those of the image, then you found a closed figure, and therefore its bounding box.
if it fills the whole image, then you hitted nothing, so divide the image in four cuadrants and do the same recursively. (You don't need to check for points that fall inside a previously found bounding box figure, cutting your search space in the process).
看起来 OpenCV 已经实现了一些用于查找轮廓边界框的算法。因此,研究它们的功能如何工作可能是一个很好的开始。
http://opencv.itseez.com/doc/tutorials/imgproc /shapeescriptors/bounding_rects_circles/bounding_rects_circles.html
It looks like OpenCV has some algorithms for finding the bounding box of a contour already implemented. So looking into how their function works might be a good way to start.
http://opencv.itseez.com/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
对于每个元素:
注意最高值是指最接近屏幕顶部的值,而不是最大值。
For each element:
Note by highest I mean closest to the top of the screen not the greatest value.
您可以计算最小生成树并删除最长的边。然后您可以计算 k 均值。删除另一条长边并计算 k 均值。冲洗并重复,直到 N=10。我相信这个算法被命名为单链接 k 均值,并且聚类类似于 voronoi 图:
“单链接 k 聚类算法......正是 Kruskal 算法......相当于找到一个 MST 并删除 k- 1 个最昂贵的边。”
例如,请参见此处: https://stats.stackexchange.com/questions/1475/visualization-software -for-clustering
然后,对于每个集群,应用此规则:
注意,最高值是指最接近屏幕顶部的值,而不是最大值。
You can calculate a minimum spanning tree and remove the longest edges. Then you can calculate the k-means. Remove another long edge and calculate the k-means. Rinse and repeat until you have N=10. I believe this algorithm is named single-link k-means and the cluster are similar to voronoi diagrams:
"The single-link k-clustering algorithm ... is precisely Kruskal's algorithm ... equivalent to finding an MST and deleting the k-1 most expensive edges."
See for example here: https://stats.stackexchange.com/questions/1475/visualization-software-for-clustering
Then for each cluster you apply this rule:
Note by highest I mean closest to the top of the screen not the greatest value.