If you want best performance, maybe you could use SDK and write custom filter in C++
This should be fastest :-D There are some premade examples. Filter should be able read pixels in certain layer because filter change pixel values in certain layer.
Simple but not very effecient way in JS.
Make rectangular selection
Copy merged bitmap
Paste it into new document
Read histogram data of this document
Repeat with different selection if you need.
I understand. Is there a way you can provide a simple example of how to make use the histogram data? Looking at the programming index, it looks like it is an array of 255 members, but not much more information is given.
Each array item contains number how many pixels has this level of luminosity.
item 0 = black pixels
item 255 = white pixels
Or opposite. I am not sure.
I see. hmm. This sounds like its going to get a bit complicated. Less complicated, though, i bet, than learning c++. Thanks man, i'm going to give it a shot and see what comes of it.
You can use Color sampler for individual pixels. No new document needed. But this could be very slow with large images.
I can confirm, item 0 is black, item 255 is white.
Actually, the histogram is read from the active channels.
Therefore, it should be possible to turn the selection in its own channel, hide all other channels, read out the histogram, analyze the data, do what's needed, dump the channel and make the other channels visible again.
Depending on the kind of pictures, it would be possible to start with a bigger selection and make it smaller only when the conditions are given.
As stated, it may be a bit time-consuming, but it should be quite straightforward.
Yes. You can invert selection and create new most top black layer from inverted selection.
So every pixel outside this selection will be in "item 0"
You can access into R G B channels directly without creating something new. I am not sure if this works for other channels.
Do you guys know if there is a way to easily access the histogram's mean? that way i can have it fire at a certain range?
What you get from Photoshop as histogram is, as already stated, an array of 256 elements, representing the number of pixels for a given grey value.
You can use Mike Hale's selectColorRange function (scObj) HERE
var blanc = new SolidColor();
blanc.rgb["hexValue"] = "ffffff" // "829fb1" // "0000ff";
for( var f = 0; f < activeDocument.artLayers.length; f++ )
activeDocument.activeLayer = activeDocument.artLayers[f];
function selectColorRange(scObj) // by Mike Hale - merci a lui :
var desc = new ActionDescriptor();
desc.putInteger( charIDToTypeID( "Fzns" ), 0 );
var cDesc = new ActionDescriptor();
cDesc.putDouble( charIDToTypeID( "Rd " ), scObj.rgb.red);
cDesc.putDouble( charIDToTypeID( "Grn " ), scObj.rgb.green);
cDesc.putDouble( charIDToTypeID( "Bl " ), scObj.rgb.blue );
desc.putObject( charIDToTypeID( "Mnm " ), charIDToTypeID( "RGBC" ), cDesc );
desc.putObject( charIDToTypeID( "Mxm " ), charIDToTypeID( "RGBC" ), cDesc );
executeAction( charIDToTypeID( "ClrR" ), desc, DialogModes.NO );
var ligneBlanc = activeDocument.selection.bounds;
var largeur = activeDocument.width;
alert("Hauteur = " + activeDocument.selection.bounds);
alert("Largeur = " + activeDocument.selection.bounds);
A little nitpicking (but needed, otherwise, the script would fail):
I hesitated !!!