Highlighted

Scripting - Accessing selection values of each pixel or alternative methohs

New Here ,
Oct 04, 2020

Copy link to clipboard

Copied

Hi! I'm new in Photoshop scripting, but not to JavaScript (I usually code in Unity).

I need to create a script that analizes the current selection. I studied the scripting documentations but I didn't find anything useful. I also used ScriptingListener and obtained some generic actions, but nothing specific for my purpose.

I supposed that I might have to store the selection in a channel, but then I can't find how to access the pixels of that channel.

 

Please could you point me to a solution or to some more specific documentation?

 

Thankyou!

TOPICS
Actions and scripting

Views

180

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

Scripting - Accessing selection values of each pixel or alternative methohs

New Here ,
Oct 04, 2020

Copy link to clipboard

Copied

Hi! I'm new in Photoshop scripting, but not to JavaScript (I usually code in Unity).

I need to create a script that analizes the current selection. I studied the scripting documentations but I didn't find anything useful. I also used ScriptingListener and obtained some generic actions, but nothing specific for my purpose.

I supposed that I might have to store the selection in a channel, but then I can't find how to access the pixels of that channel.

 

Please could you point me to a solution or to some more specific documentation?

 

Thankyou!

TOPICS
Actions and scripting

Views

181

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
Oct 04, 2020 0
Adobe Community Professional ,
Oct 04, 2020

Copy link to clipboard

Copied

You can run Adobe Bridge in background with Photoshop, then by BridgeTalk (that is all Adobe apps specific) communicate from Ps to Br (in which you can use new BitmapData()) and back. Some Br BitmapData thread

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
Reply
Loading...
Oct 04, 2020 3
New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

This seems to be a solution, but I wonder why I need to use Bridge. I have to study this function.

I expected that each ArtLayer had a property where the mask channel was linked, and for each channel one could access the pixels array data.

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
Reply
Loading...
Oct 05, 2020 0
Adobe Community Professional ,
Oct 05, 2020

Copy link to clipboard

Copied

With Bridge you have straightforward function to have all exported layer pixels, while in Photoshop you must write it yourself reading and understanding binaries.

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
Reply
Loading...
Oct 05, 2020 0
Adobe Community Professional ,
Oct 04, 2020

Copy link to clipboard

Copied

How exactly do you want to analyze the selected pixels?

You can get a histogram for these pixels.
Based on the histogram, you can, for example, calculate an average value for the color of these pixels.
 

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
Reply
Loading...
Oct 04, 2020 1
New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

I would like to check how much each pixel is selected. I have to check everyone.

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
Reply
Loading...
Oct 05, 2020 0
LEGEND ,
Oct 05, 2020

Copy link to clipboard

Copied

Please elaborate what you are actually trying to achieve. 

What are you intending to do with the information for each individual pixel? 

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
Reply
Loading...
Oct 05, 2020 0
New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

I can't explain exactly, but I need it. Is it impossible to do?

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
Reply
Loading...
Oct 05, 2020 0
LEGEND ,
Oct 05, 2020

Copy link to clipboard

Copied

Once again: Please elaborate what you are actually trying to achieve. Post screenshots or sketches if necessary. 

 

Evaluating stuff per pixel with Photoshop Scripts is possible but usually the atrocious performance for all but the most miniscule images makes it nonsensical. 

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
Reply
Loading...
Oct 05, 2020 1
Enthusiast ,
Oct 05, 2020

Copy link to clipboard

Copied

Photoshop does not give scripts direct access to pixel arrays. This data can be obtained either indirectly (histogram, iterative reading of the eyedropper), or using other programs / scripts (having previously saved the image fragment you need to disk).

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
Reply
Loading...
Oct 05, 2020 2
New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

Thankyou for the answer. This could be an idea! I could save the mask of the selection to a bitmap, and elaborate it outside!

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
Reply
Loading...
Oct 05, 2020 0
Enthusiast ,
Oct 05, 2020

Copy link to clipboard

Copied

Kukurykus offered exactly the same option. It is convenient to use the bridge because you can not interrupt the script's work - just wait for a response from the function sent via BridgeTalk. Another thing is that you stay within js, it imposes certain restrictions.

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
Reply
Loading...
Oct 05, 2020 2
Adobe Community Professional ,
Oct 05, 2020

Copy link to clipboard

Copied

You need to look not towards scripts, but towards plugins.
Photoshop works very poorly with large arrays in scripts.
Check how long such a script works.
var a = new Array();

alert()
for (var i = 0; i < 1000000; i++) a.push(i);
alert()

Just processing a 1000x1000 pixel array of one channel. It seems to be not a large fragment of the image.
 

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
Reply
Loading...
Oct 05, 2020 2
New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

Ok, thankyou for your suggestion. I'll look at plugins too!

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
Reply
Loading...
Oct 06, 2020 0