Scripting. get the number of pixels in the alpha channel of an image layer ?

Community Beginner ,
Apr 04, 2022 Apr 04, 2022

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 ?

TOPICS
Actions and scripting

Views

193

Likes

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

Adobe Community Professional , Apr 04, 2022 Apr 04, 2022
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.

Likes

Translate

Translate
Adobe Community Professional ,
Apr 04, 2022 Apr 04, 2022

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...

Likes

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 Beginner ,
Apr 04, 2022 Apr 04, 2022

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///

Likes

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
LEGEND ,
Apr 04, 2022 Apr 04, 2022

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?

Likes

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 Beginner ,
Apr 04, 2022 Apr 04, 2022

Copy link to clipboard

Copied

Yes, I already use this knowledge.

Likes

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
LEGEND ,
Apr 05, 2022 Apr 05, 2022

Copy link to clipboard

Copied

Likes

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 Professional ,
Apr 04, 2022 Apr 04, 2022

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.

 

Likes

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 Beginner ,
Apr 04, 2022 Apr 04, 2022

Copy link to clipboard

Copied

Thank you, r-bin...

Likes

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
LEGEND ,
Apr 04, 2022 Apr 04, 2022

Copy link to clipboard

Copied

That seems to be solution - mark it as correct answer if you think so 😉

Likes

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 Professional ,
Apr 05, 2022 Apr 05, 2022

Copy link to clipboard

Copied

LATEST

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])

Likes

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