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

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

问题描述

 ; x => 

我有一个像下面这样的图像的网格, (黑色单元格和灰色框),s =开始(红色圆圈),g =目标(蓝色圆圈),0 =可用路径(其他所有内容)
$ 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]]



我想我可以使用颜色,但我不知道如何。

>看起来像是有固定角度的视图



创建将屏幕位置转换为网格位置并返回的功能。应该很容易,只需 2x 线性插值。如果相机平底锅不是基于单元格的步骤,那么你需要网格线的角点,并将其用作开始点...

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

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




  • 60,30 是单元格大小在 x,y

  • (236,133)是中间单元中心的位置(uh,vh)以像素为单位

  • uh,vh 是坐标中心单元格的网格坐标
    $ b $ p $将视图平移偏移量添加到(uv, hv)(236,133)现在只需计算这个(u =?,v =? )。不要忘记地图不是矩形的!它是这样的:

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

    li>

  • 创建一组您可以遇到的所有对象的图像

    这可以完成在运行时,每次没有找到匹配项时,都会将单元格添加到项目列表中作为新的对象类型。


  • 遍历所有网格单元格位置与对象类型比较



    对于像素精确的渲染图像,您可以直接比较像素 1:1 ,如果不是这种情况你需要更强大的比较对象。但要制定一个有效的算法,我们需要查看所有可以遇到的对象类型,通常您可以比较:


    1. 平均值,最小值和最大值颜色,直方图,
    2. 宽高比,...
    3. FFT / DCT

    4. 质心位置,密度以及更多

    不要忘记屏蔽与单元格区域的比较而不包括边界矩形边角上的相邻单元


  • [注意]



    如果没有更多信息,不能更具体。


    I have a grid like the image below which 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"]]
    

    I thought I could use the colors but I'm not sure how.

    解决方案

    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

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

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