Convert RGB colors to 2D plane - excel

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.

Related

Plotting colour gamuts in Mathematica

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.

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.

how to choose a range for filtering points by RGB color?

I have an image and I am picking colors by RGB (data sampling). I select N points from a specific region in the image which has the "same" color. By "same" I mean, that part of the image belongs to an object, (let's say a yellow object). Each picked point in the RGB case has three values [R,G,B]. For example: [120,150,225]. And the maximum and minimum for each field are 255 and 0 respectively.
Let's assume that I picked N points from the region of the object in the image. The points obviously have different RGB values but from the same family (a gradient of the specific color).
Question:
I want to find a range for each RGB field that when I apply a color filter on the image the pixels related to that specific object remain (to be considered as inliers). Is it correct to find the maximum and minimum from the sampled points and consider them as the filter range? For example if the max and min of the field R are 120 ,170 respectively, can it be used as a the range that should be kept.
In my opinion, the idea is not true. Because when choosing the max and min of a set of sampled data some points will be out of that range and also there will be some point on the object that doesn't fit in this range.
What is a better solution to include more points as inliers?
If anybody needs to see collected data samples, please let me know.
I am not sure I fully grasp what you are asking for, but in my opinion filtering in RGB is not the way to go. You should use a different color space than RGB if you want to compare pixels of similar color. RGB is good for representing colors on a screen, but you actually want to look at the hue, saturation and intensity (lightness, or luminance) for analysing visible similarities in colors.
For example, you should convert your pixels to HSI or HSL color space first, then compare the different parameters you get. At that point, it is more natural to compare the resulting hue in a hue range, saturation in a saturation range, and so on.
Go here for further information on how to convert to and from RGB.
What happens here is that you implicitly try to reinvent either color indexing or histogram back-projection. You call it color filter but it is better to focus on probabilities than on colors and color spaces. Colors of course not super reliable and change with lighting (though hue tends to stay the same given non-colored illumination) that's why some color spaces are better than others. You can handle this separately but it seems that you are more interested in the principles of calculating "filtering operation" that will do segmentation of the foreground object from background. Hopefully.
In short, a histogram back-projection works by first creating a histogram for R, G, B within object area and then back-projecting them into the image in the following way. For each pixel in the image find its bin in the histogram, calculate its relative weight (probability) given overall sum of the bins and put this probability into the image. In such a way each pixel would have probability that it belongs to the object. You can improve it by dividing with probability of background if you want to model background too.
The result will be messy but somewhat resemble an object segment plus some background noise. It has to be cleaned and then reconnected into object using separate methods such as connected components, grab cut, morphological operation, blur, etc.

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?

Calculating colours in a colour map

Suppose I have some data to be displayed on a bar chart, and each bar will be coloured according to its height.
Say the bars range in height from a to b.
What is the best way of calculating the numbers in a continuous colour map so that a is assigned a set of RGB values, a+1 is assigned a set of RGB values all the way through to b. The data is continuous.
The colours assigned need to be such that if data point 1 has value x and data point 2 has a value close to x, the colours assigned to data points 1 and 2 will be similar.
Pretty much, depending on what program you're using to do it in, it's fairly straight forward. Think of having 3 columns R G and B (they could be stored multiple different ways).
Pure red is 255 with G and B being 0. Same goes for pure green and blue with their respective colors. Then it's just a matter of covering every possible color you want.
A sample color chart is here
Another option is to use the HSV color system and then convert it to RGB if you really need to have RGB. I personally find working with HSV to be easier and more concise when generating a whole array of usable colors.

Resources