Skip to main content
Participant
February 14, 2013
Question

accessing the pixels' alpha values within a script (the "a" of rgba) when scanning a layer

  • February 14, 2013
  • 1 reply
  • 6739 views

hi all,

I need to evaluate/scan all pixels of a given PSD layer via a script. for accessing the R, G, B values I

seached the script reference and found the RGBColor element as

Properties

Property Value type What it is

blue number [0..255] Read-write. The blue color value (default: 255).

green number [0..255] Read-write. The green color value (default: 255)

hexValue string Read-write. The hexadecimal representation of the color.

red number [0..255] Read-write. The red color value (default: 255)

typename string Read-only. The class name of the referenced RGBColor object.

BUT I NEED to evaluate the alpha value of the layer's pixels. where is this value stored?

is it mathematically imbedded in R, G and B?

does anybody has a sample for accessing all pixels of a layer?

thanks for any info and link to a sample script, or any note.

best

stephen

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
February 14, 2013

These are the values that are available for a selected pixel...

var mySampler = app.activeDocument.colorSamplers.add([new UnitValue( 100,'px'),new UnitValue(100,'px' )]);

var R = Math.round(mySampler.color.rgb.red); //Red Value

var G = Math.round(mySampler.color.rgb.green); //Green value

var B = Math.round(mySampler.color.rgb.blue); // Blue value

var hexColour = "#"+mySampler.color.rgb.hexValue;

var Hue = Math.round(mySampler.color.hsb.hue); //Hue value

var Saturation = Math.round(mySampler.color.hsb.saturation); //Saturation value

var Brightness = Math.round(mySampler.color.hsb.brightness); //Brightness value

var Opacity = activeDocument.activeLayer.opacity; //Layer opacity

FedtkeAuthor
Participant
February 15, 2013

thanks for your info. may I ask

* how can I determine (calculate) the alpha value of a pixel? the opacity in your formula is the global one of the layer.

* which other opacity values in other photoshop elements also control the final alpha of a pixel? channel?

* is there anything better (more efficient) given to access each pixel in a layer? programming a filter?

many thanks for any feedback!

stephen

Paul Riggott
Inspiring
February 15, 2013

That is all that is available that I know of, maybe someone knows better and can enlighten us.

For a filter you would have to look at the SDK and the people in this forum may help..

http://forums.adobe.com/community/photoshop/photoshop_sdk