从图像(填充形状)生成多边形 [英] Generating Polygons from Image (Filled Shapes)

查看:184
本文介绍了从图像(填充形状)生成多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从预处理的世界地图生成多边形, 到目前为止,我所做的是:

I'm trying to generate polygons from a preprocessed world map, What i have done so far is:

1:为每个国家/地区生成了等高线图,如下所示:

1: Generated a contour map for each of the countries, it looks like this:

  1. 从这里开始,我用以下任意颜色填充了每个国家/地区的颜色:
  1. From here i filled each of these countries with an random color like this:

到目前为止,我还是试图在countour图像中选择一个随机像素,然后沿着这条线移动,直到我到达起点为止.这确实给了我一个相对不错的结果,在多边形上的准确率没有达到90%,但是有些国家却完全消失了.

So far ive tried to just select a random pixel in the countour image and followed the line around until i hit the start point. This did give me a relatively good result, without about 90% accuracy on the polygons, However some countries dissapeared totally.

所以我想做的是在地图中以排序的方式为每个国家/地区拥有一个坐标数组,以便可以将其表示为多边形.有人知道如何实现这一目标吗?

So what i wish to do is to have a array of coordinates for each of the countries in this map in a sorted manner so it can be represented as a Polygon. Do anyone know how to achieve this?

我没有找到适合我问题的算法.

I have not found any algorithms suited for my problem.

谢谢!

推荐答案

那里有矢量化工具,但是如果您想对其进行编码(这是一项艰巨的任务),请执行以下操作:

there are vectorizing tools out there but if you want to code it (it is a hard task) do this:

  1. 扫描图像中的黑点

将所有点存储在(x,y)坐标的某些list

store all points in some list of (x,y) coordinates

将连接信息添加到所有点

如果编码不正确,这将需要大量内存,因此请添加将每个点连接到的点的分组信息(记住只是索引).

this will need huge amount of memory if not coded properly so add grouping info to which points is each point connected (remember just indexes).

添加用法标记以指向点

在关节之间找到折线

关节是点,其连接点多于2个连接点,所以

joint is point with more then 2 connected points so

  1. 找到这样的点i
  2. 遍历其连接点,直到命中另一个联接点j,而没有两次遍历任何点.这就是为什么您需要使用标志.将此路径存储为polyline
  1. find such point i
  2. go through its connected points until another join point j is hit without going twice through any point. That is why you need the usage flag. Store this path as polyline

  • 发现闭环

    它与#4 类似,但是您需要逐步完成polylines才能回到起点.记住polylinespolygons

    It is similar to #4 but you need to step through polylines to go back to the start point. Remember polylines as polygons

    因此,您将需要类似于以下的结构:

    So you will need structures similar to this:

    struct pnt
     {
     int x,y; // coordinate fo point
     int used; // usage flag for later use
     List<int> ix; // list of indexes of all points connected to this point
     };
    
    struct polylin
     {
     List<int> ix; // list of point indexes
     };
    
    struct polygon
     {
     List<int> lin; // list of polyline indexes
     List<int> dir; // direction of polyline (forward/backward)
     };
    
    List<pnt> pnts;
    List<polylin> plins;
    List<polygon> faces;
    

    如果图像点内部有孔,则需要通过其他图像处理或找到具有一定距离的连接点来处理它们.

    If your image points has holes inside then you will need to handle them by additional image processing or by connected points finding with some treshold distance.

    这篇关于从图像(填充形状)生成多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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