I made a algorithm for color detection. Basically, what it does it extracts the main colors of a clothing item. the main issue I’m having is that the model is having issue detecting color outside of blue:
[enter image description here](https://i.sstatic.net/mB66oEDs.png)enter image description here
the algorithm use for color clustering is the Peter Hansen method.
the algorithm I’m using for the retrieval of color names is the following:
def closest_color(requested_color):
TOP_COLORS = {
‘black’: (0, 0, 0),
‘white’: (255, 255, 255),
‘red’: (0, 0, 255),
‘blue’: (255, 0, 0),
‘green’: (0, 128, 0),
‘yellow’: (0, 255, 255),
‘orange’: (0, 165, 255),
‘pink’: (203, 192, 255),
‘purple’: (128, 0, 128),
‘brown’: (42, 42, 165),
‘gray’: (128, 128, 128),
‘navy’: (128, 0, 0),
‘lime’: (0, 255, 0),
‘fuchsia’: (255, 0, 255),
‘silver’: (192, 192, 192),
‘gold’: (0, 215, 255),
‘khaki’: (140, 230, 240),
‘turquoise’: (208, 224, 64),
‘violet’: (238, 130, 238),
‘indigo’: (130, 0, 75),
‘coral’: (80, 127, 255),
‘chocolate’: (30, 105, 210),
‘darkblue’: (139, 0, 0),
‘darkcyan’: (139, 139, 0),
‘darkgreen’: (0, 100, 0),
‘darkred’: (0, 0, 139),
‘midnightblue’: (112, 25, 25),
‘lightblue’: (230, 216, 173),
‘lightgreen’: (144, 238, 144),
‘lightgray’: (211, 211, 211),
‘lightpink’: (193, 182, 255),
‘lightyellow’: (224, 255, 255),
}
min_distance = float('inf')
closest_color_name = None
for color_name, rgb in TOP_COLORS.items():
distance = np.sqrt((rgb[0] - requested_color[0]) ** 2 +
(rgb[1] - requested_color[1]) ** 2 +
(rgb[2] - requested_color[2]) ** 2)
if distance < min_distance:
min_distance = distance
closest_color_name = color_name
return closest_color_name
I will apricate if anybody has a recommendation for this model on how to get more accurate responds for brighter colors