How to implement a color contrast enriching algorithm? [duplicate] - colors

This question already has answers here:
Determine font color based on background color
(22 answers)
Closed 2 years ago.
I am currently developing an App. In this App I get some RGB color code from the server, that I want to display.
As the color I get should be the background color of a Label, there is some text, that should be displayed above it. The user defining the color is completely free in choosing a color, so I am in need of finding an algorithm, where the text color of the label is somehow contrasted to the color I get from the webservice.
Problem explained in an example:
I choose black 0x000000 to be the textcolor. If the user defines a color like dark gray 0x111111, the text's visibility would be very bad.
In addition, I want the text color to be black or white in order to not over-color the app.
So how can I determine, if white or black is the better color for the textcolor, based on a RGB code I get from the server?

You just should calculate contrast ratio for user color with black and white, then choose the color with higher ratio.
Here is description for calculating relative color contrast from RGB.
Note that relative luminance of white is 1.0 and for black is 0.0, so (if you are considering only black and white) you can just check if relative luminance of user color is <0.5 then use white, and use black otherwise.

Related

Can I find a semi-transparent layer's colour and transparency using before and after values?

I have two images, one is a portion of an original image, the other is the whole of the original image covered by a uniform semi-transparent colour layer (in this case orange).
Can I use the colour difference between pixels from the first and second images to reverse engineer the colour and transparency of the covering, and if so can I then use it to find the original colour of a pixel without an uncovered equivalent? Is there just a nice single button solution within GIMP or do I need to do some actual programming/maths? I have basically no experience with image manipulation so any help would be appreciated.
Here are the uncovered and covered RGB values to help explain (and the missing value at the bottom).
Colour
Base
+Transparent
Colour 1
#179fb7
#f8b76f
Colour 2
#2fafc8
#f8bf6f
Colour 3
#3fc8d8
#f8c877
Colour 4
#578f08
#f8b73f
Colour 5
#6faf2f
#f8bf47
Colour 6
#87c847
#f8c84f
Colour 7
#9fd85f
#f8c857
Colour 8
#d0bf47
#f8bf4f
Colour 9
#8f9f1f
#f8b747
Colour 10
#6faf2f
#f8d077
Colour 11
?
#f8d06f
I assume you can find every possible colour-transparency pair that would cause the transformation for each row and the plot each as a line to find the intersection point, but I don't know enough about how colour works to do that.

How to define color range of particular color from RGB/CMYK/Hexcode model?

I am trying to find a segment in color wheel which is dedicated to particular color only (For example, red or green or black or violet).
So far, i have tried following:
I used 12 colors and 20 shades of each color to narrow down a color range(https://digitalsynopsis.com/design/color-thesaurus-correct-names-of-shades/). But, i was clearly not able to define the range of particular color because i have not found any pattern which could say when i will enter into differen color segment.
For example, to define black color, what digit should be the minimum and maximum in RGB or any other module?

What is the color threshold value for the white color?

My question is about color tracking... What is the color threshold value for white in python ? I need to track the white color alone in a group of pictures. So I need to separate the white color. In order to do so I need to know the threshold value of white color...
It depends on your pictures. Assuming that you're going to threshold using the RGB values, the RGB value for white is (255, 255, 255). But this value holds true for pure white color. If you have real-world pictures, you might have clearly white color at certain areas in your image but they wouldn't have the value (225, 255, 255). Factors like the shadow, lighting conditions, angle etc. contribute to the variance from pure white color value.
In order to threshold correctly, you need to check the range of values for your set of pictures. I recently worked on a similar problem and for my case, the range of values was as follows:
Red channel: 200-255
Green channel: 180-255
Blue channel: 140-255
But please note that this accepts a lot of variation of white like light yellow. It will highly depend on your case so make sure you check the range on your data.
One way of that can be by displaying/showing your image using skimage and then hovering over white areas, it will display the RGB value on the bottom right corner of the image. Here is the code for showing an image in skimage:
from skimage import io
def show(img):
io.imshow(img)
io.show()
You can create a range of values/threshold from the values you notice this way.

Why! 100% Cyan in CMYK is NOT rgb(0,255,255)? in Photoshop

I try to convert a solid cyan to RGB in photoshop. But I get confuse about the RGB values "rgb(0, 160, 233)".
Where can i find the formula or icc profile to calculate RGB values that like Photoshop.
There is not one conversion which is "right" - it depends on the colour profiles you are using.
For instance, it could be the case that your CMYK Cyan is outside of the sRGB colour space - in that case Photoshop tries to get as close as possible to the right colour, but it stays within the RGB-values that are possible for this profile. Don't wonder if other programs calculate other RGB-values.
But if you change to ProPhoto RGB colour space, it may be possible to match your Cyan much better, as this colour space is much larger. So, of course, the RGB values are different again.
For more information, see here: https://graphicdesign.stackexchange.com/questions/5138/why-are-colors-shifting-when-converting-from-cmyk-to-rgb-in-photoshop

Tinting Drawn Textures with the Color property in XNA / Monogame, how to balance?

I have these four icons that look like this:
But I want to be able to just have 1 gray icon and then tint them different colors by setting the color in XNA / Monogames Draw function.
I took one of the images and pulled all the colour out and made it a bit lighter it to get
I also tried a version where the center of the gray image is fully white but neither look right in the game, here's an image with the icons on top and my tinted gray on the bottom (the tint color is sampled from the center of the original icons):
I figure there should be a way, given the original icons, to figure out how to make the gray icon and also the colors to plug into the draw function so that I get an exact copy of the original. I assume this is possible? How do you do it?
EDIT:
To elaborate on my issue here is another image all with blue icons, the top images are all the original blue icon for comparison. The bottom images are all grey icons I used to tint to make the middle icons. The grey icons are, from left to right, 0 saturation, 0 saturation and 100 brightness, and auto level + 0 saturation. It seems to me that by setting the saturation to 0 I am losing the ability to make the icon look right as it's not just "darker" blue but also "bluer" blue.
EDIT 2: I don't think it's possible, thanks for the help Goose.
Would it work if the grey icon was full white at the center (it's brightest point) and got darker from there.
Then you could just sample the color at the center of your source image (the colored ones) and tint with that.
I think the issue you are seeing now is that the grey image will darken the color you are tinting with, so you actually want to tint with the source color PLUS the amount of grey at the brightest point in the image (if that makes sense).

Resources