我想索引 RGB 圖像中的一些特定像素。我對(duì) Python 比較陌生,所以我已經(jīng)實(shí)現(xiàn)了索引,就像我在 Java/C# 中所做的那樣。這是代碼:# Pane width (height)pane_step, center = 20, 10for 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有沒(méi)有更快、更“pythonic”的方法可以給我同樣的結(jié)果?
更快的 numpy 數(shù)組索引
慕尼黑8549860
2021-07-07 09:06:17