Copy link to clipboard
Copied
What would be the fastest way to detect which horizontal array of pixels is the first to be composed entirely of white pixels?
Copy link to clipboard
Copied
If you want best performance, maybe you could use SDK and write custom filter in C++
This should be fastest 😄 There are some premade examples. Filter should be able read pixels in certain layer because filter change pixel values in certain layer.
Anyway C++ is pretty hard and most people prefer scripting in JavaScript.
Copy link to clipboard
Copied
What would be the approach to take with javascript? I can't find a way to retrieve a pixels information.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You can use Color sampler for individual pixels. No new document needed. But this could be very slow with large images.
Copy link to clipboard
Copied
I can confirm, item 0 is black, item 255 is white.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
That's what you have to build your analysis and interpretation on. For that you are on your own, but JavaScript is powerful enough to let you implement any algorithm you need. You might have to find the algorithms, but for that, there is good literature around.
Copy link to clipboard
Copied
Thank you all very much for all your help. I did find an alternate tread that helps you figure out the mean in the histogram:
Copy link to clipboard
Copied
Bonjour
You can use Mike Hale's selectColorRange function (scObj) HERE
//SelectionLigneBlanche.jsx
var blanc = new SolidColor();
blanc.rgb["hexValue"] = "ffffff" // "829fb1" // "0000ff";
for( var f = 0; f < activeDocument.artLayers.length; f++ )
{
activeDocument.activeLayer = activeDocument.artLayers
; selectColorRange(blanc);
// activeDocument.selection.clear();
//activeDocument.selection.deselect();
}
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[2];
var largeur = activeDocument.width;
if (ligneBlanc=largeur)
{
//alert(activeDocument.selection.bounds[2]);
alert("Hauteur = " + activeDocument.selection.bounds[1]);
alert("Largeur = " + activeDocument.selection.bounds[2]);
}
Copy link to clipboard
Copied
A little nitpicking (but needed, otherwise, the script would fail):
the line
if (ligneBlanc=largeur)
should read
if (ligneBlanc==largeur)
Copy link to clipboard
Copied
Yes !
I hesitated !!!