-
1. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 8, 2014 12:29 AM (in response to Monstrik)How would you do it manually?
-
2. Re: Selecting the brightest pixels
Monstrik Sep 8, 2014 7:47 AM (in response to c.pfaffenbichler)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.
-
3. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 8, 2014 11:35 PM (in response to Monstrik)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.
-
4. Re: Selecting the brightest pixels
Monstrik Sep 9, 2014 2:54 PM (in response to c.pfaffenbichler)But can this be scripted, and work as quickly as loading any selection?
-
5. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 10, 2014 1:12 AM (in response to Monstrik)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.
-
6. Re: Selecting the brightest pixels
Monstrik Sep 12, 2014 11:51 PM (in response to c.pfaffenbichler)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?
-
7. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 14, 2014 6:54 AM (in response to Monstrik)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.
-
8. Re: Selecting the brightest pixels
Monstrik Sep 14, 2014 11:57 PM (in response to c.pfaffenbichler)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
-
9. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 12:23 AM (in response to Monstrik)When you switch to Quick Mask Mode the Selection is stored as a Channel, use that Channel’s Histogram.
-
10. Re: Selecting the brightest pixels
Monstrik Sep 15, 2014 2:30 AM (in response to c.pfaffenbichler)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?
-
11. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 2:38 AM (in response to Monstrik)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.
-
12. Re: Selecting the brightest pixels
Monstrik Sep 15, 2014 5:56 AM (in response to c.pfaffenbichler) -
13. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 6:35 AM (in response to Monstrik)You are trying to run the Script in ESTK, not Photoshop.
-
14. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 7:00 AM (in response to c.pfaffenbichler)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, …).
-
15. Re: Selecting the brightest pixels
Monstrik Sep 15, 2014 8:33 AM (in response to c.pfaffenbichler)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
-
16. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 8:40 AM (in response to Monstrik) -
17. Re: Selecting the brightest pixels
Monstrik Sep 15, 2014 12:29 PM (in response to c.pfaffenbichler)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?
-
18. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 15, 2014 11:34 PM (in response to Monstrik)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).
-
19. Re: Selecting the brightest pixels
Monstrik Sep 16, 2014 1:44 AM (in response to c.pfaffenbichler)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...
-
20. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 16, 2014 2:09 AM (in response to Monstrik)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.
-
21. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 16, 2014 2:14 AM (in response to c.pfaffenbichler)Also you need to add the code to load the Selection from that Channel (and then remove the Channel).
-
22. Re: Selecting the brightest pixels
Monstrik Sep 16, 2014 8:58 PM (in response to c.pfaffenbichler)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?
-
23. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 16, 2014 11:18 PM (in response to Monstrik)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.
-
24. Re: Selecting the brightest pixels
Monstrik Sep 17, 2014 6:12 AM (in response to c.pfaffenbichler)I guess you are right. Otherwise i will never learn... I will try
I have a question is it possible to make this script use the value that It alerts me of in Threshold? I mean so i dont have to click ok... Or is this value something i must inevitably be aware of? Basically my question: can i make this script do it all?
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? 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?
-
25. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 17, 2014 11:57 PM (in response to Monstrik)I have a question is it possible to make this script use the value that It alerts me of in Threshold?
Of course.
• You need to select the Channel.
In the DOM activeDocument.activeChannels can be used for this, but keep in mind that this needs an Array!
• Then you should put theIndex in the line
desc33.putInteger( idLvl, 12 );
instead of the originally recorded value.
• Then load the Channel as a Selection (check out the Class "Selection" in ESTK’s Object Model Viewer to see how one can load a channel as a Selection).
• after that you can remove the Channel
-
26. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 18, 2014 12:00 AM (in response to Monstrik)Some of the images you posted are inconvenient to me because of the loading time and because they are displayed downscaled in my browser – please post the screenshots individually and when you talk about code please post it, not just a screenshot of it.
-
27. Re: Selecting the brightest pixels
Monstrik Sep 22, 2014 3:17 AM (in response to c.pfaffenbichler)Hey Christoph, first of all thank you for helping me out...i appreciate your patience
im going to continue asking you questions
as i understand you instructed me to select the channel after i run the script your wrote... but i dont know how to do that... i tried to use this object model viewer... but im not even sure how to use it.. as you see (image 1) i tried to find out how to select the channel, but i see no codes..? please guide me
In the DOM activeDocument.activeChannels can be used for this, but keep in mind that this needs an Array!
i really dont understand this sentence.. what is DOM? also i looked up ARRAY...[Definition: In math, an array refers to a set of numbers or objects that will follow a specific pattern. An array is an orderly arrangement, often in rows, columns or a matrix] why should i keep this in mind?
• Then you should put theIndex in the line
you mean i should put this line at the end of this code?
instead of the originally recorded value.
I dont understand what is the originally recorded value?
• Then load the Channel as a Selection (check out the Class "Selection" in ESTK’s Object Model Viewer to see how one can load a channel as a Selection)
Again i looked at the object model viewer.. not sure i understand what to look at? (image 2)
-
28. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 4:56 AM (in response to Monstrik)i really dont understand this sentence.. what is DOM? also i looked up ARRAY
DOM stands for Document Object Model and is contrasted against Action Manager code (the one recorded with ScriptingListener.plugin).
An Array in JavaScript can be a collection of Numbers, Strings, Arrays, … and can be signified by square brackets.
So to create an Array of the last Channel
var theArray = [app.activeDocuments.channels[app.activeDocuments.channels.length - 1]];
I dont understand what is the originally recorded value?
The value you used in the Threshold operation when you recorded it.
Again i looked at the object model viewer.. not sure i understand what to look at? (image 2)
You had looked up
Selection.load
What arguments does this take?
A Channel, SelectionType and a boolean argument.
(Edit: In the brackets after "activeDocument.selection.load" you need to indicate the channel to load, how the Selection will be combined with a potentially existing Selection and whether it should be inverted.)
-
29. Re: Selecting the brightest pixels
Monstrik Sep 22, 2014 5:53 AM (in response to c.pfaffenbichler)Sorry im still lost... what is....
an Array of the last Channel
and please tell me what does this code do? and what i should to do with it?
var theArray = [app.activeDocuments.channels[app.activeDocuments.channels.length - 1]];
and still, please tell me where did you get this from?
Selection.load
and do i put this code into this one? like this?
var theArray = [app.activeDocuments.Selection.load[app.activeDocuments.Selection.load.length - 1]];
The only thing i think i understand is that i take this code from the last line of the script you wrote
and paste it instead of number 12?
#target photoshop
// 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);
// =======================================================
var idThrs = charIDToTypeID( "Thrs" );
var desc33 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc33.putInteger( idLvl, theIndex );
executeAction( idThrs, desc33, DialogModes.NO );
the script seems to be working.. and it seems it takes the threshold value and uses it to create a channel..which is great...
here im not sure what i should do...
(Edit: In the brackets after "activeDocument.selection.load" you need to indicate the channel to load, how the Selection will be combined with a potentially existing Selection and whether it should be inverted.)
and where did you get this from?
activeDocument.selection.load
-
30. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 6:07 AM (in response to Monstrik)and what i should to do with it?
You should use it to select that Channel.
activeDocument.activeChannels = theArray;
var theArray = [app.activeDocuments.Selection.load[app.activeDocuments.Selection.load.length - 1]];
That’s nonsense, a method (like load) needs brackets, not square brackets and there is no need to define the Selection as an Array (or call it theArray).
Selection does not exist on its own, it exists only with a document.
So to load a Channel you need to reference the document:
activeDocument.selection.load()
And in the brackets note the Channel, the SelectionType and the boolean argument for inverting.
If you do not understand the OMV yet I recommend you search for sample Scripts.
For example a search on this Forum for "selection.load" pointed to this:
-
31. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 6:08 AM (in response to c.pfaffenbichler)You should use it to select that Channel.
By this I mean "select the Channel", not "load the Channel as a Selection".
-
32. Re: Selecting the brightest pixels
Monstrik Sep 22, 2014 6:58 AM (in response to c.pfaffenbichler)First can you please tell me what im missing to achieve selection of the brightest pixel or pixels? because im getting confused
now, I have this code...
#target photoshop
// 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);
// =======================================================
var idThrs = charIDToTypeID( "Thrs" );
var desc33 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc33.putInteger( idLvl, theIndex );
executeAction( idThrs, desc33, DialogModes.NO );
activeDocument.activeChannels = theArray;
please tell me in order what's left to do?
- To select the channel
- Load the channel
- ...
-
33. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 7:17 AM (in response to Monstrik)You need to select the Channel to which you want to apply Threshold.
-
34. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 7:22 AM (in response to Monstrik)And after applying Threshold you need to load the Channel as a Selection.
-
35. Re: Selecting the brightest pixels
Monstrik Sep 22, 2014 7:38 AM (in response to c.pfaffenbichler)But i thought that this part of the code has already applied threshold.. no?
// =======================================================
var idThrs = charIDToTypeID( "Thrs" );
var desc33 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc33.putInteger( idLvl, theIndex );
executeAction( idThrs, desc33, DialogModes.NO );
activeDocument.activeChannels = theArray;
-
36. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 22, 2014 8:01 AM (in response to Monstrik)But to the active Channel/s.
Is the last Channel already selected?
-
37. Re: Selecting the brightest pixels
Monstrik Sep 23, 2014 9:25 AM (in response to c.pfaffenbichler)the last channel is selected after i run the script and also before i run the script, because i use calculations command.. so before i run this script
#target photoshop
// 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--
};
// =======================================================
var idThrs = charIDToTypeID( "Thrs" );
var desc33 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc33.putInteger( idLvl, theIndex );
executeAction( idThrs, desc33, DialogModes.NO );
i use calculations and get this
then i run the script and get this
Please tell me what's left to do? how would you select the brightest pixel/pixels?
-
38. Re: Selecting the brightest pixels
boo radley 2013 Sep 23, 2014 2:44 PM (in response to Monstrik)why don't you just use a "levels" adjustment layer ontop of the layer you need to select the brightest pixels from?
1. add levels adjustment layer ontop of the layer that you need to select the brightest pixels from
2. in the levels panel, pull the middle slider far to the right, but not all the way
3. pull the left slider just a bit to the left
now your image should be black, except for the bright pixels. You can tweak this to your needs by slightly moving those sliders again
4. merge the adjutsment layer with the layer below (your brightest pixel layer)
5. using the magic wand, select anywhere that is dark (black pixels)
6. invert your selection, and you now have the brightest pixles selected
I tried this on your "bubbles" image and it worked fine
-
39. Re: Selecting the brightest pixels
c.pfaffenbichler Sep 23, 2014 11:40 PM (in response to Monstrik)Use
activeDocument.selection.load(/*insert the Channel here*/, SelectionType.REPLACE, false)












