-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreshold.js
127 lines (97 loc) · 3.48 KB
/
threshold.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function threshold()
{
var canv2 = document.getElementById("Q2");
var context2 = canv2.getContext("2d");
var originalImagedata = context2.getImageData(0, 0, canv2.width, canv2.height);
var binaryImageData = context2.getImageData(0, 0, canv2.width, canv2.height);
var red_lo = document.getElementById("S1").value;
// var red_hi = document.getElementById("S2").value;
// var blue_lo = document.getElementById("S3").value;
// var blue_hi = document.getElementById("S4").value;
// var green_lo = document.getElementById("S5").value;
// var green_hi = document.getElementById("S6").value;
var red_hi = 255;
var blue_lo = 0;
var blue_hi = 255;
var green_lo = 0;
var green_hi = 255;
var i;
for (i = 0; i < originalImagedata.data.length; i += 4)
{
// if(originalImagedata.data[i] < red_lo ) originalImagedata.data[i] = 0;
// if(originalImagedata.data[i] > red_hi ) originalImagedata.data[i] = 0;
// if(originalImagedata.data[i+1] < blue_lo ) originalImagedata.data[i+1] = 0;
// if(originalImagedata.data[i+1] > blue_hi ) originalImagedata.data[i+1] = 0;
// if(originalImagedata.data[i+2] < green_lo ) originalImagedata.data[i+2] = 0;
// if(originalImagedata.data[i+2] > green_hi ) originalImagedata.data[i+2] = 0;
if( (originalImagedata.data[i] < red_lo) || (originalImagedata.data[i] > red_hi) || (originalImagedata.data[i+1] < blue_lo) || (originalImagedata.data[i+1] > blue_hi )
|| (originalImagedata.data[i+2] < green_lo ) || (originalImagedata.data[i+2] > green_hi) )
{
// originalImagedata.data[i] = 0;
// originalImagedata.data[i+1] = 0;
// originalImagedata.data[i+2] = 0;
binaryImageData.data[i] = 255;
binaryImageData.data[i+1] = 0;
binaryImageData.data[i+2] = 0;
binaryImageData.data[i+3] = 255;
}
else
{
binaryImageData.data[i] = 0;
binaryImageData.data[i+1] = 0;
binaryImageData.data[i+2] = 0;
binaryImageData.data[i+3] = 0;
}
}
// var canv1 = document.getElementById("Q1");
// var context1 = canv1.getContext("2d");
// context1.putImageData(originalImagedata, 0, 0);
var canv3 = document.getElementById("Q3");
var context3 = canv3.getContext("2d");
context3.putImageData(binaryImageData, 0, 0);
// alert("Done Threshold function");
// alert("Done Threshold function");
}
window.onload = function()
{
var S1 = document.getElementById("S1");
// var V1 = document.getElementById('V1');
S1.oninput = function()
{
// V1.innerHTML = this.value;
threshold();
// thresholdImage("S1", this.value);
}
// var S2 = document.getElementById("S2");
// var V2 = document.getElementById('V2');
// S2.oninput = function()
// {
// V2.innerHTML = this.value;
// threshold();
// // thresholdImage("S2", this.value);
// }
// var S3 = document.getElementById("S3");
// var V3 = document.getElementById('V3');
// S3.oninput = function()
// {
// V3.innerHTML = this.value;
// }
// var S4 = document.getElementById("S4");
// var V4 = document.getElementById('V4');
// S4.oninput = function()
// {
// V4.innerHTML = this.value;
// }
// var S5 = document.getElementById("S5");
// var V5 = document.getElementById('V5');
// S5.oninput = function()
// {
// V5.innerHTML = this.value;
// }
// var S6 = document.getElementById("S6");
// var V6 = document.getElementById('V6');
// S6.oninput = function()
// {
// V6.innerHTML = this.value;
// }
};