Plotting colour gamuts in Mathematica - colors

I am currently learning Wolfram Mathematica, I want to manually plot colour points on a CIE chart and manually join them with a boundary line.
I am confused as to how Mathematica converts colour space primaries (p3 in my example) to display on a CIE31 chart.
I've read about converting xyY to XYZ is this a step that I need to do here? Could anyone advise on this?
Cheers.

At least your definition of p3 misses a comma, i.e. it should be 0.320}, {0.265 instead of 0.320}{0.265.

Related

Convert RGB colors to 2D plane

I have three columns with RGB colors. In another set of columns, I need to convert them to X,Y coordinates per the following examples:
How?
The math is eluding me, mostly because it has to wrap back around to red.
Of note: no VB please, and I'd prefer the map jump from the second red directly to pure grayscale (i.e. no bleeding).
UPDATE: I came up with the following:
X —
=IF(AND(MAX([#R]:[#B])=[#R],MAX([#R]:[#B])<>[#B]),[#R]+[#G]-[#B],
IF(MAX([#R]:[#B])=[#G],512+[#G]+[#B]-[#R],
IF(MAX([#R]:[#B])=[#B],1024+[#B]+[#R]-[#G])))
-(256*(MAX([#R]:[#B])/256))
Y —
=ROUNDUP(MAX(Table1[#[R]:[B]])/2*IF(MIN(Table1[#[R]:[B]])=0,1,1+MIN(Table1[#[R]:[B]])/256),0)
Plus a separate quick calculation to wrap around negative X values. I'll also write a quick check for grayscale exceptions after I resolve colors.
But first, tell me why the above is wrong.

Is it possible to smoothly change (like a photoshop gradient) the color of a plotted curve as a function of distance from a given point?

Suppose one has a plot like this, for which the peak is at (x,y) = (0,0.40). The distribution is plotted in blue. Is it possible to edit the color scheme of the distribution plot in such a way that the color is a gradient - the farther from x (or y or independently for both) the more the color changes - like this?
I've searched SO for help with this, but only found solutions in which line segments were different colors. But, I want the color transition to be smooth (like this but not 3-D) instead of rough, and I want the color to depend on its distance from a particular value rather than pre-determined "randomly". A different SO post did something similar (not quite what I want though), but could only do so as a scatter plot, which only works for changing colors based on x-value if the peak is at x=0 - I'd prefer it be generalized. As an example, the further from x=0 the redder the curve gets. Ideally, there's a way to do this with a matplotlib colormap.

What is the relationship between color space RGB, XYZ and the color matching function?

What is the relationship between color spaces (RGB, XYZ) and the color matching function? Let's say we have some color matching function in the color space XYZ (3 row matrix). We also have the transformation matrix which translates from XYZ coordinates to RGB coordinates.
My understanding is that there is some visual input, which is made up of the color spectrum S(y). The human eye does not see the world - it only sees its interpretation of the world. The human eye has 3 cone types LMS, each of which is responsible for processing RED, GREEN, or BLUE. The human eye sees the spectral color only because it's eye sums over RED, GREEN, BLUE vector, and this sum matches the color of the input. In order to match the color, there is a color matching function, which takes the input spectrum and produces the weights by which to multiply the primary RED, GREEN, BLUE color vector. These then get added and their output visually matches the spectral input, even though the spectrum had many many frequencies added, while the human eye was only adding 3. So we went from HUGE space to space where we can describe all with 3 vectors, summed as dictated by the color matching function.
The spectral input, color primaries, and color matching functions behave as described above and can be summarized in this formula:
where pi is the 3d vector of primary colors, c - color matching function is also a vector of 3 components, and finally s is the spectral input.
We have XYZ color space, and a corresponding color matching function which does what is described above. We are then given matrix T, which transforms XYZ coordinates to RGB coordinates. We already know T, and we need to use it to produce a new color matching function for the RGB color space.
I do not understand how the color space relates to choice of primaries pi(λ) and the choice of color functions ci(λ1).
I have been trying to understand about colours from months and after some research, i believe I have some insights which probably can help me answer your question.
I do not understand how the color space relates to choice of primaries
pi(λ)
Primaries are nothing but the wavelength of the colors that we choose to use for making all the other colors in space and that also defines the gamut of the colour space. So if you play with the applet provided in the link that is given below you can see that the whole gamut in the colour space changes when you change your primary.
Have a look at Alternative primaries and gamuts section.
Now I do not know how much you understand the RGB and XYZ or what do you mean when you say RGB here (assuming you are referring to sRGB gamut values); XYZ are actually Tristimulus values which are called rho, beta and gamma as shown in the image above and just for simplicity XYZ are converted to xy space from where you get your standard sRGB gamut.
Please go through this if you are interested in understanding how colour sensors work and converting sensor values to XYZ matrix
Please comment if I have missed any information or answer needs editing.
I think lots of issues with color selection are due technical problems people had to solve. Usually you are not trying to reproduce colors as accurately as possible, but to make them pleasant looking, cheap, fast to calculate on cpu.... If someone watches plains of New Zealand on TV he is very unlikely to know they really look like, but almost certainly wants to enjoy the picture and pay little for it.
Several reasons why you might want to use different color matching functions might include:
You are taking pictures under non-white light and you want your picture to look natural.
You are taking underwater pictures and want to compensate for the fact that water attenuates different frequencies at different speeds.
Your sensor is not perfect and you want to compensate for that.
On the other hand you might want to change your primaries due to some reason. For example your images might be taking a picture of a scene with limited amount of colors. By nudging your primaries a little you might get a "fuller" picture.
Finally sometimes you just have to compensate for some of the limitations you have with your devices. Your phosphorus on CRT TV will impose some restrictions. So will the noise in air when transmitting using PAL. On the other hand if you go digital you might be forced to have less than 36 bits per pixel. In that case you will have to make compromises and this will give you opportunity to lose as little as possible.
If you want a short tutorial visit Cambridge in colour.
Here is a Szeliski's textbook on photography, look at chapters 1 2 and 10.
Poyton has list of common transformations.

What is the mathematical relationship between hexadecimal colour values on opposite sides of the colour wheel?

I want to incrementally rotate around the color wheel hopping to the opposite side each turn. I have an undefined number of clients to represent on a kendo chart and I want to ensure that they are all identifiable against their immediate neighbours. Can anyone pin down a mathematical relationship between colours on opposite sides of the colour wheel? I am of course working on this myself but I thought it an interesting little problem that you guys might enjoy with me.
It would be easier to do this type of conversion in the HSL or HSV color space, rather than RGB (aka hex values). Then to get the opposite point on the wheel just follow the formula:
hue = (hue + 180) % 360
So starting with hsl(0, 80%, 20%) would yield hsl(180, 80%, 20%) etc. The easiest way to convert a given RGB value to an RGB value on the opposite point would be to convert RGB to HSL or HSV, do the shift, and convert that back to RGB. The formulas for that can be found here: http://en.wikipedia.org/wiki/HSL_and_HSV
Modern browsers support HSL natively, so maybe some of this complexity can be avoided and you would never need to muck with RGB values in the first place. http://caniuse.com/css3-colors
The color wheel is based on the HSV color space, where the hue coordinate represents your angle on the color wheel. You need to convert RGB colors into HSV, perform your rotation on the hue coordinate, then convert back to RGB.

How to adjust gradient color by RGB or HSB

I'm trying to make a bar with gradient color updownward, I set 3 points as stated in the bar. Now the picture seems good, but I don't know how to automatically generate these color mathematically, by RGB or HSB? I'm having trouble with the rule of this kind of art thing.
I was intending to do it with RGB but I found it hard to do. But with HSB, I changed "S" and it makes a little sense as shown in picture.
My question is: How to calculate these three colors based on ONE given color, makes the gradient natural?
Thanks in advance, this has nothing to do with code but I think it definitely has a mathematical solution(formula).
I think there's no general rule for how to do this and different possibilities to get to a (subjectively pleasing) result.
I copied your colors here for analysis but didn't find a pattern in your choice. My solution would be to find a pleasing distance of (relative) luminance. To adabt to your example I chose one arbitrary color, then increased the Lum value by 18% for the second color and for the third one I subtracted 10% Lum again.
Do you like this solution?

Resources