Copy link to clipboard
Copied
I'm writing a script that converts a document to Index color, then makes a selection of each of the colors it was indexed to.
The scripting command to convert to Index Color seems to only accept RGB values for the colors it will use to index to. To select the colors after indexing, Color Range only accepts LAB colors as arguments. So I have to convert my RGB numbers to LAB values to select the same colors I just used to separate. (scripting the wand only accepts locations to click, not directly entering color values through scripting)
If I bring up the "Color Picker" in Photoshop and enter an RGB value I used to separate, and take the LAB values shown in the color picker and put them in the Color Range in the script, it gets a perfect selection every time. No decimal places on the lab values or anything, just using the whole numbers shown, with the Color Range Min and Max values set to the same LAB value shown and the "Fuzziness" set to 0, it fully selects the exact color needed. But I need to script the conversion, I can't manually bring up the Color Picker, it defeats the whole purpose.
Of course, there's a "Convert color" scripting command. When I use this, I get a different LAB value for the same RGB number than the Color Picker gives.
If I change my Color Settings in Photoshop, the Color Picker always returns the same LAB value for the same RGB value, regardless. (Which tells you that what it's doing is fundamentally wrong, because it only makes sense to convert relative values like RGB number to absolute values like LAB numbers through a color profile, and the same RGB equates to different LAB depending on the profile, but that's another story.)
However, changing the color settings in Photoshop does make the scripting command "Convert color" return (often wildly) different LAB values for the same RGB number.
So, does anyone know what the "Color Picker" does to convert an entered RGB value to LAB, so I can attempt to replicate it and get my selections?
I've noticed the values seem to be closest to what I get using Convert Color with an sRGB profile in Color Settings, but not close enough to make it work.
Thanks,
Tom.
Copy link to clipboard
Copied
From my understanding, LAB is the true color. RGB is a value of the LAB color based on the intended display or output, which is what the profiles are for. So it makes complete sense that different profiles would return different RGB values of the same LAB color. I've never considered how the conversion works in the opposite direction though, from RGB to LAB.
You said the color picker always returns the same LAB value for the same RGB value which makes sense when I think about it. The values are absolutes. The RGB profiles just control the perception of the values. It seems to me that if you started with an sRGB document as your first step, you should get consistent numbers for sampled colors. But maybe I missed something in your explanation.
Copy link to clipboard
Copied
The documents all start off in sRGB as both the working space and the document profile.
If I enter an RGB number in "Color Picker," it gives me one set of LAB values. If I use the scripting function "convert color" to convert the same RGB number to LAB, I get a different LAB number.
Only the LAB number provided by "Color Picker" works to actually select the colors in the document when used with the Color Range function. The LAB numbers provided by "Convert Color" for the same RGB number do not select the colors in the document.
So I need to know how to get the LAB number provided by the "Color Picker" without manually typing every RGB number into the "Color Picker" and writing down the LAB numbers it generates.
It does not make sense to go either direction between RGB and LAB without a color profile. It's impossible. It's equating real, defined colors (LAB) to numbers that represent a different color on every device. You have to know the profile to equate the RGB numbers to real colors.
There is some conversion going on in the Color Picker. If I could find out what assumptions (ICC profile, rendering intent, possible rounding) underlie that conversion, I might be able to convert my document to color settings that will make "Convert Color" behave the same as "Color Picker."
It is really annoying that asking Photoshop to convert an RGB number to LAB in the same document, with the same color settings, gives very different answers depending on where you ask.
The numbers are similar enough with an sRGB profile that I suspect that may be involved with what Color Picker does, but I can't find settings that make it close enough to work.
Copy link to clipboard
Copied
Converting from a higher gamut color space likie LAB to a lower gamut space like sRGB always requires some form of color management and what you are forgetting is that even without CM PS is "aware" of the monitor profile and adjusts its display, which of course will also affect any color operation based on sampling those colors in screen space. That may be exactly your problem.
Mylenium
Copy link to clipboard
Copied
If I set the Color Settings to "Monitor Color," the LAB numbers from "Convert Color" still do not match the numbers from Color Picker. In fact, they get further off than working in sRGB.
Copy link to clipboard
Copied
TomT-shirts wrote:
It does not make sense to go either direction between RGB and LAB without a color profile
Absolutely correct, so for everyone's benefit you should call it sRGB if that's what it is, not "RGB" which is undefined.
There is some conversion going on in the Color Picker.
Yes, and all of it is based on what you have as defaults and policies in Color Settings. The open document overrides Color Settings if they're different.
If document profile and working space are the same, the readouts should be identical. If they're not, I can think of four possible reasons:
The monitor profile doesn't come into play here, unless you're sampling from screenshots. If that's what you're doing, that explains it right there.
Copy link to clipboard
Copied
D Fosse wrote:
TomT-shirts wrote:
It does not make sense to go either direction between RGB and LAB without a color profile
Absolutely correct, so for everyone's benefit you should call it sRGB if that's what it is, not "RGB" which is undefined.
Why would I call it "sRGB" when I type RGB values into Color Picker? The fact that Photoshop returns different LAB values for the conversion than "Convert Color" returns for the same RGB values in the sRGB profile implies that is is not sRGB. I don't know what it is... the point of the question is asking what it's doing, which probably mostly means "what profile and settings is it using for conversion." If sRGB were correct, I wouldn't have had a question.
There is some conversion going on in the Color Picker.
Yes, and all of it is based on what you have as defaults and policies in Color Settings. The open document overrides Color Settings if they're different.
This is inaccurate, as stated in my initial question. Try it yourself. You can make the most radical changes to your Color Settings, and the Color Picker always returns the same LAB values for the same RGB values.
If document profile and working space are the same, the readouts should be identical. If they're not, I can think of four possible reasons:
The values returned for Convert Color vary wildly based on Color Settings - which they should. But the values for Color Picker never change. I'm attempting to find a color conversion that equals what Convert Color does. I can find no case where the outputs are identical, that is the problem I'm trying to solve.
a color defined in Lab is out of sRGB gamut
I'm having trouble seeing how this is relevant - I am always starting with an RGB number, and converting it to LAB using two different UI's. All RGB is within LAB gamut. But even if I were performing an out-of-gamut conversion, that doesn't explain why I get different results from Photoshop for the same conversion, or what Color Picker does to convert.
the eydropper is set to a large sample size, picking up neighboring color
Since I am manually typing in RGB values, I doubt the eyedropper settings are affecting the outcome.
it's a jpeg compression artifact (yes, jpeg can do that)
The idea that JPG compression artifacts are affecting this seems far fetched to me. I don't even have to have any document open in Photoshop to do these conversions, both Color Picker and Convert Color function with no documents open.
it's a rounding error working in 16 bit depth and an 8 bit readout
This could only be the cause if the suggested answer is "the Color Picker uses sRGB, and the differences you're still seeing when you use sRGB in Color Setting are due to rounding errors." However, this can not be the cause of the error, because the difference are much too great in magnitude to be rounding errors.
The monitor profile doesn't come into play here, unless you're sampling from screenshots. If that's what you're doing, that explains it right there.
It would not actually have any effect if I were sampling from screenshots, or even directly from the screen itself. Where I sample from to get an RGB number does not change the returned LAB values for that number by either conversion method. But I am not sampling, I am typing in RGB numbers.
Copy link to clipboard
Copied
You're not getting my point.
Numbers are relative to color space. There is no such thing as "RGB" - only sRGB, Adobe RGB, <monitor> RGB etc. All of them produce different numbers from the same color.
If the numbers differ, it's because they refer to different color spaces. Yes, if you picked from a screenshot you would get other numbers than from an sRGB document inside Photoshop.
But you seem to already have made up your mind.
Copy link to clipboard
Copied
D Fosse wrote:
You're not getting my point.
It is true that if you have said anything that helps in any way with solving my problem, I missed it. What is your solution to the question, "How does the "Color Picker" convert from RGB to LAB?"
Numbers are relative to color space. There is no such thing as "RGB" - only sRGB, Adobe RGB, <monitor> RGB etc. All of them produce different numbers from the same color
I have a thorough understanding of color profiles. I have worked professionally as a color management consultant, I prepare, optimize, and automate prepress workflows professionally. I am asking this question because I am automating a prepress workflow for a company now.
"There is no such thing as "RGB" is a rather bizarre statement. I assume what you mean is that RGB values can not be equated to "real color," meaning what you'd measure with a spectrophotomoeter, or an expected tristimulus response, without an associated profile. But RGB was used for years before color profiles were invented. A lot of RGB is still untagged, and a lot of what is tagged just had sRGB tacked on without it accurately representing a conversion between the RGB values and the intended real colors. Color profiles are required by modern software to perform colorspace conversions. That's not the same thing as "There is no such thing as RGB." When I go to the Color Picker, it lets me enter an RGB value. It does not let me enter a profile, and it does not appear to use the current profile in Color Settings. So the number I type in are untagged RGB. That is RGB. Now, to convert it, Photoshop is using some profile. I don't know what. That is the problem.
I feel that my question must not be clear, but I am unsure how to state it more clearly. Because what am am doing will "produce different numbers from the same color," I am trying to figure out the color space and settings Photoshop's Color Picker uses to convert entered RGB numbers to CMYK.
If the numbers differ, it's because they refer to different color spaces. Yes, if you picked from a screenshot you would get other numbers than from an sRGB document inside Photoshop.
But you seem to already have made up your mind.
I had not "already made up my mind," I read your response, took a screenshot, tested what you were saying, and found it to be false. For the same RGB input number, the LAB values returned by both the Color Picker and Convert Color did not change regardless of whether the open document was a screenshot I opened in Photoshop, or an original Photoshop sRGB document.
That aside, there is really nothing to have an opinion on here, this is an extremely nuts-and-bolts question and if the correct answer is provided it will be extraordinarily simply to prove that that it is the correct answer - it will produce the same LAB values for a given RGB for both Color Picker and Convert Color, and there will be nothing to disagree about.
Copy link to clipboard
Copied
So, while I have not found the correct answer, I did find a hacky work-around for this problem, which I am posting in case someone else finds this thread in the future and it helps them.
The Color Sampler Tool, when set to LAB readout, does return the same LAB values as the Color Picker. Color Samplers can be created via scripting, but unfortunately, it appears to be impossible to set the mode of the sample via scripting. New samplers default to reading in the document's color mode, so you can convert the document mode to the desired output and then create the sampler. But the mode conversion honors the Color Settings, so now the Color Sampler will be returning the same values that Convert Color provides... not good. Converting the document back to the original mode after creating the sampler... changes the sampler's output mode too...
So, I created a 1 pixel square empty RGB document with a pre-made Color Sampler with LAB readout already on it. The script opens this saved document every run. It fills the pixel with the RGB number, reads the LAB value off the Color Sampler, and repeats the process through all values. Then it closes the document.
So this works - it is automated, and it converts RGB values to LAB values using whatever the Color Picker uses to do the same, and the values I get from this work perfectly every time for selecting the colors in the document with Color Range with 0 tolerance.
I am still interested to know what is going on in the "Color Picker," if anyone actually knows the answer to that. This problem reminds me how sad I am that Bruce Fraser died, because perhaps he alone both understood Photoshop's byzantine rules for using color, and was willing to share that knowledge with the world.
Copy link to clipboard
Copied
OK, have it your way, but you're really overcomplicating this to the point where it confuses everyone, including yourself.
As long as color space is consistent, numbers are consistent.
It really is that simple, as Bruce Fraser would have told you. There are no "byzantine rules" at play here.
Copy link to clipboard
Copied
D Fosse wrote:
OK, have it your way, but you're really overcomplicating this to the point where it confuses everyone, including yourself.
As long as color space is consistent, numbers are consistent.
It really is that simple, as Bruce Fraser would have told you. There are no "byzantine rules" at play here.
I agree that if the color space (and color conversion settings and CMM) are consistent, then the numbers will be consistent. In practice, the numbers are not consistent, therefore, the color space is not consistent. This is the reasoning that led me to ask this question, "How does the "Color Picker" convert from RGB to LAB?" I am attempting to get consistent numbers, so if I knew what it was doing, then I might be able to recreate it.
I am sorry this is so complicated. I keep try to find a way to state it more simply. I want to know how Photoshop calculates the color conversions it does in the "Color Picker" dialog. I am struggling to find a simpler way to word it.
Copy link to clipboard
Copied
Tom What I see is different to your observation and in keeping with D.Fosse's reply.
I currently have two documents open - one is in the Adobe RGB space the second in sRGB
If I open the colour picker with each document in turn, the colour picker has the same RGB numbers but different Lab numbers . This is what I would expect if the colorspace is being used in the conversion.
Colour picker in Adobe RGB document :
Colour picker in sRGB document
Dave
Copy link to clipboard
Copied
Ah, thank you, now that's interesting.
I had not tried having two documents with different profiles open under the same color settings, I had only tried changing my color settings on the same document. Changing the color settings on the same document DOES change the numbers returned by Convert Color but does NOT change the numbers returned by Color Picker.
I should have tried this. Yes, so if I use Assign Profile to change values - which should leave RGB alone and change the LAB values, that is exactly what I get. I started with RGB {250,200,150} and LAB was {84, 14, 32}, then I assigned Adobe RGB, and sure enough, RGB remained {250,200,150} and LAB changed to {86, 19, 36}. So I was wrong about that, the Color Picker does not always return the same result. It still seems to ignore Color Settings, but it respects document profiles. I re-confirmed this, I changed color settings to a radically different one, re-sampled the pixel, and the RGB and LAB were identical.
So
- Convert Color changes the way it converts based on the Color Settings
- Color Picker changes the way it converts based on the document profile
Still, knowing this, I would have thought that what I started with would have worked - my document is tagged with sRGB (sRGB IEC61966-2.1) and my Color Settings use the same for my working space, yet the two methods of performing the conversion still yield different number.
In sRGB document & working space, still with RGB {250,200,150}
Color Picker: {84, 14, 32}
Convert Color: {84.237670898438, 13.07177734375, 31.515075683594}
At first I thought it would just round to the same, but it often doesn't... in this case, the middle value is quite off, 13.07... is not close to rounding to 14.
I tried to check the possibility of 8 bit vs 15+1 bit rounding errors, but unless I was off in my math, it shouldn't account for this. Some were off by even more, the greatest differences I've seen are ≈2.
They are close enough that I did suspect rendering intent or black point compensation. It seems like they must use Adobe CMM, I can't imagine they don't.
So, the options here. I'm going to use the exact LAB values returned by using a script to read a Color Sampler, because I have determined experimentally that these always round to what's shown in Color Picker, and I want to compare the decimal numbers so that rounding doesn't make it appear that we've succeeded by chance.
Full Adobe Color Picker / Color Sampler numbers, sRGB conversion of RGB {250,200,150}:
{value_L:84.24, value_a:13.63, value_b:32.14}
Convert Color with sRGB working space and:
Perceptual: {value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
Saturation: {value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
Relative Colorimetric: {value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
Absolute Colorimetric: {value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
So, as expected, rendering intent has no effect when going from a smaller color space to a larger one... the whole thing always maps the same way.
Black Point Compensation could theoretically have an effect, because the black point of LAB is true 0, where sRGB has a Black point luminance of 0.2 cd/m2. But this color is far from black. Running in Relative Colorimetric with Black Point Compensation off:
{value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
Nothing's changed...
Just in case this is some weirdness with sRGB, now that I know how to make Color Picker use a different profile (thanks!):
Under AdobeRGB1998 for both the Document Profile and the Working Space:
{86, 19, 36}
Color Sampler: {value_L:86.22, value_a:19.34, value_b:35.72}
Convert Color:{value_L:86.215209960938, value_a:18.768188476562, value_b:35.079223632812}
No luck.
So, another thing that occurred to me is that Photoshop probably isn't ever using the exact color numbers I enter in Color Picker. It probably immediately converts those to 15+1. Now the rounding error when converting from 16,777,216 possibilities to 35,187,593,412,609 possibilities should be negligible, but just in case:
Back to sRGB for both the document and the working space. Enter color number RGB {250,200,150} in color picker, fill pixel with color, read RGB value with Color Sampler:
{red:249.996108949416, green:199.996108949416, blue:149.996108949416}
Converted to LAB via Convert Color:
{value_L:84.237670898438, value_a:13.07177734375, value_b:31.515075683594}
Which is identical to what I had been getting, so it's not that....
Still out of ideas here. But thanks once again for pointing out that I can control what profile the Color Picker uses... I just can't figure out why it delivers significantly (and unusably) different results than Convert Color using the same profile.
Copy link to clipboard
Copied
I think I found the answer:
http://www.rags-int-inc.com/phototechstuff/colorcalculator/adobemath.html
It looks like this is due to bugs in how Photoshop does math with it's 15+1 bit internal lab values, sometimes treating them as if they were true 16 bit. It appears that the Info Panel and Color Picker share a math bug that the scripting component Convert Color does not.
I am not wholly convinced this is the problem, but my problem seems very similar to the one documented here.
If that is the case, I am wasting my time messing around with color profiles. I would either need to reverse engineer exactly what math bug leads to these differences and re-implement it in my script, or else I can take the more realistic route of continuing to use the hack I pasted above.
Thanks to everyone for trying to help, and of course let me know if you think I've got this wrong and there's a better explanation than the linked bug. Special thanks to davescm for the insight on Color Picker using document profiles.
Copy link to clipboard
Copied
TomT-shirts wrote:
the insight on Color Picker using document profiles.
That's exactly what I tried to tell you. But OK, I wasn't clear enough, my bad.
If this is a rounding error, I'd like to know if anyone else can reproduce this, and if so how. I can't, I'm going back and forth between sRGB/Lab and Adobe RGB/Lab several different ways, and the numbers always check out.
I'm not denying it's a real issue, I just haven't seen it. It would be nice to know about.
Copy link to clipboard
Copied
You're using the Convert Color scripting function? I mean, when you say you keep going back and forth and back and forth, between what? And when you say the numbers check out - the numbers check out relative to what? How are you doing the color conversion between your RGB numbers/profile and LAB other than in Color Picker, so you know that any of your Color Picker Numbers "check out?" What's the "check" on them checking out?
To get a third value to check PS's against, I'm using Apple's Colorsync utility to do the conversions, and it makes it appear that it is Convert Color that is off and the Color Picker / Info window are correct.
Using sRGB IEC61966-2.1, with Perceptual, Relative, or Saturation intent, it converts RGB {250,200,150} to LAB {84,14,42}.
That's the values for Photoshop's Color Picker / Info Window. So if a math bug is the answer, the bug would appear to be in Convert Color.
Copy link to clipboard
Copied
Also, just to note, Colorsync Utility provides the same values for converting that RGB to LAB using Perceptual, Relative, or Saturation intent, but very different LAB numbers for Absolute Colorimetric rendering intent.
Using Convert Color definitely uses the current working space for the profile, but the ColorSync result leads me to believe that Convert Color is ignoring the Rendering Intent from Color Settings.
Copy link to clipboard
Copied
Standard working space profiles like sRGB or Adobe RGB have only one rendering intent, and that's relative colorimetric. The profile only contains one table.
Whatever intent you pick in Photoshop, it ends up relative colorimetric.
There's a new version 4 sRGB specification from icc that supports other intents, but the standard sRGB IEC61966-2.1 doesn't.
EDIT: to be more precise, matrix profiles don't contain the tables for perceptual. I'm not sure about the situation with absolute colorimetric, which is identical to relative except it doesn't remap the white point.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now