in src/engine/loaders/voltools.js [172:228]
static buildSmoothedHistogram(histSrc, histDst, numEntries, gaussSigma) {
// check args
const ERR_NO_SRC = -1;
const ERR_NO_DST = -2;
const ERR_SRC_DST_DIF_LEN = -3;
const ERR_SRC_LEN_NOT_MATCH = -4;
const ERR_SIGMA_RANGE = -5;
if (histSrc === null) {
return ERR_NO_SRC;
}
if (histDst === null) {
return ERR_NO_DST;
}
if (histSrc.length !== histDst.length) {
return ERR_SRC_DST_DIF_LEN;
}
if (histSrc.length !== numEntries) {
return ERR_SRC_LEN_NOT_MATCH;
}
const SIGMA_MIN = 0.0;
const SIGMA_MAX = 64.0;
if (gaussSigma < SIGMA_MIN || gaussSigma > SIGMA_MAX) {
return ERR_SIGMA_RANGE;
}
const SIZE_DIV = 60;
let windowSize = Math.floor(numEntries / SIZE_DIV);
// avoid too large neighbourhood window size
const SIZE_LARGE = 32;
if (windowSize > SIZE_LARGE) {
windowSize = SIZE_LARGE;
}
for (let i = 0; i < numEntries; i++) {
let sum = 0.0;
let sumKoef = 0.0;
for (let j = -windowSize; j <= +windowSize; j++) {
// t in [-1..+1]
let t = j / windowSize;
// t in [0..1]
t = t >= 0.0 ? t : -t;
let idx = i + j;
idx = idx >= 0 ? idx : 0;
idx = idx < numEntries ? idx : numEntries - 1;
const val = histSrc[idx];
const koef = Math.exp(-t * gaussSigma);
sum += val * koef;
sumKoef += koef;
} // for j around neighbourhood
// divide by window range
// sum /= (2 * windowSize + 1);
// normalize average
sum /= sumKoef;
histDst[i] = Math.floor(sum);
} // for i all entries
return 1;
} // buildSmoothedHistogram