Answer the question
In order to leave comments, you need to log in
Is there a formula or method for determining the opposite color?
Hello.
I am writing a program to work with an image.
The program takes an image and uses the k-means algorithm to find a common color (remembers the color value in rgb). And then, using a formula or method, or even some algorithm, he must determine the opposite color to this color, so that later the written text is clearly visible. What will be your assumptions?
*No need to offer any schemes, etc. I need the program to determine the color itself.
Here are examples of opposite colors:
First pair (0, 181, 68) and (250, 43, 0)
Second pair (250, 118, 0) and (2, 139, 152)
You get the idea.
You can even write your work in any language. I care about the essence.
Thanks in advance
Answer the question
In order to leave comments, you need to log in
To find the opposite color, you can do the following:
- convert the RGB values to the HSL color model
- rotate the H value by 180 degrees (if H < 180, then add 180, if H > 180, then subtract)
- convert back to the RGB model.
Here is the resource: https://colorscheme.ru/
There, look at the source code for JS and that's it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question