How to convert RGB code to 8 simple intervals (maybe?)

I am working on my final bachelor's project in computer science, and while I'm at a standstill. Here is what I am stuck:

I am trying to classify any color (rgb code) in any of 8 (eight) simple colors. In short, I need to find 8 intervals where any color can be placed and considered the main color (red, blue, green, black, yellow, purple, gray, brown).

example:
(18,218,23), which will be classified as "green"
(81, 214.85) also "green"
but
(15,52,16) must be black
(110,117,110) should be gray

So there are 256 x 256 x 256 possible colors, and I need to divide them into 8 (intervals) primary colors.

I am waiting for some suggestions.

Greetings!


To be clear (as I saw in the comments), I am looking for a specific set of 8 colors (red, black, green, brown, blue, purple, gray, yellow). Sorry for the orange above!

+4
source share
5 answers

Based on your example, I would start by determining whether all components are approximately the same or stand out. If they are about the same, then decide if the values โ€‹โ€‹are enough to be black or not, then they are gray. If one value is different from the other two, then it's easy to check what the difference is and choose one of six possible colors.

Alternatively, set each component to 0 or 1 according to the threshold, then you have 8 combinations to display 8 colors.

threshold = 100: (18,218,23) -> (0, 1, 0) - to be classified as "green" (81,214,85) -> (0, 1, 0) - also "green" (15,52,16) -> (0, 0, 0) - to be "black" (110,117,110) -> (1, 1, 1) - to be "grey" 
+3
source

Do not do this in RGB, convert HSV into a more convenient color space, probably the easiest way - then 8 "colors" of only 8 intervals along the Hue axis.

+8
source

A simple solution is to make a distance from certain points that you designated as a special color. This is not a complete proof, but it is a simple solution and should work decently.

Long answer: Color spaces are annoying and do not translate labels well.

+3
source

RGB is terrible for this kind of thing, so your first step is to convert the color to Lab color space . You can find many open implementations of this conversion online. As soon as you have your own Lab color, everything will become very simple. Three values โ€‹โ€‹become coordinates in three dimensions, which you can easily separate according to color - check the images in the wikipedia link.

+1
source

Know not too much about the color scheme, but calculating the Euclidean distance will be a good solution.

0
source

Source: https://habr.com/ru/post/1415233/


All Articles