Copy link to clipboard
Copied
getRedHistogramStdDev();
function getRedHistogramStdDev() {
var channels = app.activeDocument.channels;
var red = channels[0].histogram;
alert(getStdDev(red));
}
function getStdDev(arry){
var length = arry.length;
var tarry = new Array(length);
var si = 0;
var s = 0;
for (var i = 0; i < arry.length; i += 1) {
if (arry[i] > 0) {
s += i;
si += arry[i];
}
}
var average = si / s;
for (var i = 0; i < length; i++) {
var dev = parseFloat(arry[i]) - parseFloat(average);
tarry = Math.pow(dev, 2);
}
var powSum = 0;
for (var j = 0; j < tarry.length; j++) {
if (tarry[j].toString() != "" || tarry[j].toString() != null) {
powSum = parseFloat(powSum) + parseFloat(tarry[j].toString());
}
}
return Math.sqrt(parseFloat(powSum) / parseFloat(length)).toFixed(2);
}
This is my code, but the result is inconsistent with the histogram's StdDev data.Please help me, thanks.
Does this work more consistently?
...
// 2018, use at your own risk;
#target "photoshop-120.032"
//#target photoshop
if (app.documents.length > 0 && activeDocument.mode == DocumentMode.RGB) {
var theR = histogramMeanStandardDeviation(activeDocument.channels[0].histogram);
var theG = histogramMeanStandardDeviation(activeDocument.channels[1].histogram);
var theB = histogramMeanStandardDeviation(activeDocument.channels[2].histogram);
alert ((theR[2]+theG[2]+theB[2])/3);
};
////// get mean of hist
Copy link to clipboard
Copied
Does this work more consistently?
// 2018, use at your own risk;
#target "photoshop-120.032"
//#target photoshop
if (app.documents.length > 0 && activeDocument.mode == DocumentMode.RGB) {
var theR = histogramMeanStandardDeviation(activeDocument.channels[0].histogram);
var theG = histogramMeanStandardDeviation(activeDocument.channels[1].histogram);
var theB = histogramMeanStandardDeviation(activeDocument.channels[2].histogram);
alert ((theR[2]+theG[2]+theB[2])/3);
};
////// get mean of histogram //////
function histogramMeanStandardDeviation (theHist) {
// get total number;
var thePixels = 0;
for (var m = 0; m < theHist.length; m++) {
thePixels = thePixels + theHist[m]
};
// get mean and median;
var theMean = 0;
var aTotal = 0;
var check = false;
for (var n = 0; n < theHist.length; n++) {
theMean = theMean + (n * theHist[n] / thePixels);
aTotal = aTotal + theHist[n];
if (aTotal >= thePixels / 2 && check == false) {
theMedian = n;
check = true;
}
};
// get standard deviation;
var theStandDev = 0;
for (var o = 0; o < theHist.length; o++) {
theStandDev = theStandDev + (Math.pow ((o - theMean), 2) * theHist[o])
};
theStandDev = Math.sqrt (theStandDev / thePixels);
//
return ([theMean, theMedian, theStandDev]);
};
Copy link to clipboard
Copied
Yes,It works very well,thank you very much!
Copy link to clipboard
Copied
Hi c.pfaffenbichler,sorry to disturb you.I want to get value of theMax and theMin in histogram not the the pixels,how to get this? Thanks
Copy link to clipboard
Copied
Does this work? (Edit: Otherwise I may have misunderstood your intention.)
// 2018, use at your own risk;
#target "photoshop-120.032"
//#target photoshop
if (app.documents.length > 0 && activeDocument.mode == DocumentMode.RGB) {
var theMinMax = histogramMinMax(activeDocument.histogram);
alert ("min "+theMinMax[0]+"\nmax "+theMinMax[1]);
};
////// get mean of histogram //////
function histogramMinMax (theHist) {
// the minimum;
var check = false;
var theMin = 0;
while (check == false) {
if (theHist[theMin] != 0) {
check = true
} else {theMin++}
};
// the maximum;
var check = false;
var theMax = 255;
while (check == false) {
if (theHist[theMax] != 0) {
check = true
} else {theMax--}
};
//
return ([theMin, theMax]);
};
Copy link to clipboard
Copied
It is that i mean, forgive me for not being clear,because i am not clear about the relationship with them which like "n * theHist
Copy link to clipboard
Copied
n being the index also indicated the luminance while theHist
Copy link to clipboard
Copied
You got almost full stake! Last time I looked at, you was at 8 lvl. It'll take another century your skull will be finally inpaled 🙂
Copy link to clipboard
Copied
I think the last »bar« of those levels takes a lot of points, no hurry …
Copy link to clipboard
Copied
Ok,thanks
Copy link to clipboard
Copied
I got it. I have ling54k in list of users I follow, actually he added me first. It's why I was announced of his topic.
Copy link to clipboard
Copied
Will this work on 32 bpc floating point data? If not, is there a quick workaround?
Thanks,
RONC
Copy link to clipboard
Copied
It does work on 32 bpc data very well. Just need to display the histograms.
RONC
Copy link to clipboard
Copied
That's 3rd topic during last month I'm called constantly to although neither I haven't posted anything on here nor anyone mentioned my forum name 😕 That must be some error 😕
Copy link to clipboard
Copied
Well, would not be the first time the Forum software displays »issues«, would it?
Have you tried contacting an Admin or asking about the issue on
yet?
Copy link to clipboard
Copied
No that is no problem for me, it doesn't happen often, especially taking into consideration I forgot 's' at end of 'month' in last post. So once a 1,5 month something causing I'm alerted of new posts in certain topic.
Copy link to clipboard
Copied
Hello dearest people and @c.pfaffenbichler !
I don't get this script working. Gives me a spinning cursor and after that nothing happens. Then i fired it in ESTK and it gave me "theMedian is undefined". I tried to figure it out by myself but the best what i get out of it is "NaN" lol.
Is this again some typo error because of the glorious change of forum software? If yes, i don´t find it,
The first script from @raxby gives me "0.00" all the time btw.
Thanks for your help in advance!
Copy link to clipboard
Copied
I can also add that I can't get the script working in later versions either, looking for the Std Dev.
Copy link to clipboard
Copied
I corrected the scripts.
Copy link to clipboard
Copied
@Kukurykus – thank you!