Converting rgb values to a color name

I have managed to get an averaged single RGB color values for given image, by help of this. And the resulting table is:

Now I want to classify values under 3 or 4 different colornames, like, yellow, blue, grey or red (above table is falling into yellow for example), into an additional column. Is it possible? (I am afraid I do not know javascript).

Hi @rogerwilco

my naive approach would be to create new columns with the rgb values of your colors (yellow, blue,…). Then you compute the differences between your image’s colors and these values and decide for the color with the lowest difference.

r206 g189 b85 (in your table)
difference to yellow (r255 g255 b0): r49 + g66 + b85 = 200
difference to blue (r0 g0 b255): r206 + b189 + b170 = 565
difference to grey (r128 g128 b128): r78 + g61 + b43 = 182

But as you see this does not work very well. Your yellow would be categorized as “Gray”. RGB does not really work that well for that. I found somebody on stackoverflow suggesting to convert to HSV for that purpose. You could use a ColorSpace converter for that.


Hi @johannes.schweig

Thank you for the answer it helped a lot, after rgb->hsb conversion, the table is now looks like;

This seems a good separation, since row0 and row2 is yellow images, and row1 and row3 is bluish images. For the moment, I want to go for these two colors only. Final aim is writing “image_filename,yellow” lines to a csv file. What can be the next step? I could not find a way to apply;

"if Col1+Col2+Col3 < 80 then col4= “blue”

Hi @rogerwilco,

have a look at the Rule Engine node, which is able to apply such rules.

I order to do that, you can just use a CSV Writer node.


1 Like

Hi @DaveK,

Thanks for this, adding ->Math_formula->Rule Engine->CSV writer nodes solved the problem.


Now I am wondering If this could be classified with a classifier? (Joke! thanks!)

Hi @rogerwilco,

glad I could help.

Sure, just use your table as a training set for e.g. the Decision Tree Learner node :wink:



1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.