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

Selecting the brightest pixels

Explorer ,
Sep 07, 2014 Sep 07, 2014

Hello

Is it possible to write a script that finds brightest pixel or pixels (if there are more of them at the same brightness) in an active layer and selects them?

if there is an easier way to do that, (without writing a script) please tell me how...

TOPICS
Actions and scripting
8.4K
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
Adobe
Community Expert ,
Sep 08, 2014 Sep 08, 2014

How would you do it manually?

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
Explorer ,
Sep 08, 2014 Sep 08, 2014

That is the problem, i dont really know. One possible solution, but very very slow, even if it was made as an action would be "blend if sliders". I would push the dark slider to the right until i have no visible pixels left. Then i would do ctrl+click on the layer to select transparency, and do inverse selection twice to see if the selection remains In tact. If it dissapears, then there were no pixels to select. Therefore i would push the slider back through one luminosity step and do the same again by inverting the selection twice.

If the selection remains, then there is a pixel or more selected. Probably that is how i would know i got the brightest pixel or pixels. Or maybe i could push the white slider to the left and look for pixels dissapearing. Then again, click for transparency, inverse, inverse.

But that is crazy. I need a quick way of doing it; just boom and there it is - brightest pixel/s selected.

if my poor english is an obtacle to understand what i wrote here, please tell me, i would post screenshots.

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
Community Expert ,
Sep 08, 2014 Sep 08, 2014

Loading and re-loading etc. the Transparency may be a bit time consuming. (I don’t understand what the double inversion is supposed to achieve.)

I would recommend storing the luminance in a new file and using a Solid Color Layer set to Blend Mode Lighten (starting with 254/254/254) and check the Histogram.

As long as all the pixels have the same value no lighter pixel can be underneath, so when the Histogram starts showing more than one spike that would be the indicator and the appropriately adjusted Channel can be used as a Layer Mask.

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
Explorer ,
Sep 09, 2014 Sep 09, 2014

But can this be scripted, and work as quickly as loading any selection?

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
Community Expert ,
Sep 10, 2014 Sep 10, 2014

I think it can be Scripted but will not be as fast as that by a long run.

Scripts are just like "smarter" Actions, they only utilise the same functionalities you can use manually, for more intricate needs proper plug-ins may be necessary.

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
Explorer ,
Sep 12, 2014 Sep 12, 2014

So i guess before i ask for any script i must come up with a way of doing it manually that works fast...

How long would your offered method take, if it was scripted (Approx)? Is it like 10min, or 10 seconds?

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
Community Expert ,
Sep 14, 2014 Sep 14, 2014

Dang, the issue may be a lot simpler than I originally thought.

The Selection’s Histogram (in Quick Mask Mode) can be used too determine the first value that has more than zero pixels going back from 255, Image > Adjustments > Threshold can then be used to edit the Selection accordingly.

Of course this can result in a Selection of literally one pixel.

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
Explorer ,
Sep 14, 2014 Sep 14, 2014

Can you please give me more details on how to do that...for example im not sure what is selection's histogram... As i understand it is a histogram of a selected area? Am i right? even so, i dont understand how to do that.. Please explain

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

When you switch to Quick Mask Mode the Selection is stored as a Channel, use that Channel’s Histogram.

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
Explorer ,
Sep 15, 2014 Sep 15, 2014

I hate to be a nuisance but could you help me a little bit more. I still dont understand how to do this...can you explain step by step please... im not getting it... So for example i take a random image, what is the first thing i do?

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

Load the luminance, switch to Quick Mask Mode.

Then use something like this to determine the brightest value in the Histogram.

// check the histogram;

var theHist = activeDocument.channels[activeDocument.channels.length - 1].histogram;

var theCheck = false;

var theIndex = 255;

while (theCheck == false) {

var thePixels = theHist[theIndex];

// if the value has more than one pixels;

if (thePixels > 0) {var theCheck = true};

theIndex--

};

alert (theIndex);

Then use that with Threshold for example.

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
Explorer ,
Sep 15, 2014 Sep 15, 2014

Please im still stuck.. help.. please look at the screenshots... what am i doing wrong?

luminosity 5.jpg

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

You are trying to run the Script in ESTK, not Photoshop.

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

I omitted the line

#target photoshop

because the code was only a fragment that you need to combine with the other steps anyway (the Selection, Quick Mask Mode, …).

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
Explorer ,
Sep 15, 2014 Sep 15, 2014

Can you please tell me how to run the script in photoshop? . Sorry but i didnt know there is way to run scripts inside photoshop

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

You can determine the target application with code ("#target photoshop") or in the Window.

You can also put the jsx file in Photoshop’s Scripts Folder.

estkApplicationSelection.jpg

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
Explorer ,
Sep 15, 2014 Sep 15, 2014

i got it... It worked, but i've faced another problem.... If the image is darker than 128 i get this warning:

No pixels are more than 50% selected

And therefore photoshop doesnt place marching ants


I need photoshop to select any pixel, doesnt matter if it is very bright or pretty dark.  So if i use a very dark image, it doesnt do the job... how could this be fixed?

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
Community Expert ,
Sep 15, 2014 Sep 15, 2014

So use something other than loading the composite as a Selection and Quick Mask (which does raise the alert but does not affect the operation otherwise).

Image > Calculations for example can be used to create a Channel (using Gray Channel for both Sources and Blending Normal).

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
Explorer ,
Sep 16, 2014 Sep 16, 2014

Please tell me what i'm doing wrong... this time i've faced two problems.. one: the script doesnt place marching ants after i run the script? what did i do wrong? (please have a look at the screenshots). Second problem: it seems like it includes more values than the very brightest pixels or pixel...

script doesnt work B.P 6.jpg

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
Community Expert ,
Sep 16, 2014 Sep 16, 2014

Why so you use "Merged" and "Layer 0"?

I already mentioned that you need to use the value that the code I posted alerts you of in Threshold.

You should create the code for that yourself.

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
Community Expert ,
Sep 16, 2014 Sep 16, 2014

Also you need to add the code to load the Selection from that Channel (and then remove the Channel).

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
Explorer ,
Sep 16, 2014 Sep 16, 2014

I used layer 0 so i could use the blend if slider to check. it doesnt have to be merged or layer 0.


Would it be possible for you to write a script so it does include this threshold operation, please? Could you please make the script do it all? For example: i have an active layer, i click run the script and i get the marching ants selecting the brightest pixel or pixels?? Is it even possible?

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
Community Expert ,
Sep 16, 2014 Sep 16, 2014

If this was the first time I tried to help you it would be one thing, but as it is I think you should learn to do more of your Scripts yourself.

Use ScriptingListener.plugin to record Threshold and have that code take the intended value and apply it to the Channel.

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
Explorer ,
Sep 17, 2014 Sep 17, 2014

I guess you are right. Otherwise i will never learn... I will try

But i believe it will take several months or more until i finish this script. Im a dummy when comes to photoshoping let alone scripting. I'm still learning. And i have learned a lot from this forum. So please gime me time and please help. Let me learn how to script to open a document first. You know how i felt when you said i should do it myself, i felt like Neo in Matrix entering the operator's room

image.jpg

ok this is what i did... i created an aplha channel using calculations (as you said)... i ran the script you wrote.. and then i used threshold to record its code...do i paste that code into ESTK? And then how do i have this code take the intended value and apply it to the channel... To be honest I dont know what you mean by saying "apply to the channel". I dont even understand how would this have photoshop select brightest pixels?

dont give up on me yet, please help...

scripting plugin 8.jpg

Edit: you said that i should use threshold to edit the selection the script creates, but the script doesnt create any selection...what i am doing wrong?

scripting plugin 9.jpg

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