• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How does Photoshop calculate Lab values?

Engaged ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

In the Color Picker tool, Photoshop presents the Lab values of colors if you type in the RGB or HSB values. 

I doubt Adobe goes to one of the color conversion websites to get the Lab values. Does anybody know the formula they use to calculate it?

 

Scott

TOPICS
Windows

Views

750

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

It's the other way round. All color space numbers are calculated from Lab.

 

Lab is the reference and at the base of all color management. It is one of two commonly used Profile Connection Spaces (the other is CIE XYZ).

 

A standard profile conversion goes, say, Adobe RGB > Lab > sRGB.

 

Lab numbers define a color absolutely.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 07, 2024 Dec 07, 2024

Copy link to clipboard

Copied

Hi there --

 

I appreciate the time you invested to respond to my question.  However, you answered a question I didn't ask. I asked how does Photoshop calculate the numbers that appear in the color picker when a user enters RGB values. I've found formulas online that purport to do it, but they're written in code or use calculus. I took calculus around 40 years ago and have never needed to use it until now. I need to calculate the Delta-E between multiple colors, and plugging them into a website form one by one takes too much time. I'm too old to waste it on that kind of stuff, know what I mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

We did answer it. The answer is color management. The Lab numbers are always there as the definition of the RGB numbers in the given RGB color space.

 

The online calculators are rubbish because they usually don't even consider color management, color spaces and icc profiles. RGB what? There is no such thing as "RGB". Numbers are undefined until associated with a specific color space.

 

Look at the screenshot I posted below. That's how given Lab numbers are represented in different color spaces.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

You might want to take that up with Adobe, because they have no problem spitting out Lab numbers if you input RGB into their color picker.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

quote

You might want to take that up with Adobe, because they have no problem spitting out Lab numbers if you input RGB into their color picker.

By @scotwllm

 

It’s not clear why you see that as a counter-argument, because as D Fosse is explaining, Lab is the device-independent reference for all Photoshop colors in any color mode.

 

In other words, of course Adobe has “no problem spitting out Lab numbers if you input RGB into their color picker” because that’s what it does every time anyway, for any color. It will always run the color values through Lab to get to any other color space. (The only exception might be a Device Link profile conversion, but I don’t have enough experience with those.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

I see it as a counter-argument because Dave answered a question that I didn't ask.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

@scotwllm 

 

What @D Fosse referred to was 3rd party tools that don't specify an RGB colour profile/space to define the scope of the values. Photoshop (should) always have an RGB or CMYK profile set against a document, or as a fallback in colour settings, providing meaning to the RGB or CMYK values.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

quote

I need to calculate the Delta-E between multiple colors, and plugging them into a website form one by one takes too much time. I'm too old to waste it on that kind of stuff, know what I mean?


By @scotwllm

 

Which dE: de76/dEab, dE94 etc?

 

If the formula can be translated into JavaScript, there may be a way to do this...

 

I'm sure you know of the following:

 

http://www.brucelindbloom.com/index.html?Calc.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

The following three scripts provide a rough dE evaluation between the foreground and background colour picker values.

 

dE.png

 

 

 

/*
    Calculates the CIE76 (dE76) color difference between the foreground and background colors in Photoshop
    v1.1
    https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-does-photoshop-calculate-lab-values/m-p/15028840
*/

#target photoshop

function calculateDE76(lab1, lab2) {
    var deltaL = lab1[0] - lab2[0];
    var deltaA = lab1[1] - lab2[1];
    var deltaB = lab1[2] - lab2[2];

    return Math.sqrt(deltaL * deltaL + deltaA * deltaA + deltaB * deltaB);
}

function main() {
    /*
    if (!app.documents.length) {
        alert("No document open.");
        return;
    }
    */

    // Get foreground and background colors
    var fgColor = app.foregroundColor.lab;
    var bgColor = app.backgroundColor.lab;

    var fgLab = [Math.round(fgColor.l), Math.round(fgColor.a), Math.round(fgColor.b)];
    var bgLab = [Math.round(bgColor.l), Math.round(bgColor.a), Math.round(bgColor.b)];

    // Calculate dE76
    var dE76 = calculateDE76(fgLab, bgLab);

    alert("Foreground vs. Background Color Picker Difference\n" +
        "Foreground color (L:" + fgLab[0] + " a:" + fgLab[1] + " b:" + fgLab[2] + ")\n" +
        "Background color (L:" + bgLab[0] + " a:" + bgLab[1] + " b:" + bgLab[2] + ")\n" +
        "The dE76 color difference is: " + dE76.toFixed(2));
}

main();

 

 

 

/*
    Calculates the CIE94 (dE94) color difference between the foreground and background colors in Photoshop
    v1.1
    https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-does-photoshop-calculate-lab-values/m-p/15028840
*/


#target photoshop

function calculateCIE94(lab1, lab2) {
    // Weighting factors for CIE94
    var kL = 1;
    var kC = 1;
    var kH = 1;
    var K1 = 0.045;
    var K2 = 0.015;

    // Differences in Lab
    var deltaL = lab1[0] - lab2[0];
    var deltaA = lab1[1] - lab2[1];
    var deltaB = lab1[2] - lab2[2];

    // Calculate chroma
    var c1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]);
    var c2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]);
    var deltaC = c1 - c2;

    // Calculate deltaH (corrected)
    var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;

    // Scaled components
    var sl = 1; // Lightness scale
    var sc = 1 + K1 * c1; // Chroma scale
    var sh = 1 + K2 * c1; // Hue scale

    // CIE94 formula
    var dE94 = Math.sqrt(
        Math.pow(deltaL / (kL * sl), 2) +
        Math.pow(deltaC / (kC * sc), 2) +
        Math.pow(deltaH / (kH * sh), 2)
    );

    return dE94;
}

function main() {

    /*
    if (!app.documents.length) {
        alert("No document open.");
        return;
    }
    */

    // Get foreground and background colors
    var fgColor = app.foregroundColor.lab;
    var bgColor = app.backgroundColor.lab;

    var fgLab = [Math.round(fgColor.l), Math.round(fgColor.a), Math.round(fgColor.b)];
    var bgLab = [Math.round(bgColor.l), Math.round(bgColor.a), Math.round(bgColor.b)];

    // Calculate dE94
    var dE94 = calculateCIE94(fgLab, bgLab);

    alert("Foreground vs. Background Color Picker Difference\n" +
        "Foreground color (L:" + fgLab[0] + " a:" + fgLab[1] + " b:" + fgLab[2] + ")\n" +
        "Background color (L:" + bgLab[0] + " a:" + bgLab[1] + " b:" + bgLab[2] + ")\n" +
        "The CIE94 color difference is: " + dE94.toFixed(2));
}

main();

 

 

 

/*
    Calculates the CIEDE2000 (dE00) color difference between the foreground and background colors in Photoshop
    v1.1
    https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-does-photoshop-calculate-lab-values/m-p/15028840
*/

#target photoshop

function calculateCIEDE2000(lab1, lab2) {
    // Weighting factors
    var kL = 1;
    var kC = 1;
    var kH = 1;

    // Helper functions
    function degToRad(deg) {
        return (deg * Math.PI) / 180;
    }
    function radToDeg(rad) {
        return (rad * 180) / Math.PI;
    }

    // Calculate chroma
    var c1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]);
    var c2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]);

    // Mean chroma
    var cBar = (c1 + c2) / 2;

    // Calculate G
    var g = 0.5 * (1 - Math.sqrt(Math.pow(cBar, 7) / (Math.pow(cBar, 7) + Math.pow(25, 7))));

    // Adjusted a values
    var a1Prime = lab1[1] * (1 + g);
    var a2Prime = lab2[1] * (1 + g);

    // Recalculate chroma with adjusted a values
    var c1Prime = Math.sqrt(a1Prime * a1Prime + lab1[2] * lab1[2]);
    var c2Prime = Math.sqrt(a2Prime * a2Prime + lab2[2] * lab2[2]);

    // Mean chroma prime
    var cBarPrime = (c1Prime + c2Prime) / 2;

    // Calculate h primes
    var h1Prime = Math.atan2(lab1[2], a1Prime);
    var h2Prime = Math.atan2(lab2[2], a2Prime);

    if (h1Prime < 0) h1Prime += 2 * Math.PI;
    if (h2Prime < 0) h2Prime += 2 * Math.PI;

    var hBarPrime = Math.abs(h1Prime - h2Prime) > Math.PI
        ? (h1Prime + h2Prime + 2 * Math.PI) / 2
        : (h1Prime + h2Prime) / 2;

    // Delta h prime
    var deltaHPrimeRaw = Math.abs(h1Prime - h2Prime) > Math.PI
        ? h2Prime - h1Prime + 2 * Math.PI * (h2Prime <= h1Prime ? 1 : -1)
        : h2Prime - h1Prime;

    // Delta L, C, and H primes
    var deltaLPrime = lab2[0] - lab1[0];
    var deltaCPrime = c2Prime - c1Prime;
    var deltaHPrime = 2 * Math.sqrt(c1Prime * c2Prime) * Math.sin(deltaHPrimeRaw / 2);

    // Weighting functions
    var lBar = (lab1[0] + lab2[0]) / 2;
    var t = 1
        - 0.17 * Math.cos(hBarPrime - degToRad(30))
        + 0.24 * Math.cos(2 * hBarPrime)
        + 0.32 * Math.cos(3 * hBarPrime + degToRad(6))
        - 0.20 * Math.cos(4 * hBarPrime - degToRad(63));

    var sl = 1 + ((0.015 * Math.pow(lBar - 50, 2)) / Math.sqrt(20 + Math.pow(lBar - 50, 2)));
    var sc = 1 + 0.045 * cBarPrime;
    var sh = 1 + 0.015 * cBarPrime * t;
    var deltaTheta = degToRad(30) * Math.exp(-Math.pow((hBarPrime - degToRad(275)) / degToRad(25), 2));
    var rc = 2 * Math.sqrt(Math.pow(cBarPrime, 7) / (Math.pow(cBarPrime, 7) + Math.pow(25, 7)));
    var rt = -rc * Math.sin(2 * deltaTheta);

    // CIEDE2000 formula
    var dE00 = Math.sqrt(
        Math.pow(deltaLPrime / (kL * sl), 2) +
        Math.pow(deltaCPrime / (kC * sc), 2) +
        Math.pow(deltaHPrime / (kH * sh), 2) +
        rt * (deltaCPrime / (kC * sc)) * (deltaHPrime / (kH * sh))
    );

    return dE00;
}

function main() {

    /*
    if (!app.documents.length) {
        alert("No document open.");
        return;
    }
    */

    // Get foreground and background colors
    var fgColor = app.foregroundColor.lab;
    var bgColor = app.backgroundColor.lab;

    var fgLab = [Math.round(fgColor.l), Math.round(fgColor.a), Math.round(fgColor.b)];
    var bgLab = [Math.round(bgColor.l), Math.round(bgColor.a), Math.round(bgColor.b)];

    // Calculate dE00
    var dE00 = calculateCIEDE2000(fgLab, bgLab);

    alert("Foreground vs. Background Color Picker Difference\n" +
        "Foreground color (L:" + fgLab[0] + " a:" + fgLab[1] + " b:" + fgLab[2] + ")\n" +
        "Background color (L:" + bgLab[0] + " a:" + bgLab[1] + " b:" + bgLab[2] + ")\n" +
        "The CIEDE2000 color difference is: " + dE00.toFixed(2));
}

main();

 

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

The prepression.blogspot.com website was blocked "due to riskware." 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

quote

The prepression.blogspot.com website was blocked "due to riskware." 


By @scotwllm

 

¯\_(ツ)_/¯

 

I had major problems with Google not liking the JavaScript code samples and I had to take them down. Some security software or other sites may not like something there like the ExifTool commands, so who knows.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

That's too bad. I was looking forward to reading it. I've noticed that lots of sites with color info are blocked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2024 Dec 09, 2024

Copy link to clipboard

Copied

quote

That's too bad. I was looking forward to reading it. I've noticed that lots of sites with color info are blocked.


By @scotwllm


All of the information is there and there is nothing nefarious IMHO. Use different browsers or not, it's up to you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

Colour management.

 

Make 2 separate RGB files, one sRGB, the other ProPhoto RGB. Type in the same set of RGB values and compare the Lab readings. Type in the same Lab values and compare the RGB readings.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2024 Dec 06, 2024

Copy link to clipboard

Copied

color_2.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

I found the answer. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

quote

I found the answer. 


By @scotwllm

Does that actually honor the RGB Color Space? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

כן

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

@scotwllm 

That's exactly what I'm saying. That does not specify the RGB color space, and that makes it completely worthless.

What I've posted is the correct answer. I can't take responsibility for incorrect and misleading information you may find out on the internet.

 

All Photoshop number calculations use the open document color space first, and if that doesn't apply, it goes to your working spaces.

 

All RGB numbers refer to a specific color space: sRGB, Adobe RGB, etc. That's what a color space is - a definition of the numbers relative to a reference. That reference is Lab.

 

EDITED for clarity

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

It was not the correct answer to *my* question. The correct answer to *my* question needed to contain the formula Adobe uses to convert RGB values to Lab in its color picker. I didn't ask about color spaces or why Lab is the best or any of that stuff you wrote about. Maybe someone else asked you about those things, but I sure didn't.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

The correct answer is that RGB numbers without specifying the RGB color space those numbers refer to are meaningless. There is no "RGB", there is only sRGB, Adobe RGB, ProPhoto RGB etc.

 

The RGB numbers will be different in all these color spaces, for the same color. And vice versa.

 

But they all have a common reference at the bottom, and that reference is Lab. Lab numbers defines the color absolutely. That is why Lab is used as a PCS, profile connection space, in all color management (together with CIE XYZ).

 

I honestly thought the screenshot I posted would make this very clear and obvious.  Please look at it again and note the numbers. You can replicate this yourself in Photoshop if you don't think it's correct.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

Yes. I saw it and know what it means. I also know how to make screengrabs. The color picker doesn't ask about sRGB or Adobe RGB or ProPhoto RGB, etc. It just says RGB. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2024 Dec 08, 2024

Copy link to clipboard

Copied

quote

The color picker doesn't ask about sRGB or Adobe RGB or ProPhoto RGB, etc. It just says RGB. 

That’s not a relevant observation, the Color Space is clear based on the image or (if the image is unprofiled) Photoshop’s Color Settings. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2024 Dec 09, 2024

Copy link to clipboard

Copied

There is - or should always be! - an embedded color profile. This is what Photoshop uses for the calculation:

notification_3.png

 

All numbers primarily refer to the color space of the open document. Secondarily, if the calculation is across different modes so that there isn't an open document to refer to, Photoshop goes to your working spaces as the reference for the numbers. It also does that if the document is missing an embedded profile.

 

Another, simpler way of saying this is that the embedded color profile overrides the working space.

 

But Lab is always constant, as the underlying reference for everything. The whole color management architecture is built upon this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines