如何确定多个元素的边界矩形?

发布于 2024-12-27 03:09:07 字数 263 浏览 1 评论 0原文

我想实现一种算法,该算法将找到轮廓的边界矩形(已由另一种算法确定)。我唯一拥有的是二值化图像(如下所示)。基本思想是:

  • 采用这样的东西 - 预处理的二值化图像 在此处输入图像描述

  • 并生成类似的内容 在此处输入图像描述

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
    enter image description here

  • and produce something like this
    enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

迷荒 2025-01-03 03:09:07

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).

拍不死你 2025-01-03 03:09:07

我可以建议一个简单的开始方法:

在图像中,对图像中的中间点 (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).

书信已泛黄 2025-01-03 03:09:07

看起来 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

陌路黄昏 2025-01-03 03:09:07

对于每个元素:

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.

注意最高值是指最接近屏幕顶部的值,而不是最大值。

For each element:

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.

Note by highest I mean closest to the top of the screen not the greatest value.

思慕 2025-01-03 03:09:07

您可以计算最小生成树并删除最长的边。然后您可以计算 k 均值。删除另一条长边并计算 k 均值。冲洗并重复,直到 N=10。我相信这个算法被命名为单链接 k 均值,并且聚类类似于 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.

注意,最高值是指最接近屏幕顶部的值,而不是最大值。

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:

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.

Note by highest I mean closest to the top of the screen not the greatest value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文