Copy link to clipboard
Copied
Hi guys.
Someone tell me how I can get the number of pixels in the alpha channel of an image layer ?
Copy link to clipboard
Copied
More information is required, ideally you can attach samples. Black, white or shades of grey?
I think that I recall a script for how many pixels in an irregular selection and one can load an alpha as selection...
Copy link to clipboard
Copied
Someone tell me how can I get the number of pixels in the alpha channel of an image layer whose transparency value is 0.
Sorry///
Copy link to clipboard
Copied
While you're back to forum, was the answer given in Photoshop Scripting. How to put each closed path on a separate Path layer ? that you were looking for?
Copy link to clipboard
Copied
Yes, I already use this knowledge.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Algorithm (the hint).
Turn the transparency channel into a selection (ctrl+click on layer )
Save it to new alpha channel.
Select only this alpha channel.
Read the document's histogram value at index 255.
Copy link to clipboard
Copied
Thank you, r-bin...
Copy link to clipboard
Copied
That seems to be solution - mark it as correct answer if you think so š
Copy link to clipboard
Copied
the code
// create temp channel from layer transparency
var tmp_name = Math.random().toString();
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("name"), tmp_name);
d1.putEnumerated(stringIDToTypeID("colorIndicates"), stringIDToTypeID("maskIndicator"), stringIDToTypeID("selectedAreas"));
d.putObject(stringIDToTypeID("new"), stringIDToTypeID("channel"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d1.putReference(stringIDToTypeID("to"), r);
d1.putBoolean(stringIDToTypeID("invert"), true);
d1.putBoolean(stringIDToTypeID("preserveTransparency"), true);
d.putObject(stringIDToTypeID("with"), stringIDToTypeID("calculation"), d1);
executeAction(stringIDToTypeID("applyImageEvent"), d, DialogModes.NO);
// get histogram
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("histogram"));
r.putName(stringIDToTypeID("channel"), tmp_name);
var ret = executeActionGet(r).getList(stringIDToTypeID("histogram"));
var hist = new Array();
for (var i = 0; i < 256; i++) hist.push(ret.getInteger(i));
// delete temp channel
var d = new ActionDescriptor();
var r = new ActionReference();
r.putName(stringIDToTypeID("channel"), tmp_name);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);
// alert number of pixels with opacity==0 & opacity==100
alert(hist[255] + "\n" + hist[0])