One possibility is to go to HSV colourspace and look for red tones. Reds are harder to find because they straddle 0 and 360 degrees on the Hue/Saturation/Value wheel so I will invert the image and look for cyan which is where red will show up in an inverted image.
#!/usr/bin/env python3
import numpy as np
import cv2
# Load the image as BGR
im = cv2.imread('strip.jpg')
# Invert image, i.e. 255-im, to make reds into cyan and convert to HSV
hsv = cv2.cvtColor(255-im, cv2.COLOR_BGR2HSV)
# Set low and high limit for the tones we want to identify - based on Hue of cyan=90 in OpenCV
lo = np.uint8([80,30,0])
hi = np.uint8([95,255,255])
# Mask all red pixels
mask = cv2.inRange(hsv,lo,hi)
# Save mask for fun
cv2.imwrite('result1.png',mask)
That gives this:
Carrying on with the code, we now apply that mask to the original image to blacken uninteresting pixels:
# Zero out to black all uninteresting pixels in original image
im[mask<255] = 0
cv2.imwrite('result2.png',im)
# Reshape as a tall column of R, G, B values and find unique rows, i.e. unique colours
unique = np.unique(im.reshape(-1,3), axis=0)
print(unique)
That gives around 700 RGB triplets. Carrying on, grab the unique colours and write to an image so we can see them:
# This line is a hack based solely on the current image just for illustration
cv2.imwrite('unique.png',unique[:625,:].reshape((25,25,3)))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…