Yes, that’s possible.
Take this as an example image:
You can read out the documents histogram with batchPlay. If you just need the brightest color of one specific layer, either merge your layers before that or make only said layer visible.
The histogram is an array of 255 values, representing the luminosity and the count of pixels for each luminosity. Btw, while researching this I learned that this is perceived luminosity, not absolute luminosity.
Here’s an excerpt of the histogram for my example document:
(Subtract 1 as array indexes start at 0, but my VSC line numbers start at 1)
…
As you can see, there are 18225 pixels with luminosity 0, representing the black rectangle of my image. The red rectangle has the same size and therefore the same amount of pixels for that luminosity value, which is 146.
Since you want the brightest color, reverse the array (to start at 255) and get the first index whose value is greater than 0 ( meaning that there are pixels in your image for that luminosity value).
Also, since we reversed the array, we should subtract the index from 255 to get the index of the non-reversed array.
const brightestLuminosity = 255 - histogram.reverse().findIndex(pixels => pixels > 0)
In my example, this results to 146, as expected.
You can then use the threshold filter to get a black and white representation of your document showing a specific luminosity (the brightest one we just found out) as white and all other luminosities as black:
Then simply make a pixel selection from the documents channel (for example RGB channel) et voilà:
You can use that selection for further processing like adding a gradient etc.