forked from Experience-Monks/glsl-fast-gaussian-blur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoefficients.js
50 lines (40 loc) · 1.36 KB
/
coefficients.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var range = require('array-range')
module.exports = coefficients
//a row of a pascal table with ends chopped off
function coefficients(weights) {
if (weights.length % 2 === 0)
throw new Error('only supports odd table')
console.log('taps', weights.length)
var mid = Math.floor((weights.length-1)/2)
var sum = weights.reduce(function(a, b) {
return a + b
}, 0)
weights = weights.slice(mid)
var weightDiv = weights.map(function(w) {
return w / sum
})
var offsets = range(mid+1)
var linearWeights = weightDiv.slice(0, 1)
var linearOffsets = [0]
for (var i=1; i<offsets.length-1; i+=2) {
var off1 = offsets[i]
var off2 = offsets[i+1]
var weight1 = weights[i]
var weight2 = weights[i+1]
var wsum = weight1 + weight2
var t = (off1 * weight1 + off2 * weight2) / wsum
linearOffsets.push(t)
linearWeights.push(wsum / sum)
}
console.log('offsets', linearOffsets)
console.log('weights', linearWeights)
}
var weights = '28 56 70 56 28' // 5 taps
// var weights = '45 120 210 252 210 120 45' // 7 taps
// var weights = '66 220 495 792 924 792 495 220 66' // 9 taps
// var weights = '120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120'
.split(/\s+/)
.map(function(a) {
return parseInt(a, 10)
})
module.exports(weights)