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

Color Picker scripting or Levels algorithm help

Engaged ,
Oct 16, 2009 Oct 16, 2009

First question is: Does anyone know of a good explanation of the Levels algorithm as in how each setting affects a pixel in an image. If I change the midpoint of the levels, how would a specific pixel change in relation to that? I've been experimenting for hours and can't figure a common factor other than it seems to be a binary type relationship. The reason I ask this is because I'm trying to script something that will balance colors.

If that method isn't practical, I can go to the old fashioned trial and error method but this way also presents a roadblock to me. I set a color picker point and the script can obtain the values from that point exactly as it is in the Info panel. If I put a levels adjustment layer over top and adjust it, I now see the original color value and the adjusted color value in the Info panel, but I can't figure out how to obtain the adjusted value with a script. It still returns the original value. Does anyone know a way to obtain the adjusted value?

I hope I explained this right.

TOPICS
Actions and scripting
1.8K
Translate
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

Mentor , Oct 16, 2009 Oct 16, 2009

What version of Photoshop are you using and which layer was active when you ran the script? I guess that color space and bit depth might also matter.

With CS4, 8 bit RGB I get different values unless the adjustment layer was not visible when the script starts. It looks like perhaps your adjustment layer was off when you ran the script becuse you are seeing 226(rounded) in the alert

Translate
Adobe
Mentor ,
Oct 16, 2009 Oct 16, 2009

This thread may help with the levels part. http://ps-scripts.com/bb/viewtopic.php?t=2498

As for the adjustment layer you need to get the color twice. Once with the adjustment layer visible then again with it not visible.

var csColor = activeDocument.colorSamplers[0].color;
activeDocument.layers.getByName('Levels').visible = false;
var csColor2 = activeDocument.colorSamplers[0].color;
alert( csColor2.rgb.red + " : " + csColor.rgb.red );

Translate
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 ,
Oct 16, 2009 Oct 16, 2009

Thanks, Michael.

I'll have to look through that post on ps-scripts.com in more detail. That might be what I need.

This little snippet you wrote:

Michael L Hale wrote:

This thread may help with the levels part. http://ps-scripts.com/bb/viewtopic.php?t=2498

As for the adjustment layer you need to get the color twice. Once with the adjustment layer visible then again with it not visible.

var csColor = activeDocument.colorSamplers[0].color;
activeDocument.layers.getByName('Levels').visible = false;
var csColor2 = activeDocument.colorSamplers[0].color;
alert( csColor2.rgb.red + " : " + csColor.rgb.red );

doesn't get me the before and after values. Example: The point I selected has a red value of 226. I added a Levels adj layer on top and moved the midpoint so the red value at that point (adjusted) was 234. I ran your code and it came back with 225.591439688716 : 225.591439688716. It isn't showing the adjusted value of that point.

Translate
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
Mentor ,
Oct 16, 2009 Oct 16, 2009

What version of Photoshop are you using and which layer was active when you ran the script? I guess that color space and bit depth might also matter.

With CS4, 8 bit RGB I get different values unless the adjustment layer was not visible when the script starts. It looks like perhaps your adjustment layer was off when you ran the script becuse you are seeing 226(rounded) in the alert

Translate
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 ,
Oct 16, 2009 Oct 16, 2009

CS4 Extended. RGB/16.

The adjustment layer was visible and active when I ran the script. But I see now where I went wrong. The Rasterized layer should be active and not the adjustment layer. My bad. Thanks.

It works now.

Translate
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
Mentor ,
Oct 16, 2009 Oct 16, 2009
LATEST

Just so it's clear to anyone reading this thread.

If the adjustment layer is the activeLayer the color will be from either the layer mask( default reading ) if there is one or the top most visible layer with a pixel at that point( no mask ). If there is a mask  the mask color is returned even if there is a visible layer above the adjustment layer

If it's not the adjustment layer then it's the top most visible layer with a pixel at the point. That may or not be the activeLayer.

To ensure the activeLayer is the one the color is from your script will need to turn off all layers above the activeLayer.

Translate
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