summaryrefslogtreecommitdiff
path: root/convolve.html
blob: 24e35903cdb423291062db2fe6fe68fa21b8270e (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<style>
canvas { display: inline-block; }
</style>
<body></body>
<script src="convolve.js"></script>
<script src="smartblur.js"></script>
<script src="fetch.js"></script>
<script>

var url = 'img/oranges.jpg'
var smart_blur = new SmartBlurFilter ()

var identityArray = [
  1,
]
var brightArray = [
  2,
]
var dimArray = [
  0.5,
]
var oddArray = [
	-1, -1, -1,
	-1, 8.5, -1,
	-1, -1, -1,
]
var blurArray = [
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1
]

var edgeArray = [
  0,-1,0,
  -1,6,-1,
  0,-1,0,
]

var kernels = [
//  	new Kernel(1, 1, identityArray),
	new Kernel(1, 1, brightArray),
	new Kernel(1, 1, dimArray),
//  	new Kernel(3, 3, oddArray),
// 	new Kernel(3, 3, edgeArray).normalize(),
 	new Kernel(9, 9, blurArray).normalize(),
]
var convolvers = kernels.map(function(kernel){
	return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null)
}).concat(kernels.map(function(kernel){
	return new ConvolveOp(kernel, ConvolveOp.EDGE_ZERO_FILL, null)
}))

fromImage(url, function(canvas){
	document.body.appendChild(canvas)
	convolvers.forEach(function(convolver){
		var convolved = convolver.convolveCanvas(canvas)
		document.body.appendChild(convolved)
	})
})

</script>