M
M
mcjohnyx2019-12-06 21:44:18
Algorithms
mcjohnyx, 2019-12-06 21:44:18

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)
plain-00B544.svgplain-FA2B00.svg
Second pair (250, 118, 0) and (2, 139, 152)
plain-FA7600.svgplain-028B98.svg
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

3 answer(s)
V
Vyacheslav Zikran, 2019-12-13
@mcjohnyx

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.

X
xmoonlight, 2019-12-06
@xmoonlight

Here is the resource: https://colorscheme.ru/
There, look at the source code for JS and that's it.

D
dom1n1k, 2019-12-09
@dom1n1k

As soon as you say/find out what principle you called the given colors opposite, it will immediately become easy to find its implementation in the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question