Copy link to clipboard
Copied
Hi there --
Do any of you know the formulas to calculate hue from RGB values? I know I can plug the RGB values into the color picker, which will show the HSL values. That's a tedious process, and I want to do it in an Excel spreadsheet. I have a grid with blocks of solid colors in Photoshop, and I want to arrange the blocks in hue order (0-360). There are different formulas based on red, green, and blue light ratios:
R > G > B
R > B > G
B > R > G
B > G > R
G > R > B
G > B > R
Scott
Scott
I'm not in Photoshop. I have a list of RGB values in an Excel spreadsheet.
By @scotwllm
So this sounds like it is more of a MS Excel question than a Photoshop one at this point...
https://www.mrexcel.com/board/threads/rgb-to-hue-formula.559852/
=IF(180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2))<0,180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2))+360,180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2)))
To round the result of the formula down to 161 to match Photoshop sRGB, apply the following formula
...Copy link to clipboard
Copied
with(new SolidColor) rgb.hexValue = '00ff00', hsb.hue
Copy link to clipboard
Copied
Thanks for the speedy reply. Kukurykus. What do I do with that code?
Scott
Copy link to clipboard
Copied
Save as hue.jsx to Presets/Scripts folder of your Photoshop. After relaunch go to File/Scripts.
The '00ff00' is hex value you may change to other while end of code change to alert(hsb.hue).
Copy link to clipboard
Copied
First, you must define which RGB color space. That defines the scale of the RGB values. IOW, in sRGB, R234/G56/B89 isn't the same color as the same triplets in Adobe RGB (1998).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@scotwllm wrote:
At this phase of the workflow, I'm not in Photoshop. I have a list of RGB values in an Excel spreadsheet. I need to sort them by hue. Then I use the colors in that order in Photoshop.
RGB numbers without a color space have no definition.
1000 alone is meaningless.
1000 miles versus 1000 kilometers does.
Where did the RGB triplets come from? Do they have an associated RGB color space? No calculations are possible without one.
Copy link to clipboard
Copied
Eyedropper tool. In this instance, I screengrabbed color samples from an Adobe pdf document.
Copy link to clipboard
Copied
@scotwllm wrote:
Eyedropper tool. In this instance, I screengrabbed color samples from an Adobe pdf document.
And that's based on a color space. What is it?
Oh and a screenshot doesn't account for the source color space.
Even using Apple's Digital Color Meter utility** or similar to 'measure' color. They can't tell you anything about the actual color numbers of documents inside say Photoshop. This is a Photoshop forum and if you don't care what PS now does with the numbers fine. PS does however. Sorting RGB and calculation from RGB in PS, big difference.
**This is not measuring anything. It is taking two or three bits of information:
1. The color that an app is actually outputting to a pixel. i.e. an RGB level.
2. The colorspace that the app says should be used for that pixel for ColorSync to correctly display it (defaults to sRGB if the app doesn't specify).
3. The ICC profile associated with the display.
For this reason, a mismatch in numbers is expected.
Copy link to clipboard
Copied
You're very knowledgeable and passionate when it comes to color spaces. We have to be careful not to create mountains out of molehills when we become subject matter experts. In this particular question, we solved the problem without doing anything to the colorspace. When Excel is crunching numbers, it doesn't care what color they are. I was careful, though, when I used the eyedropper to sample a color on the spreadsheet, that the spreadsheet was on my calibrated UHD monitor.
Copy link to clipboard
Copied
You are correct, Excel knows nothing about color and only raw numbers. You asked in a Photoshop forum about converting RGB numbers to something not RGB. That isn't possible with out a color space. Sorting values in Excel is.
The eye dropper method does not work for PS for the same reasons. Again, this is how Photoshop works and if you don't care, fine. We have to be careful not to create mountains or molehills that don't work in a specific software product asked about for color conversions. Again, sorting raw numbers and converting RGB color numbers (your original question) isn't remotely the same.
Copy link to clipboard
Copied
"asked in a Photoshop forum about converting RGB numbers to something not RGB. That isn't possible with out a color space." While I would agree with you and your passionate advocacy of it -- and I'd agree that hue can't be considered a standard value -- Still -- Actually, yes it is possible with out a color space, in this specific case. There is no "HSB colour space" nor "HSB profiles". HSB is simply a reversible mapping of RGB values. So sRGB RGB values map to HSB which also apply to sRGB. Or Adobe RGB would convert to HSB applicable to Adobe RGB. And so on. So, it doesn't REQUIRE a space to do a correct conversion, any more than, say, going from 0-255 to 0.0-1.0 values, or going from 0-255 values to #xxxxxx hex values.
Copy link to clipboard
Copied
HSB is simply a reversible mapping of RGB values from WHAT RGB color space?
R0/G255/B0 is a color in sRGB.
R0/G255/B0 is a not color in ProPhoto RGB. It is just a triplet of RGB numbers. What is the reversible mapping of RGB of those RGB values without the scale? The same mapping?
Getting from a known RGB number in a defined color space to HSB or LCH, or HSL or LAB is easy and no user profiles are necessary. Many such conversions take place hundreds of thousands of times a day in Photoshop alone.
Copy link to clipboard
Copied
Wait - photoshop handles LCH? Why couldn't I find that??
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@riccia80600895 wrote:
Wait - photoshop handles LCH? Why couldn't I find that??
HSB, and Lab.
Copy link to clipboard
Copied
If you search the web for "rgb to hsl algorithm", you'll find lots of info about this. Mostly differing in presentation,some more general, some aimed at coders.
Here's a site that has description of how it works.
Copy link to clipboard
Copied
I'm not in Photoshop. I have a list of RGB values in an Excel spreadsheet.
By @scotwllm
So this sounds like it is more of a MS Excel question than a Photoshop one at this point...
https://www.mrexcel.com/board/threads/rgb-to-hue-formula.559852/
=IF(180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2))<0,180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2))+360,180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2)))
To round the result of the formula down to 161 to match Photoshop sRGB, apply the following formula in cell E2:
=ROUNDDOWN(D2)
Copy link to clipboard
Copied
It's a Photoshop project that uses Excel a bit. It's a reasonable assumption that Photoshop users would be more versed in everything to do with light than your everyday Excel expert who's probably more interested in macros to create invoices.
I tried this formula earlier today. You have to change the semi-colons to commas, and it still doesn't work.
Copy link to clipboard
Copied
It worked for me in LibreOffice, it also auto converted the semi-colons to commas when I pasted in the formula. The screenshots in my post shows that it works (in LibreOffice at least) and I tested and verified in Photoshop with multiple values before posting this as a proposed solution. I have updated my previous post to use commas.
EDIT: It also works in Excel and Apple Numbers. I have attached the spreadsheet.
Copy link to clipboard
Copied
I don't know what LibreOffice is. I'll post a jpg of what I get when I try to use it.
Copy link to clipboard
Copied
LibreOffice is like OpenOffice – however, it was always more stable for me than OpenOffice.
Try the spreadsheet that I uploaded to my previous post, the formula works fine in all common mentioned spreadsheet packages.
Copy link to clipboard
Copied
There's only one conversion on there.
Here's where things stand on this endeavor. There are six different relative proportions the RGB values can have:
R>G>B
R>B>G
G>R>B
G>B>R
B>R>G
B>G>R
I have formulas for four of these six conditions that I'm sure will produce correct results. I have formulas for the other two that have been wrong every time. So I'm just looking for how Adobe's color picker calculates hues when G>R>B and when B>R>G.
Btw -- the spreadsheet I use includes a VB Script that reads the numbers in columns B, C, and D and colors column A automatically. I didn't have to use their color picker.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
In the end, you are the winner as you can now sort by hue! How you get that back into Photoshop is of course up to you.