Compute HSL main color values (red, yellow, green, magenta, blue and purple) - colors

How do I mathematically compute the values for HSL main colors?
I can hardcode them in the program, of course, but I remain interested how can I determine if the color is main or combined. There must be an inscribed hexagon in the HSL color circle, so I need angles on which its corners lay.

Related

Is there a term for non-grayness of a color (where black and white would be non-gray)?

If the RGB space were rendered as a cube, white, black, red, green, blue, yellow, magenta, and cyan would be corners; gray would lie at the center of the cube.
Is there a name for colors on the surface of that cube?
In simple terms, non-grayness could be quantified (with r, g, and b from [0..1]) as
abs(max(r, g, b) - .5) / .5
Here, white, black, red, orange, etc. would have a "non-grayness" of 1.
A recent article in colour vision theory (an open-access version is available on bioRxiv) defined this concept as vividness.
It is based on the representation of colours in a colour solid, where each axis is one component of colour. In such solids, the origin is black and the opposite edge is white. For example, this is the colour solid of the CMYK colourspace, plotted in this StackOverflow question:
Vivid colours are colours on the surface of this colour solid, which is exactly what you are describing in your question:
We define a measure of colour vividness, such that points on the surface are maximally vivid and the ‘grey’ centre is minimally vivid.

Excel - RGB HSL keeps "Autocorrecting" and changing values

So I know basically nothing about colors apart from the very basics.
I have a color I'm trying to mimic.
I copied it, stuck it in paint, and used the color feature to get the RGB HSL numbers. Great!
RGB: 0; 49; 70
HSL: 132; 240; 33
The issue: When I try to manually input them into Excel, it "autocorrects" the RGB values after I enter in the HSL, and it "autocorrects" the HSL when I re-enter the RGB.
Why is this happening? Is this just an aspect to colors I know nothing about? Some limitation on Excel?
For reference, when I put in just the RGB, I'm much closer (but not quite there) on the color I'm looking for
HSL and RGB are two ways of "translating colors" into numbers.
HSL means Hue, Saturation, Lightness.
Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, 240 is blue.
Saturation is a percentage value; 0% means a shade of gray and 100% is the full color.
Lightness is also a percentage; 0% is black, 100% is white.
RGB means Red, Green, Blue, each of which is given a value between 0 and 255 in Excel.
Check this tool - https://www.w3schools.com/colors/colors_hsl.asp
If you put 0, 49, 70 for HSL you would see that it gets translated to 216, 141, 141 into RGB.
Excel is following the same logic, thus once you adjust the RGB the HSL gets automatically adjusted to represent the same color.
Excel colors are confusing because they don't follow the standard
Although the first reason you may have been confused was if you didn't know that RGB and HSL are two different ways of describing colors (and that every RGB color code has an equivalent HSL color code—see examples below), a second reason many people can get confused when selecting colors in Excel particularly is:
“Frustratingly, Excel does not handle HSL in the standard way. Instead, Excel measures all the numbers where 0 is the lowest and 255 is the biggest. But, it’s a quirk we can handle.” - https://exceloffthegrid.com/convert-color-codes/
“This approach assumes that each of your HSL values can be express in the range of 0 to 255. If, however, your HSL values are either an angle (for hue) or a percentage (for saturation and luminance), then you'll need to convert them manually before entering them in step 6. You can convert an angle value by multiplying the angle by 255 and then dividing by 360. Percentages can be converted by multiplying them by 2.55.” - https://excelribbon.tips.net/T013535_Converting_HSL_to_RGB.html
“To change the lightness (adding white) or darkness (adding black), drag your selection up and down the luminance scale on the right. Notice that the Lum value increases as the color gets lighter. Full luminance is 255 (white), and setting Lum to 0 results in black regardless of the hue and saturation settings.” - https://support.microsoft.com/en-us/office/choosing-colors-in-the-colors-dialog-box-c3d59ddf-65a7-4e62-aad7-f7b8d7684a2d
Examples of converting RGB color codes to HSL
rgb(0, 49, 70) = hsl(198, 100%, 14%)
These independent sites agree with Google that that RGB code converts to that HSL code:
https://colorpicker.me/#003146
https://hslpicker.com/#003146
So if someone told you that rgb(0, 49, 70) was equivalent to hsl(132, 240, 33), they were mistaken (even when using Excel's non-standard way of calculating HSL).

How to color only the backbone nitrogen atom in PyMOL?

I have a cartoon representation of a structure. On this structure I want to show the backbone nitrogens colored. I tried
select bb, name n
then tried to color bb by representation and element
But, unfortunately, none of the options seem to give colors. Could you please let me know how to only color the backbone nitrogen?
Thanks
The cartoon representation inside a protein is an average over three atoms in each amino acid: the C alpha and the amide bond's C and N atom. I'm not sure how you imagine it should look if only the "N part" of this representation should be colored.
Be aware: the cartoon's color is determined through the C alpha, so coloring the N will do nothing, however, if you color the C alpha (name CA), you will color the full cartoon.
if you want to have a helix with alternating colors, you should take a look at
spectrum which allows an alternating color of the cartoon. Maybe you could fiddle something together with it.
E.g. a 9mer peptide would have red white and blue alternating on each amino acid like this:
spectrum count, red white blue red white blue red white blue red white blue red white blue red white blue red white blue red white blue red white blue, 9merselection

Calculate the apparent difference in color between two HSI color values

I have two color values in HSI (Hue Saturation and Intensity) and I want a number which represents the visual difference between the two colors. Hue is a number between 0 and 360 inclusive. Saturation is 0 to 1 and Intensity is 0 to 1.
Lets consider for example Red and Blue at Saturation of 100% and Intensity of 100%.
At this website is a way to display the color by entering in the following text.
red is:
hsv 0, 100%, 100%
blue is:
hsv 240, 100%, 100%
Clearly these are two very different colors, and so a simple way I could try to calculate the difference between colors is to use the Hue component and calculate the absolute difference in hue which would be 120 (360-240) since 360 is also equal to 0 in hue.
The problem arises where the Saturation or Intensity is very dark or light, consider a very dark red and blue.
dark red is:
hsv 0, 100%, 20%
dark blue is:
hsv 240, 100% 20%
Obviously the visual difference between these two colors is less than the bright red and blue colors, as a human would state if asked to compare the differences. What I mean here is, ask a friend "Which pair of colors is most different?" they will likely say the top bright red blue.
I am trying to calculate the difference between two colors as a human would notice. If a human being looked at two colors a and b, then two colors c and d, he could notice which ones are the most different. Firstly if the colors are bright (but not too bright) then the difference is hue based. If the colors are too bright such as white or too dark such as black or too grey then the differences are smaller.
It should be possible to have a function diff where x=diff(a,b) and y=diff(c,d) yields x and y, and I can use x and y to compare the differences to find the most different color or least different color.
The WCAG2.0 and 1.0 guidelines both make reference to different equations on perception of color difference:
contrast ratio (http: //www.w3.org/TR/2008/REC-WCAG20-20081211/Overview.html#contrast-ratiodef)
brigtness difference and 3. color difference (http://www.w3.org/TR/AERT#color-contrast).
I tried the Delta-e method(http: //colormine.org/delta-e-calculator/) but it is quasimetric so the difference measurement may change depending on the order you pass the two colors. If in your example you expect diff(a,b) to always equal diff(b,a) then this is not what you want(there may be different algorithms under this name that aren't quasimetric but I haven't looked into it past that site).
I think that the color difference metric is the closest to matching my expectations of color difference measurements. For your example it will yield that diff(a,b) > diff(c,d)
You can test it out for yourself using the tool at this website: http://www.dasplankton.de/ContrastA/
The general answer seems to be what David van Driessche said, to use Delta E. I found some Java code here: https://github.com/kennyliou/GAI
This is a answer to the question, may not be the best answer.

RGB for color composition rather than primary hues

Why do computers use RGB (red, green, and blue) values for color composition rather than the primary hues, red, yellow, and blue?
The hues of magenta, yellow, and cyan are primary for subtractive combination (e.g. paints or inks) rather than additive combination such as light where red, green, and blue are primary.
Wikipedia has more detail on the whys and wherefores.
Computers use the additive colour model, which involves adding together RGB to form white, and is the usual way of forming colours when using a light source.
Printers use subtractive color, normally using Cyan(C), Magenta(M), and Yellow(Y), and often Black(K). Abbreviated CMYK
Cyan is opposite to Red, Magenta is opposite to Green, and Yellow is opposite to Blue.
This is a really simple explanation of a complex issue, the guy that came up with additive colour was James Maxwell (yes, that one), so if you dig into the many articles about him, that may explain much better.
Just for clarification, the primary colours you learn at school are incorrectly given as red, yellow & blue. In fact they are Cyan, Yellow & Magenta, just like your inkjet printer. As the previous posts state, Cyan, Yellow & Magenta are the subtractive prime colours; you see what the pigments reflect. Red, Green & Blue are the additive primary colours that CRTs, Plasmas & LCDs use.
For efficiency: the RGB model is additive. For example, superimpose pure red and pure blue light, and you get magenta. It's also easy to build into monitors. If you take a magnifying glass and look at your monitor, you'll be able to see individual red, green and blue dots that vary in intensity to compose the colors needed. As ffpf mentioned, check out Wikipedia. Here's a link to the article on the RGB color model.
Computer screens emit light to display pixels. Mixing different colours of light is called Additive colour. Additive colour uses red, green, and blue as primary colours.
Subtractive colour is how different colours of materials mix, such as paints. Subtractive colour uses red, yellow, and blue as primary colours.
How I think of it is that when light reflects off an object into your eyes, the object absorbs some of the colour, and reflects the rest to your eyes. So if an object's green, it means it's absorbing the red and the blue out of the white light. This is why mixing red, green, and blue light creates white light, but mixing red, yellow, and blue paint creates black (the mixed paint now absorbs all primary colours.) That is the reason for the difference between additive and subtractive light.
Because combining light sources (which computer monitors do) does not work the same way as combining printed ink. It's just a guess.
Color is Not Real
Color is a perception. Light exists in different wavelengths or frequencies, but the only thing that makes a certain wavelength appear to be a "color" is the nature of human perception.
The Long, Medium, and Short of it
The eye has three types of "cone" cells where are sensitive to one of three bands of light, long, medium, or short wavelengths (about 700nm to 380nm). "Long" we think of as red, medium—green, and short—blue. But each cone type covers a wider band, and there is definite overlap, especially of the long and medium cones.
It's All In Your Head
Most of the human visual system (HVS) is in the brain (62% of the brain is involved in visual processing). The overlapping cone responses are filtered by ganglion cells in the back of the eye, sent over the optic nerve, and then further filtered and processed by the visual cortex.
No Such Thing As "Primaries"
While we may call some colors "primary", there is no set of just three real colors that can make up all other colors. Pantone requires 14 different dyes to make up that set of colors for instance, and a typical artist will load their paulette with a dozen colors from which to mix.
TVs/Monitors use red, green, and blue "primaries" with wavelengths chosen with the intent to stimulate each of the three types of cones in the eye as independently as possible. However this is impossible to achieve due to the cone bandwidth overlap.
As such, you "could" say that red, green, blue were the primary colors of light, but even that is not completely correct. Yellow stimulates the "red" and "green" cones about equally, in the middle of the cone overlap. When a computer monitor displays yellow, it is displaying separate green and red, which does not mix in the air to make yellow — it just stimulates the red and green cones causing the brain to perceive yellow.
We perceive yellow, and not a reddish-green nor a greenish-red, due to the opponent process of color that is a result of the ganglion cells in the back of the eye.
Red/Green is an opponent pair, and Yellow/Blue is an opponent pair, making up four "unique" colors (Red, Yellow, Green, Blue). Since Yellow is easily created with red and green light, additive color processes typically omit yellow.
Subtracting Light
Reflected surfaces (and transparent film) "subtract" light by absorbing it, reflecting (or transmitting) only certain wavelengths. As it turns out, we get the best gamut of colors using "primaries" cyan, magenta, and yellow when working with subtractive reflected/translucent colors, as opposed to emitted light colors where we are trying to selectively stimulate each of the three cone types using red, green, and blue.
Also, it is useful to note that cyan is the "opposite" of red, magenta "opposite" of green and yellow "opposite" of blue.
And for the record, in an sRGB monitor, the red is really a red/orange. The green is really a green/yellow, and the blue is more of a violet.
For either additive or subtractive processes, the specific colors chosen are (generally) intended for creating the widest gamut of color, limited by various reasons of economics and practicality.

Resources