【问题标题】:Find circles containing only zeros in an arbitrary binary matrix在任意二进制矩阵中查找仅包含零的圆
【发布时间】:2017-04-23 07:51:57
【问题描述】:

给定一个任意大小的二进制矩阵,我需要找到适合这个矩阵并且只覆盖“0”-fields 而没有“-1”-fields 的圆圈。

对于这个例子

1 0 0 0 0 1 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 0 0 0 0 1 1

我想找到以下最大圆(用+表示)

1 0 0 + 0 1 1
1 0 + + + 0 1
1 + + + + + 1
1 0 + + + 0 1
1 0 0 + 0 1 1

其实这不是圆,只是一个近似值。可以借助直方图在这种二进制矩阵中查找矩形,请参阅here。此外,我尝试找到像这样的小圆圈:

1 0 + 0 0 1 1                1 0 0 0 0 1 1
1 + + + 0 0 1                1 0 0 0 0 0 1
1 0 + 0 0 0 1   or this one  1 0 0 + 0 0 1
1 0 0 0 0 0 1                1 0 + + + 0 1
1 0 0 0 0 1 1                1 0 0 + 0 0 1

是否有人对如何识别这些圆(或其离散近似)有一个聪明的想法(如矩形的直方图方法)?

【问题讨论】:

  • 你的圆圈应该是“真实”(圆形)圆圈的近似值还是只是像你的例子中的钻石?
  • 实际上,它们应该是圆形“真实”圆的近似值。
  • @samgak 确实。

标签: algorithm matrix geometry


【解决方案1】:

执行nearest neighbour search,对于每个0 元素到find the closest 1 元素,使用欧几里得距离并创建另一个矩阵来存储从每个元素到最近的1 的距离(或者只跟踪最大的)。

可以容纳最大圆的空间将由与最近邻居距离最大的元素给出,每个元素的距离将指定可以容纳以该元素为中心的空间的圆的大小(距离为 1,表示单个+,距离为 2 表示简单的十字架等)。

请注意,这只适用于以给定元素为中心的圆圈。它不会处理在一个元素和另一个元素之间居中的圆。

【讨论】:

    【解决方案2】:

    第一步: 逐个元素开始迭代

    1.1 : If the element is 0
         1.1.1 : check if it in the border , ie,  row = 0 or row = max_row or col = 0 or col = max_col
         1.1.2 : if not so, check if bottom , top, left and right elements are 0
         1.1.3 : if all are 0, increment radius 
           1.1.4 : else break;
           1.1.5: now check bottom-1, top+1, left-1; right+1 to see if they are 0
           1.1.6: if they are also 0, again increment radius
    
           1.1.7: repeat the above steps till you break
     1.2 : check all elements of matrix
    

    【讨论】:

    • 但是使用这种算法会导致形状看起来像十字,而不像圆形(因为您只检查底部 1、顶部 + 1、左侧 1、右侧 + 1 而不是例如左上角)。
    猜你喜欢
    • 2021-11-03
    相关资源
    最近更新 更多