【发布时间】:2019-06-03 14:32:38
【问题描述】:
所以,基本上我有一个包含 16 个 RGB 颜色值的数组,我必须计算输入图像中像素的 RGB 值与所有这 16 个颜色值之间的距离。距离较小的 RGB 值将是输出图像中的 RGB 值。
问题是:我使用嵌套的 for 循环来执行这些操作,而且它真的很慢。摘录如下:
for i in range (row):
for j in range (columns):
pixel = img[i, j]
for color in colorsarray:
dist.append(np.linalg.norm(pixel - color))
img[i,j] = colorsarray[dist.index(min(dist))]
dist.clear()
有没有 numpy 函数可以帮我优化这个?
【问题讨论】: