简体   繁体   English

获取嵌入在矩阵中的多边形的边界和其他后处理技术

[英]obtaining boundary of polygon embedded in a matrix and other post-processing techniques

I have a 100x100 Boolean matrix called mat . 我有一个名为mat的100x100布尔矩阵。 All cells have false value except a continuous patch of polygonal area. 除了连续的多边形区域之外,所有像元均具有假值。 I can read the cells belonging to this polygon by running through each cell of the matrix and finding true cells. 通过遍历矩阵的每个单元并找到真实的单元,可以读取属于该多边形的单元。

region_of_interest=false(size(mat));
for i=1:size(mat,1)
    for j=1:size(mat,2)
        if mat(i,j)
            region_of_interest(i,j)=true;
        end
    end
end

Now I want to do further processing of this polygon like store only the boundary cells. 现在,我想对该多边形进行进一步处理,例如仅存储边界单元。 How to do this? 这个怎么做? I tried visiting each polygonal cell and seeing if all its four neighbors are in the polygon or not. 我尝试访问每个多边形单元,并查看其所有四个邻居是否都在多边形中。 But this did not seem very efficient. 但这似乎不是很有效。 Are there better algorithms out there? 有更好的算法吗?

If there are other post-processing methods that can be run in this scenario please suggest. 如果在这种情况下还有其他可以运行的后处理方法,请提出建议。 Suggestions outside of Matlab are also welcome. 也欢迎在Matlab之外提出建议。

This is neither Python nor a convex-hull problem. 这既不是Python也不是凸包问题。

However, I would point out that boundary cells inside the polygon are true and have at least one neighbor which is false, and boundary cells outside the polygon are false and have at least one neighbor which is true. 但是,我要指出,多边形内部的边界单元是真实的,并且至少有一个为假的邻居,多边形外部的边界单元是假的,并且具有至少一个为真的邻居。

It's up to you to decide whether you want inner or outer boundary cells, and what a "neighbor" is. 由您决定是要使用内部边界单元还是外部边界单元,以及“邻居”是什么。 For example, are the neighbors of a cell the four neighbors in cardinal directions, or the eight neighbors in diagonal directions too? 例如,一个单元的邻居是基数方向上的四个邻居,还是对角线方向上的八个邻居? If it's the former, then you'll still have to search through the eight neighbors to use the algorithm I describe below to get from cell 1 to cell 2 in cases like the following: 如果是前者,则在以下情况下,您仍然必须搜索八个邻居以使用我在下面描述的算法从单元1到单元2进行计算:

...XX
...2X
XX1XX
XXXXX

That being said, it would depend on what your data is like as to how you'd want to write the algorithm. 话虽如此,这取决于您的数据是什么样的,以及您要如何编写算法。 If you know that there is a single contiguous block with no holes in it, which seems to be what your question implies, then once you find a boundary cell, you simply need to walk along the boundary until you find the first cell again. 如果您知道其中有一个没有孔的连续块,这似乎是您的问题所隐含的含义,那么一旦找到边界单元,您只需要沿着边界走,直到再次找到第一个单元。 So search neighbors until you find the next boundary cell, and then do it again. 因此,搜索邻居,直到找到下一个边界单元,然后再次进行。

The problem is finding that first boundary cell. 问题是找到第一个边界单元。

One method would be just searching randomly until you find a cell within the patch, and, then walking in any direction until you find a boundary. 一种方法是随机搜索,直到找到补丁中的一个单元,然后沿任何方向行走,直到找到边界。

Another would be to do some sort of uniform search, perhaps in a grid, until you find that same first cell as described above. 另一种方法是在网格中进行某种统一的搜索,直到找到与上述相同的第一个单元格。 If you know that your patch size is always at least x-cells large, you could adjust your grid size based on that. 如果您知道补丁大小始终至少为x-cell大,则可以基于此调整网格大小。

Without more specific information, these ideas should at least help you reach a solution. 如果没有更多具体信息,这些想法至少应该可以帮助您找到解决方案。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM