我想索引 RGB 图像中的一些特定像素。我对 Python 比较陌生,所以我已经实现了索引,就像我在 Java/C# 中所做的那样。
这是代码:
# Pane width (height)
pane_step, center = 20, 10
for i in range(0, field_size * pane_step, pane_step):
for j in range(0, field_size * pane_step, pane_step):
r, g, b, = img[i + center, center + j, :]
if (r, g, b) == (255, 0, 0):
grid[int(i / pane_step)][int(j / pane_step)] = 2
elif (r, g, b) == (0, 128, 0):
grid[int(i / pane_step)][int(j / pane_step)] = 1
elif (r, g, b) == (0, 0, 0):
grid[int(i / pane_step)][int(j / pane_step)] = -1
有没有更快、更“pythonic”的方法可以给我同样的结果?
互换的青春
相关分类