1 year ago

#309906

test-img

4u Don

I would like to know the nearest or the closest rgbvalues base on 9 rgb color range

i know there are similar question like this one. Find closest RGB color for every pixel in image

But mine is i want to know base on the range of the color.

#the brighter values of colors
low_color = [(0, 0, 0),         #black
                (0, 90, 10),      #brown
                (255, 0, 0),       #red
                (211, 104, 62),     #orange
                (255, 255, 0),     #yellow
                (0, 255, 0),       #green
                (0, 0, 255),       #blue
                (200, 0, 255),     #violet
                (128, 128, 128),   #gray
                (255, 255, 255)]   #white

#the darker values of colors
high_color = [(179, 255, 93),      #black
              (15, 250, 100),      #brown
              (204, 0, 0),       #red
              (199, 90, 57),     #orange
              (255, 204, 102),  #yellow
              (6, 85, 28),      #green
              (40, 73, 86),      #blue
              (110, 0, 51),      #violet
              (73, 65, 62),      #gray
              (250, 250, 250)]   #white

how would i check the color base on these ranges(c[0],c[1]) using rgbvalues only. I would like to know the index where the color is best matched of.

ex. if the sought out color is rgb=(93, 30, 38) it should select the 2nd index(brown)

def findNearest(rgb):
    dist = ((low_color[0][0]-rgb[0])*0.3)**2 + ((low_color[0][1]-rgb[1])*0.59)**2 + ((low_color[0][2]-rgb[2])*0.11)**2
    index = 0
    for i in range(1,len(high_color)):
        d = ((low_color[i][0]-rgb[0])*0.3)**2 + ((low_color[i][1]-rgb[1])*0.59)**2 + ((low_color[i][2]-rgb[2])*0.11)**2
        if d < dist:
            dist = d
            index = i
    return low_color[index]

python

opencv

image-processing

colors

color-detection

0 Answers

Your Answer

Accepted video resources