2D图像格值二维数组 [英] 2D grid image values to 2D array

查看:215
本文介绍了2D图像格值二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2D网格像下面的图像的图像,我希望把这种格式的数组。

 ; X =壁(黑色细胞和灰色框),S =启动(红圈),G =目标(蓝圈),0 =可用路径(一切)
 $数据[5] [5] = [[×,×,×,×,×]​​,_
               [×,S,0,×,×]​​,_
               [×,×,0,×,×]​​,_
               [×,×,0,G,×]​​,_
               [×,×,×,×,×]​​]

任何想法我怎么能做到这一点?什么是有用的。
我艰难的我也许可以使用的颜色,但我真的不知道如何做到这一点。

我是新来的AutoIt所以让我知道如果我需要添加任何东西。


解决方案

  1. 看起来你有固定角度的看法

    创建函数,它的屏幕位置转换为网格位置和背部。它应该很容易只是 2 线性插值。如果相机锅不与基于细胞的步骤则需要的网格线的角点和使用,作为一个开始点...

    例如像这样(希望我正确测量像素):

      X = 236 +(+(U-嗯) - (V-VH))* 60;
    Y = 133 +( - (U-嗯) - (V-VH))* 30;


    • 60,30 X中的单元格大小,Y

    • (236133)是中期细胞的中心位置(UH,VH)像素

    • UH,VH 在你的中心单元的网格坐标

    补充意见泛偏移(UV,HV)(236133)现在只是计算的还从这个反向变换(U =?v =?)。不要忘了,地图是不是长方形!它是这样的:

      0000x0000,
        000xxx000,
        00xxxxx00,
        0xxxxxxx0,
        XXXXXXXXX,
        0xxxxxxx0,
        00xxxxx00,
        000xxx000,
        0000x0000,


  2. 创建一组的所有物体的图像,你可以遇到

    这可以在运行完成后,每次都没有找到匹配增加细胞项目列表作为新的对象类型的时间。


  3. 遍历所有网格单元的位置,并比较对象类型

    像素precise渲染的图像可以比较直接像素的 1:1 :如果这是不是你需要更有力地比较对象的情况。但是,为了使一个有效的算法,我们需要看到所有类型的对象通常可以遇到你可以比较:


    1. 平均值,最小值和最大值的色彩,柱状图,

    2. 长宽比,...

    3. FFT / DCT

    4. 群众的位置,密度的中心,多

    不要忘了掩饰比较单元的面积只有不包括边框角落相邻小区


【注意事项】

不能没有进一步的信息更具体

I have an image containing a 2D grid like the image below and I want to put in an array in this format.

 ;x = wall(black cells and grey boxes), s= start (red circle), g = goal(blue circle), 0 = available path(everything else)
 $data[5][5] = [["x","x","x","x","x"], _
               ["x","s","0","x","x"], _
               ["x","x","0","x","x"], _
               ["x","x","0","g","x"], _
               ["x","x","x","x","x"]]

Any ideas how I could do that? Anything would be useful. I tough I could maybe use the colors but I'm not really sure how to do this.

I am new to Autoit so let me know if I need to add anything.

解决方案

  1. looks like you have the view with fixed angles

    create function that converts screen position to grid position and back. It should be easy just 2x linear interpolation. if the camera pan is not with cell based step then you need the corner point of grid lines and use that as a start point ...

    for example something like this (hope I measured the pixels correctly):

    x = 236 + (+(u-uh)-(v-vh))*60;
    y = 133 + (-(u-uh)-(v-vh))*30;
    

    • 60,30is the cell size in x,y
    • (236,133) is position of center of mid cell (uh,vh) in pixels
    • uh,vh are coordinates in your grid of center cell

    add the views pan offset to (uv,hv) or (236,133) now just compute the also the reverse transform from this (u=?,v=?). Do not forget that the map is not rectangle! It is something like this:

        0000x0000,
        000xxx000,
        00xxxxx00,
        0xxxxxxx0,
        xxxxxxxxx,
        0xxxxxxx0,
        00xxxxx00,
        000xxx000,
        0000x0000,
    

  2. create a set of images of all objects that you can encounter

    this can be done on the run, each time you do not found a match add cell to item list as new object type.

  3. loop through all grid cell locations and compare to object types

    for pixel precise rendered images you can compare directly pixels 1:1 if that is not the case the you need to compare objects more robustly. But to make a valid algorithm we need to see all the types of object you can encounter usually you can compare:

    1. average,min and max colors, histograms,
    2. aspect ratio,...
    3. FFT/DCT
    4. center of mass position,density, and more

    do not forget to mask comparison to area of cell only to not include the neighboring cells on corners of bounding rectangle

[Notes]

Can not be more specific without further info

这篇关于2D图像格值二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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