Copy link to clipboard
Copied
After searching for a few hours I am trying to get help here.
I can see it manually in Histogram panel and selecting "Selected layer" (I translated this name from my polish Photoshop so english may differ), but could not find any code snippets even reading scripting guide or js ref - pdfs.
Copy link to clipboard
Copied
I'm affraid you must make selection of layer you want to check its histogram.
Use this code where in the label of CLM function you have written in polish what it is for:
function CLM(v1, v2, v3) {// ZAZNACZENIE KANAŁU / MASKI / WARSTWY Z PRZEZROCZYSTOŚCIĄ:
function cTT(v) {return charIDToTypeID(v)} (ref1 = new ActionReference()).putProperty(c = cTT('Chnl'), cTT('fsel'));
eval('(ref2 = new ActionReference())' + (v = (v1 && v2) ? '.putEnumerated(c, cTT(v1), cTT(v2))' : ''))
if (v3) ref2.putName(cTT(v ? 'Lyr ' : 'Chnl'), v3); (dsc = new ActionDescriptor()).putReference(cTT('null'), ref1)
dsc.putReference(cTT('T '), ref2), executeAction(cTT('setd'), dsc, DialogModes.NO)
}
CLM('Chnl', 'Trsp'), hst = (aD = activeDocument).histogram, aD.selection.deselect()
Copy link to clipboard
Copied
//You can turn off all other layers then get the histogram then turn on all layers again
toggle_other_visible()
var hist = app.activeDocument.histogram;
//var hist = app.activeDocument.channels[0].histogram;
toggle_other_visible()
alert(hist)
function toggle_other_visible()
{
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
list.putReference( ref );
desc.putList( charIDToTypeID( "null" ), list );
desc.putBoolean( charIDToTypeID( "TglO" ), true );
executeAction( charIDToTypeID( "Shw " ), desc, DialogModes.NO );
}
catch (e) { alert(e);}
}
Copy link to clipboard
Copied
r-bin your function shows histogram or current layer and transparent pixels of document, but to be honest I didn't think up nothing beside that example I always used, so now I'm at least aware it can be done using also other (your) method
Copy link to clipboard
Copied
When I need to know the exact histogram, I insert a SolidColor layer (=30) under this layer and ignore the index 30 in the histogram.
Copy link to clipboard
Copied
You had to give me simple example of that becuase I can't imagine how to do it, but sounds very easy...
Copy link to clipboard
Copied
There's actually a very tricky function for getting absolutely accurate clipping values for a given percentage. I'm not ready to post it yet.
Copy link to clipboard
Copied
OK. Create a 5x5 pixel file.
Create three transparent layers, two of which have an opacity of 20%, the third 100%.
Draw on one layer a pixel with a brightness of 20, on the other 128, on the third 250.
Merge the layers. Compare your histogram from the script with what the histogram panel shows.
In general, I found an acceptable simple way of obtaining an accurate histogram of brightness. I combined the code from your script with mine.
In CS6 use should use shift_selection_cs6() function.
try { app.activeDocument.suspendHistory("Test", "test()") } catch(e) { alert(e); }
function test() {
function CLM(v1, v2, v3) {
function cTT(v) {return charIDToTypeID(v)} (ref1 = new ActionReference()).putProperty(c = cTT('Chnl'), cTT('fsel'));
eval('(ref2 = new ActionReference())' + (v = (v1 && v2) ? '.putEnumerated(c, cTT(v1), cTT(v2))' : ''))
if (v3) ref2.putName(cTT(v ? 'Lyr ' : 'Chnl'), v3); (dsc = new ActionDescriptor()).putReference(cTT('null'), ref1)
dsc.putReference(cTT('T '), ref2), executeAction(cTT('setd'), dsc, DialogModes.NO)
}
CLM('Chnl', 'Trsp')
shift_selection_CC(100, 0);
shift_selection_CC(100, 0);
shift_selection_CC(0, 100);
shift_selection_CC(0, 100);
toggle_other_visible()
hst = (aD = activeDocument).histogram, aD.selection.deselect()
toggle_other_visible()
xxx=0
for (var i in hst) xxx+=hst;
alert(xxx+"\n\n"+hst)
}
function toggle_other_visible()
{
try {
var desc = new ActionDescriptor();
var list = new ActionList();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
list.putReference( ref );
desc.putList( charIDToTypeID( "null" ), list );
desc.putBoolean( charIDToTypeID( "TglO" ), true );
executeAction( charIDToTypeID( "Shw " ), desc, DialogModes.NO );
}
catch (e) { alert(e);}
}
function shift_selection_cs6(shift, contrast, dlg)
{
try {
var desc = new ActionDescriptor();
desc.putUnitDouble( stringIDToTypeID( "refineEdgeBorderRadius" ), charIDToTypeID( "#Pxl" ), 0 );
desc.putUnitDouble( stringIDToTypeID( "refineEdgeBorderContrast" ), charIDToTypeID( "#Prc" ), contrast );
desc.putInteger( stringIDToTypeID( "refineEdgeSmooth" ), 0 );
desc.putUnitDouble( stringIDToTypeID( "refineEdgeFeatherRadius" ), charIDToTypeID( "#Pxl" ), 0 );
desc.putUnitDouble( stringIDToTypeID( "refineEdgeChoke" ), charIDToTypeID( "#Prc" ), shift );
desc.putBoolean( stringIDToTypeID( "refineEdgeAutoRadius" ), false );
desc.putBoolean( stringIDToTypeID( "refineEdgeDecontaminate" ), false );
desc.putEnumerated( stringIDToTypeID( "refineEdgeOutput" ), stringIDToTypeID( "refineEdgeOutput" ), stringIDToTypeID("refineEdgeOutputSelection") );
executeAction( stringIDToTypeID( "refineSelectionEdge" ), desc, (dlg == true)?DialogModes.ALL:DialogModes.NO );
}
catch (e) { alert(e); }
}
function shift_selection_CC(shift, contrast, dlg)
{
try {
var desc = new ActionDescriptor();
desc.putInteger( stringIDToTypeID( "smartBrushRadius" ), 0 );
desc.putInteger( stringIDToTypeID( "smartBrushSmooth" ), 0 );
desc.putUnitDouble( stringIDToTypeID( "smartBrushFeather" ), charIDToTypeID( "#Pxl" ), 0 );
desc.putUnitDouble( stringIDToTypeID( "smartBrushContrast" ), charIDToTypeID( "#Prc" ), contrast );
desc.putUnitDouble( stringIDToTypeID( "smartBrushShiftEdge" ), charIDToTypeID( "#Prc" ), shift );
desc.putBoolean( stringIDToTypeID( "sampleAllLayers" ), false );
desc.putBoolean( stringIDToTypeID( "smartBrushUseSmartRadius" ), false );
desc.putBoolean( stringIDToTypeID( "smartBrushDecontaminate" ), false );
desc.putEnumerated( stringIDToTypeID( "refineEdgeOutput" ), stringIDToTypeID( "refineEdgeOutput" ), stringIDToTypeID( "selectionOutputToSelection" ) );
executeAction( stringIDToTypeID( "smartBrushWorkspace" ), desc, (dlg == true)?DialogModes.ALL:DialogModes.NO );
}
catch (e) { alert(e); }
}
Another example in pictures
Copy link to clipboard
Copied
Not everything is clear for me in your description:
Should I draw a pixel with a brigthenss of 20 on layer with opacity 20%?
Should I draw a pixel with a brigthenss of 128 on layer with opacity 20%?
Should I draw a pixel with a brigthenss of 255 on layer with opacity 250%?
How to draw a pixel with brightness? Should I use pencil? If so, how to set brightness?
What do you mean by it, as I don't see it in CS6, while the range of all sliders is 0 - 100
Copy link to clipboard
Copied
no matter
darw on 20% with pencil 1x1 with RGB(20,20,20)
darw on 100% with pencil 1x1with RGB(128,128,128)
darw on 20% with pencil 1x1with RGB(250,250,250)
Copy link to clipboard
Copied
Well I did, this is my result:
In the alert there was 1 and then histogram where after only zero values it ended with , 1, 0, 0, 0 ,0, 0
While compared to histogram it showed there are 25 pixels (so 5 * 5), but the count wasn't available.
Mean: 254.80, Std Dev: 0.99, Median: 255, but when selected then Mean: 250.00, Std Dev: 0.00, Median: 250
Copy link to clipboard
Copied
Did you turn off the background? At me with a script it turns off automatically.
Nevertheless, did you understand that your histogram is not quite correct?
Copy link to clipboard
Copied
Yes, background was deleted, only merged 3 layers left. Yes I saw difference in results you posted
Copy link to clipboard
Copied
By the way, on these pictures (with transparency) auto-options in Levels or Curves do not work, because they show not the correct histogram. Only a direct call to the layer (Ctrl-L, Ctrl-M) shows the correct histogram of the layer.
And no one in Adobe is going to even fix it
Copy link to clipboard
Copied
michal-44680644
Are you going to get a histogram for layers with transparency?
If "yes", then the method will be more difficult. Using the selection does not give an accurate result.
Copy link to clipboard
Copied
Custom C++ plugin with scripting API would be best option.