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

RGB to LAB values via new solidcolor inaccurate?

Contributor ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

I've been trying to find a way of automating the sampling of an average color without duplicating a layer and using the filter average command. I work in AdobeRGB and prefer to read LAB numbers for color correction. However what i am finding is that the RGB to LAB conversion of numbers using a solidcolor object produces inaccurate numbers, is there function out there to convert adobeRGB to Lab numbers accurately???

i.e. 

 

RGB: 73.5023530022085 45.439188788593 39.9453177108809

 

outputs these numbers....

L*ab: 22.1099853515625,12.1768493652344,8.62826538085938

 

   sColor = new SolidColor();
red = getMean (0)
green = getMean (1)
blue = getMean (2)

sColor.rgb.red = red
 sColor.rgb.blue = blue
 sColor.rgb.green = green
$.writeln('RGB: '+ red +" "+ green + " "+ blue)

var labValues = rgbToLab(red, green, blue);

$.writeln('L*ab: '+ labValues)
copyTextToClipboard (desc)
alert( desc)


//debugger
function getMean(chanNo){

var histo = activeDocument.channels[chanNo].histogram
var mean = 0;  
var total = 0;  
for (var n = 0; n < histo.length; n++) {  
total = total + histo[n];  
};  
for (var m = 0; m < histo.length; m++) {  
var thisValue = histo[m];  
mean = mean + (m * thisValue / total);  
}; 
return mean}

function copyTextToClipboard( txt )
{
    const keyTextData         = app.charIDToTypeID('TxtD');
    const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

    var textStrDesc = new ActionDescriptor();

    textStrDesc.putString( keyTextData, txt );
    executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );
}


function rgbToLab(red, green, blue) {
  var color = new SolidColor;

  color.rgb.red = red;
  color.rgb.green = green;
  color.rgb.blue = blue;

  return [
    color.lab.l,
    color.lab.a,
    color.lab.b
  ]
}

The base of the code was brilliantly written by @c.pfaffenbichler 

on this post click here 

 

TOPICS
Actions and scripting

Views

813

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

correct answers 1 Correct answer

Community Expert , Jun 01, 2021 Jun 01, 2021

Is Adobe RGB also your RGB Working Space? 

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Is Adobe RGB also your RGB Working 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
Contributor ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Ahh bingo! moved to new version and forgot to update color settings. 

 

new result 

 

RGB: 64.6131759199016 34.4235433383937 26.7300612665365

L*ab: 17.12646484375,19.5230407714844,15.9044189453125

 

Is there a simple way to have this constantly refresh as a mini info pallet, i have never delved into modeless dialogs before, so still on simple scriptUI, and from what i read modeless dialogs quite buggy in scriptUI

 

 

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 ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Sorry, I haven’t familiarized myself with Adobe UXP, either. 

Maybe someone else has some insight.

 

If you want to check out UXP maybe start over on 

Adobe UXP: Things you need to know! #1 Rundown on the UXP announcement

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
Contributor ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

having a look at his videos at the moment, will come back when ive developed something 

 

many thanks for your help

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
Valorous Hero ,
Jun 01, 2021 Jun 01, 2021

Copy link to clipboard

Copied

Why is the rgbToLab() function needed

var labValues = rgbToLab(red, green, blue);

when all lab values are already in the SolidColor object?

var labValues = [sColor.lab.l, sColor.lab.a, sColor.lab.b];

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
Contributor ,
Jun 04, 2021 Jun 04, 2021

Copy link to clipboard

Copied

LATEST

to be honest before i posted here i was trying all sorts as i couldnt work out why the lab numbers were off. I know the function is not needed. 

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