Copy link to clipboard
Copied
Hello everyone, I want a solution from you
I found this script and tweaked it a bit for me
Because I found a problem which is that it is a script that when it reaches the hidden channel it stops, so I want a way to show it the channel directly
/*
Statistics Histogram v1.3.jsx v1.3
*/
#target photoshop;
app.bringToFront();
main();
function main(){
var inputFolder = Folder.selectDialog ("Please select folder to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|crw|cr2|psb|exr|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|rw2)$/i);
var outFile = File(Folder.desktop +"/"+decodeURI(inputFolder.name)+".csv");
outFile.open('w');
outFile.writeln("Filename,Mean Bleu,Mean Marron,Mean Jaune,Mean Noir,Mean Rose,Mean Relief");
for(var a in fileList){
open(fileList[a])
//var area = activeDocument.histogram;
//var luminosity = activeDocument.histogram;
//CMYK Channel
var Bleu = activeDocument.channels["COBALT"].histogram;
var mean_Bleu = 0;
var total_Bleu = 0;
for (var n_Bleu = 0; n_Bleu < Bleu.length; n_Bleu++) {
total_Bleu = total_Bleu + Bleu[n_Bleu];
};
for (var m_Bleu = 0; m_Bleu < Bleu.length; m_Bleu++) {
var thisValue_Bleu = Bleu[m_Bleu];
mean_Bleu = mean_Bleu + (m_Bleu * thisValue_Bleu / total_Bleu);
};
var Marron = activeDocument.channels["MARRON"].histogram;
var mean_Marron = 0;
var total_Marron = 0;
for (var n_Marron = 0; n_Marron < Marron.length; n_Marron++) {
total_Marron = total_Marron + Marron[n_Marron];
};
for (var m_Marron = 0; m_Marron < Marron.length; m_Marron++) {
var thisValue_Marron = Marron[m_Marron];
mean_Marron = mean_Marron + (m_Marron * thisValue_Marron / total_Marron);
};
var Jaune = activeDocument.channels["JAUNE CITRON"].histogram;
var mean_Jaune = 0;
var total_Jaune = 0;
for (var n_Jaune = 0; n_Jaune < Jaune.length; n_Jaune++) {
total_Jaune = total_Jaune + Jaune[n_Jaune];
};
for (var m_Jaune = 0; m_Jaune < Jaune.length; m_Jaune++) {
var thisValue_Jaune = Jaune[m_Jaune];
mean_Jaune = mean_Jaune + (m_Jaune * thisValue_Jaune / total_Jaune);
};
var Noir = activeDocument.channels["NOIR"].histogram;
var mean_Noir = 0;
var total_Noir = 0;
for (var n_Noir = 0; n_Noir < Noir.length; n_Noir++) {
total_Noir = total_Noir + Noir[n_Noir];
};
for (var m_Noir = 0; m_Noir < Noir.length; m_Noir++) {
var thisValue_Noir = Noir[m_Noir];
mean_Noir = mean_Noir + (m_Noir * thisValue_Noir / total_Noir);
};
var Rose = activeDocument.channels["ROSE"].histogram;
var mean_Rose = 0;
var total_Rose = 0;
for (var n_Rose = 0; n_Rose < Rose.length; n_Rose++) {
total_Rose = total_Rose + Rose[n_Rose];
};
for (var m_Rose = 0; m_Rose < Rose.length; m_Rose++) {
var thisValue_Rose = Rose[m_Rose];
mean_Rose = mean_Rose + (m_Rose * thisValue_Rose / total_Rose);
};
var Relief = activeDocument.channels["RELIEF"].histogram;
var chnl = activeDocument.channels["RELIEF"];
var chnls = activeDocument.channels;
chnl.visible();
for(var i = 0;i < chnl.length;i++){
chnl.visible = true;
}
var mean_Relief = 0;
var total_Relief = 0;
for (var n_Relief = 0; n_Relief < Relief.length; n_Relief++) {
total_Relief = total_Relief + Relief[n_Relief];
};
for (var m_Relief = 0; m_Relief < Relief.length; m_Relief++) {
var thisValue_Relief = Relief[m_Relief];
mean_Relief = mean_Relief + (m_Relief * thisValue_Relief / total_Relief);
};
//(Bleu).toFixed(0));
outFile.writeln(decodeURI(activeDocument.name) + "," + (mean_Bleu) + "," + (mean_Marron) + "," + (mean_Jaune) + "," + (mean_Noir) + "," + (mean_Rose) + "," + (mean_Relief));
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
outFile.close();
alert("Process complete\nCSV created...\n" + decodeURI(outFile));
}
// ----------------------
The code is not very good, because instead of accessing universal channel indexes, it uses their localized names. In any case, it is enough to add a line like activeDocument.channels ["COBALT"]. visible = true
/*
Statistics Histogram v1.3.jsx v1.3
*/
#target photoshop;
app.bringToFront();
main();
function main(){
var inputFolder = Folder.selectDialog ("Please select folder to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|crw|cr2|psb|ex
...
WTF? why can't i edit my comments?
NOT to top of code, but after
//CMYK Channel
i.e.
//CMYK Channel
var chnls = activeDocument.channels;
chnl.visible();
for(var i = 0;i < chnl.length;i++){
chnl.visible = true;
}
Copy link to clipboard
Copied
The code is not very good, because instead of accessing universal channel indexes, it uses their localized names. In any case, it is enough to add a line like activeDocument.channels ["COBALT"]. visible = true
/*
Statistics Histogram v1.3.jsx v1.3
*/
#target photoshop;
app.bringToFront();
main();
function main(){
var inputFolder = Folder.selectDialog ("Please select folder to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|crw|cr2|psb|exr|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|rw2)$/i);
var outFile = File(Folder.desktop +"/"+decodeURI(inputFolder.name)+".csv");
outFile.open('w');
outFile.writeln("Filename,Mean Bleu,Mean Marron,Mean Jaune,Mean Noir,Mean Rose,Mean Relief");
for(var a in fileList){
open(fileList[a])
//var area = activeDocument.histogram;
//var luminosity = activeDocument.histogram;
//CMYK Channel
activeDocument.channels["COBALT"].visible = true
var Bleu = activeDocument.channels["COBALT"].histogram;
var mean_Bleu = 0;
var total_Bleu = 0;
for (var n_Bleu = 0; n_Bleu < Bleu.length; n_Bleu++) {
total_Bleu = total_Bleu + Bleu[n_Bleu];
};
for (var m_Bleu = 0; m_Bleu < Bleu.length; m_Bleu++) {
var thisValue_Bleu = Bleu[m_Bleu];
mean_Bleu = mean_Bleu + (m_Bleu * thisValue_Bleu / total_Bleu);
};
activeDocument.channels["MARRON"].visible = true
var Marron = activeDocument.channels["MARRON"].histogram;
var mean_Marron = 0;
var total_Marron = 0;
for (var n_Marron = 0; n_Marron < Marron.length; n_Marron++) {
total_Marron = total_Marron + Marron[n_Marron];
};
for (var m_Marron = 0; m_Marron < Marron.length; m_Marron++) {
var thisValue_Marron = Marron[m_Marron];
mean_Marron = mean_Marron + (m_Marron * thisValue_Marron / total_Marron);
};
activeDocument.channels["JAUNE CITRON"].visible = true
var Jaune = activeDocument.channels["JAUNE CITRON"].histogram;
var mean_Jaune = 0;
var total_Jaune = 0;
for (var n_Jaune = 0; n_Jaune < Jaune.length; n_Jaune++) {
total_Jaune = total_Jaune + Jaune[n_Jaune];
};
for (var m_Jaune = 0; m_Jaune < Jaune.length; m_Jaune++) {
var thisValue_Jaune = Jaune[m_Jaune];
mean_Jaune = mean_Jaune + (m_Jaune * thisValue_Jaune / total_Jaune);
};
activeDocument.channels["NOIR"].visible = true
var Noir = activeDocument.channels["NOIR"].histogram;
var mean_Noir = 0;
var total_Noir = 0;
for (var n_Noir = 0; n_Noir < Noir.length; n_Noir++) {
total_Noir = total_Noir + Noir[n_Noir];
};
for (var m_Noir = 0; m_Noir < Noir.length; m_Noir++) {
var thisValue_Noir = Noir[m_Noir];
mean_Noir = mean_Noir + (m_Noir * thisValue_Noir / total_Noir);
};
activeDocument.channels["ROSE"].visible = true
var Rose = activeDocument.channels["ROSE"].histogram;
var mean_Rose = 0;
var total_Rose = 0;
for (var n_Rose = 0; n_Rose < Rose.length; n_Rose++) {
total_Rose = total_Rose + Rose[n_Rose];
};
for (var m_Rose = 0; m_Rose < Rose.length; m_Rose++) {
var thisValue_Rose = Rose[m_Rose];
mean_Rose = mean_Rose + (m_Rose * thisValue_Rose / total_Rose);
};
activeDocument.channels["RELIEF"].visible = true
var Relief = activeDocument.channels["RELIEF"].histogram;
var chnl = activeDocument.channels["RELIEF"];
var chnls = activeDocument.channels;
chnl.visible();
for(var i = 0;i < chnl.length;i++){
chnl.visible = true;
}
var mean_Relief = 0;
var total_Relief = 0;
for (var n_Relief = 0; n_Relief < Relief.length; n_Relief++) {
total_Relief = total_Relief + Relief[n_Relief];
};
for (var m_Relief = 0; m_Relief < Relief.length; m_Relief++) {
var thisValue_Relief = Relief[m_Relief];
mean_Relief = mean_Relief + (m_Relief * thisValue_Relief / total_Relief);
};
//(Bleu).toFixed(0));
outFile.writeln(decodeURI(activeDocument.name) + "," + (mean_Bleu) + "," + (mean_Marron) + "," + (mean_Jaune) + "," + (mean_Noir) + "," + (mean_Rose) + "," + (mean_Relief));
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
outFile.close();
alert("Process complete\nCSV created...\n" + decodeURI(outFile));
}
// ----------------------
Copy link to clipboard
Copied
... or move this part to top of code
var chnls = activeDocument.channels;
chnl.visible();
for(var i = 0;i < chnl.length;i++){
chnl.visible = true;
}
Copy link to clipboard
Copied
WTF? why can't i edit my comments?
NOT to top of code, but after
//CMYK Channel
i.e.
//CMYK Channel
var chnls = activeDocument.channels;
chnl.visible();
for(var i = 0;i < chnl.length;i++){
chnl.visible = true;
}
Copy link to clipboard
Copied
Thank you very much. I was pleased with your answer, sir. I am grateful to you
Copy link to clipboard
Copied
Thank you very much. I was pleased with your answer, sir. I am grateful to you..
Copy link to clipboard
Copied
Works for any (non-basic) channels, including invisible ones.
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("histogram"));
r.putName(stringIDToTypeID("channel"), "Alpha 1"); // channel name here
var ret = executeActionGet(r).getList(stringIDToTypeID("histogram"));
var hist = new Array();
for (var i = 0; i < 256; i++) hist.push(ret.getInteger(i));
alert(hist);
Copy link to clipboard
Copied
Additional channels can also be accessed by index. They differ from the base ones by the alphaChannelOptions descriptor. I.e:
#target photoshop;
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfChannels'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(r).getInteger(p)
for (var i = 1; i <= len; i++) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('alphaChannelOptions'));
r.putIndex(s2t('channel'), i);
if (executeActionGet(r).hasKey(p)) {
var r = new ActionReference();
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('histogram'));
r.putIndex(s2t('channel'), i);
var ret = executeActionGet(r).getList(p),
hist = new Array();
for (var x = 0; x < 256; x++) hist.push(ret.getInteger(i));
alert(hist);
}
}
Copy link to clipboard
Copied
I tried to adapt the source code so that it does not depend on the channel name and can work even if the set of channel names in the document series is different.
#target photoshop;
s2t = stringIDToTypeID;
app.bringToFront();
if ((inputFolder = Folder.selectDialog("Please select folder to process"))) {
var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|crw|cr2|psb|exr|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|rw2)$/i),
idx = 0,
csv = {};
for (var a in fileList) {
open(fileList[a]);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('numberOfChannels'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var len = executeActionGet(r).getInteger(p)
for (var i = 1; i <= len; i++) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('alphaChannelOptions'));
r.putIndex(s2t('channel'), i);
if (executeActionGet(r).hasKey(p)) {
var r = new ActionReference();
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('histogram'));
r.putIndex(s2t('channel'), i);
var h = executeActionGet(r).getList(p),
mean = 0,
total = 0;
for (var n = 0; n < h.count; n++) {
total = total + h.getInteger(n);
};
for (var m = 0; m < h.count; m++) {
mean = mean + (m * h.getInteger(m) / total);
};
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('channelName'));
r.putIndex(s2t('channel'), i);
var c = executeActionGet(r).getString(p);
if (csv[c] == undefined) csv[c] = {}
var t = csv[c]; t[idx] = mean
}
}
idx++
app.activeDocument.close()
}
var headers = ['Filename']
for (a in csv) { headers.push(a) }
var outFile = File(Folder.desktop + "/" + decodeURI(inputFolder.name) + ".csv")
outFile.open('w');
outFile.writeln(headers.join(';'));
for (i = 0; i < fileList.length; i++) {
var line = [decodeURI(fileList[i].name)]
for (a in csv) {
var t = csv[a]
line.push(t[i] == undefined ? 0 : t[i])
}
line.join(';')
outFile.writeln(line.join(';'));
}
outFile.close()
alert("Process complete\nCSV created...\n" + decodeURI(outFile));
}
I used ';' as CSV separator if you need exactly a comma - change these two lines at the end of the code.