从矩阵获取区域/区域边界
对我来说,我有一个非常基本的需求:提取组成矩阵的区域的坐标。
让我举个例子。这是一些矩阵:
| A | B | D | E | F | G | H | I | J |
| 1 | 0 | 0 | 0 | 2 | 2 | 2 | 4 | 4 | 4 |
| 2 | 0 | 0 | 2 | 2 | 2 | 2 | 4 | 4 | 4 |
| 3 | 0 | 0 | 2 | 2 | 2 | 3 | 3 | 4 | 4 |
| 4 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 5 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 6 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 7 | 1 | 0 | 0 | 0 | 1 | 1 | 3 | 0 | 4 |
| 8 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 9 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 10| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
我想获得一个包含每个区域的边界和值的数组(不需要特定的顺序)。
左上角区域的示例:
- 值:0
- 边界:{A1,D1,B2,B3,13}
您知道有一些库可以满足此需求还是我应该自己编写代码?
Sounds to me I've a very basic need: extracting coordinates of the zones composing a matrix.
Let me give an example. Here is some matrix:
| A | B | D | E | F | G | H | I | J |
| 1 | 0 | 0 | 0 | 2 | 2 | 2 | 4 | 4 | 4 |
| 2 | 0 | 0 | 2 | 2 | 2 | 2 | 4 | 4 | 4 |
| 3 | 0 | 0 | 2 | 2 | 2 | 3 | 3 | 4 | 4 |
| 4 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 5 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 6 | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 |
| 7 | 1 | 0 | 0 | 0 | 1 | 1 | 3 | 0 | 4 |
| 8 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 9 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 10| 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
And I'd like to get an array with the boundaries and value of each zone (no particular order needed).
Example for the top-left zone:
- value: 0
- boundaries: {A1, D1, B2, B3, 13}
Do you know some library answering this need or should I code this myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己编写代码,不确定是否有库。
我会针对每个区域依次考虑每个点。那么(我认为)这应该可行:
将越界方块视为不同的。
I'd code this myself, not sure if there are libraries.
I'd consider each point in turn, for each region. Then (i think) this should work:
Treat out of bounds squares as different.