I have an image with color segmentations and I want to find the pixels that have a color from a list of BGR colors. From those pixel indexes I want to fill a 2D array with some arbitrary value. I've accomplished this but it is terribly slow:
#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)
There's got to be a faster way of doing this, probably using np.where but I just can't figure it out.