Invert color space for contrast mesh

I have a random colored background, which is divided into solid colored rectangles. I want to draw a grid over the rectangles (this is not a problem). The problem is that due to random colors, I cannot hardcode the color of the mesh, because it may not be displayed.

Another way to think about this is to draw a grid on the surface graph f (x, y). If the color of the grid is the same color of the function (however, it is defined), then it will not be visible.

I would like to take the background color and calculate a new color (shades of gray or a similar background color) that contrasts with the color so that it can be easily seen (but not distract, for example, pure white on black).

I tried using brightness and weighted brightness, but it does not work well for all colors. I also tried gamma color correction, but it also does not work.

I would also like the mesh color to be as uniform as possible (I could calculate the adjacent mesh colors for blending). This is not so important, but it would be nice to have some uniformity.

The code I'm working with is based on

//byte I = (byte)(0.2*R + 0.7*G + 0.1*B);
//byte I = (byte)(R + G + B)/3.0);
byte I = (byte)(Math.Max(Bar.Background.R, Math.Max(Bar.Background.G, Bar.Background.B)));

if (I < 120) 
    I = (byte)(I + 30); 
else 
    I = (byte)(I - 30);
//I = (byte)(Math.Pow(I/255.0, 1/2.0)*255);

I also tried rgb gamma correction.

Does anyone have any ideas?

+3
source share
1 answer

The colors that offer the most contrast are the colors that are fully saturated. This gives you the opportunity to find a color that can work (but not necessarily for many reasons). In fact, you select the farthest color along the line connecting the color to the fully saturated color.

+3

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


All Articles