算法来计算集箱通过离散轮廓边界的 [英] Algorithm to compute set of bins bounded by a discrete contour

查看:191
本文介绍了算法来计算集箱通过离散轮廓边界的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在离散基于网格的面(认为:图像的像素),我有一个封闭的轮廓,可以EX pressed无论是:

On a discrete grid-based plane (think: pixels of an image), I have a closed contour that can be expressed either by:

  • 一组二维点(X1,Y1)(X2,Y2);(X3,Y3); ...
  • 或4连弗里曼code ,有一个起点点:(X1,Y1)+ 00001112 ...
  • a set of 2D points (x1,y1);(x2,y2);(x3,y3);...
  • or a 4-connected Freeman code, with a starting point: (x1,y1) + 00001112...

我知道如何从一个切换到另一个这些重presentations的。这将是在输入数据

I know how to switch from one to the other of these representations. This will be the input data.

我想获得一套网格坐标是的轮廓。 考虑这个例子,其中红的坐标的轮廓,而灰色一个起点:

I want to get the set of grid coordinates that are bounded by the contour. Consider this example, where the red coordinates are the contour, and the gray one the starting point:

如果灰色的坐标,比方说,在(0,0),那么我想一个向量控股: (1,1),(2,1),(3,1),(3,2)

If the gray coordinate is, say, at (0,0), then I want a vector holding: (1,1),(2,1),(3,1),(3,2)

顺序并不重要,并输出向量也可以容纳在轮廓本身

Order is not important, and the output vector can also hold the contour itself.

选择的语言是C ++,但我开到任何现有的code,算法,图书馆,指针,无论...

Language of choice is C++, but I'm open to any existing code, algorithm, library, pointer, whatever...

不过,我觉得,也许 CGAL 会有这样的事情,但我不熟悉它,找不到我的方式,通过手工,所以我甚至不知道。 我也看了朝 opencv的,但我认为它不提供这个算法(但我可能是错的?)。

I though that maybe CGAL would have something like this, but I am unfamiliar with it and couldn't find my way through the manual, so I'm not even sure. I also looked toward Opencv but I think it does not provide this algorithm (but I can be wrong?).

我在想找到边框,然后检查每个在矩形的点,看看他们是的内/外,但这似乎不理想。你知道吗?

I was thinking about finding the bounding rectangle, then checking each of the points in the rectangle to see if they are inside/outside, but this seems suboptimal. Any idea ?

推荐答案

要解决这个问题的方法之一是<一个href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=drawcontours#drawcontours"相对=nofollow> drawContours ,你有轮廓点你。

One way to solve this is drawContours, and you have contours points with you.

  1. 创建空白垫,并绘制轮廓厚度= 1(边界)。
  2. 创建另一张空白垫,并绘制轮廓与厚度= CV_FILLED(整个地区,包括边界)。
  3. 现在, bitwise_and 上述两个(你得到的填充的区域不包括边界)。
  4. 最后检查非零像素。
  1. Create blank Mat and draw contour with thickness = 1(boundary).
  2. Create another blank Mat and draw contour with thickness = CV_FILLED(whole area including boundary).
  3. Now bitwise_and between above two(you got filled area excluding boundary).
  4. Finally check for non-zero pixel.

这篇关于算法来计算集箱通过离散轮廓边界的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆