Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
How would you do it manually?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
But can this be scripted, and work as quickly as loading any selection?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
When you switch to Quick Mask Mode the Selection is stored as a Channel, use that Channel’s Histogram.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Please im still stuck.. help.. please look at the screenshots... what am i doing wrong?
Copy link to clipboard
Copied
You are trying to run the Script in ESTK, not Photoshop.
Copy link to clipboard
Copied
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, …).
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
i got it... It worked, but i've faced another problem.... If the image is darker than 128 i get this warning:
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?
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Also you need to add the code to load the Selection from that Channel (and then remove the Channel).
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
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...
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?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now