Skip to main content
Known Participant
September 7, 2014
Question

Selecting the brightest pixels

  • September 7, 2014
  • 4 replies
  • 8638 views

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

This topic has been closed for replies.

4 replies

c.pfaffenbichler
Community Expert
Community Expert
September 27, 2014

The pasted code was posted wrong again, the three spaces were changed to two spaces, I corrected that and the posted code seems to work properly.

So as far as I am concerned the issue is closed.

MonstrikAuthor
Known Participant
September 28, 2014

First of all, thank you very much for such an incredible work. based on my skills, i would've taken a year to write such script. I mean it. I appreciate that so much. Just one little issue i have encountered. i wonder if it is possible to fix it. If you have a little more time please see the images. I tested the script and learned that it selects more pixels than the very brightest. In other words, it includes pixels that are less as bright as the brightests..

i reduced exposure to make sure the difference is clearly visible...


Edit: we can see in the pictures that the brightest value is 14. But the script has also selected values which are lower than 14.


Inspiring
September 23, 2014

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

MonstrikAuthor
Known Participant
September 24, 2014

Boo Radley thank for your method. The problem is that im trying to make it work either as an action or, if it's not posssible , as a script.

c.pfaffenbichler
Community Expert
Community Expert
September 18, 2014

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.

c.pfaffenbichler
Community Expert
Community Expert
September 8, 2014

How would you do it manually?

MonstrikAuthor
Known Participant
September 8, 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.

c.pfaffenbichler
Community Expert
Community Expert
September 14, 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?


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.