【发布时间】:2021-02-10 04:37:27
【问题描述】:
我有一个带有颜色分割的图像,我想从 BGR 颜色列表中找到具有颜色的像素。从这些像素索引中,我想用一些任意值填充二维数组。我已经完成了,但是速度非常慢:
#load image with color segmentations
img = cv2.imread(segmented_img_path)
#create empty output array
output = np.zeros((img.shape[0], img.shape[1]))
#iterate over image and find colors
for i, row in enumerate(img):
for j, bgr in enumerate(row):
if np.any(np.all(np.isin(np.array(color_list),bgr,True),axis=1)):
output[i,j] = float(some_value)
必须有一种更快的方法来做到这一点,可能使用 np.where 但我就是想不通。
【问题讨论】: