term-number-wp.js
6.72 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
function abc(msg) {
var msg1 = msg;
self.postMessage({
'cmd': 'getLocationForMatchedTermsInWholeBody',
'value': msg1
});
}
getLocationForMatchedTermsInWholeBody = function (termNo, maskCanvasData)
{
var matchedRGBLocationInBodyRegion = [];
for (var x = 0; x < maskCanvasData.length; x++) {
// alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
var bodyRegionId = maskCanvasData[x].bodyRegionId;
var canvasId = maskCanvasData[x].canvasId;
var maskData = maskCanvasData[x].maskData;
// {
//var scaledWidth = $scope.ColoredImageSRC[x].Width;
//var scaledHeight = $scope.ColoredImageSRC[x].Height;
////var maskImg = $scope.ColoredImageSRC[x].SRC;
//var coloredImg = $scope.ColoredImageSRC[x].SRC;
//var maskImg = $scope.GetMaskImageSource(coloredImg);
//var scledX = $scope.ColoredImageSRC[x].x;
//var scledY = $scope.ColoredImageSRC[x].y;
//// 1. get mask canvas for this body region.
//var maskCanvasID;
//if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
// maskCanvasID = 'imageCanvas' + bodyRegionId + '_MR_mci';
//}
//else {
// maskCanvasID = 'imageCanvas' + bodyRegionId + '_mci';
//}
//var maskCanvas = document.getElementById(maskCanvasID);
//var maskCanvasContext = maskCanvas.getContext("2d");
//var maskImgData = maskCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
//// 2. get coloured canvas for this body region.
//var coloredImageDataVar;
//var coloredImageDataMRVar
//if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
// coloredImageDataVar = $rootScope.coloredImageMRCanvasList[parseInt(bodyRegionId)];
//}
//else {
// coloredImageDataVar = $rootScope.coloredImageCanvasList[parseInt(bodyRegionId - 1)];
//}
//var grayImageDataVar;
//var grayCanvas;
//if ($scope.ColoredImageSRC[x].haveMirror == 'true') {
// //// 3. get mask canvas for this body region._MR
// var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR';
// grayCanvas = document.getElementById(grayCanvasID);
// var grayCanvasContext = grayCanvas.getContext("2d");
// var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
// grayImageDataVar = grayImageData.data;
//}
//else {
// var grayCanvasID = 'imageCanvas' + bodyRegionId;
// grayCanvas = document.getElementById(grayCanvasID);
// var grayCanvasContext = grayCanvas.getContext("2d");
// var grayImageData = grayCanvasContext.getImageData(0, 0, scaledWidth, scaledHeight);
// grayImageDataVar = grayImageData.data;
//}
//var coloredImageDataVarMR;
//var coloredImageDataMR
var counter = 0;
var imageDataVar = maskData.data;
// var previousBRID;
var counter = 0;
var n = maskData.data.length;
for (var i = 0; i < n; i += 4) {
var RED = imageDataVar[i] - 9;
var GREEN = imageDataVar[i + 1] - 9;
var BLUE = imageDataVar[i + 2] - 9;
var Red;
var Green;
var Blue;
var zero = "0";
if ((RED).toString().length != 2) {
Red = zero.concat((RED).toString())
}
else {
Red = (RED).toString()
}
if ((GREEN).toString().length != 2) {
Green = zero.concat((GREEN).toString())
}
else {
Green = (GREEN).toString()
}
if ((BLUE).toString().length != 2) {
Blue = zero.concat((BLUE).toString())
}
else {
Blue = (BLUE).toString()
}
var Icolor = (Red + Green + Blue);
// alert('Icolor: ' + Icolor)
if (parseInt(termNo) == parseInt(Icolor)) {
counter++;
//var obj = new Object();
//obj.bodyRegionId = bodyRegionId;
//obj.location = i;
matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });
// var have = machedIcolorInBodyRegion.indexOf(bodyRegionId);
//if (have == -1) {
// // machedIcolorInBodyRegion.push(bodyRegionId);
//}
//else {
//}
//previousGrayColoredData = i;
//if (coloredImageDataVar != null) {
// var RED_coloredImage = coloredImageDataVar[i];
// // grayImageDataVar[i] = RED_coloredImage;
// var GREEN_coloredImage = coloredImageDataVar[i + 1];
// /// grayImageDataVar[i + 1] = GREEN_coloredImage;
// var BLUE_coloredImage = coloredImageDataVar[i + 2];
// //grayImageDataVar[i + 2] = BLUE_coloredImage;
// var ALPHA_coloredImage = coloredImageDataVar[i + 3];
// // grayImageDataVar[i + 3] = ALPHA_coloredImage;
//}
}
// grayCanvasContext.putImageData(grayImageData, 0, 0);
}
self.postMessage({
'cmd': 'getLocationsForMatchedTermsInWholeBody',
'value': matchedRGBLocationInBodyRegion
});
// grayCanvasContext.putImageData(grayImageData, 0, 0);
//}
}
}
self.onmessage = function (e) {
getLocationForMatchedTermsInWholeBody(e.data.termNumber, e.data.maskCanvasData);
}
function launchMatchPixelWorkerProcess() {
var worker = new Worker('match-pixel-wp.js');
worker.onmessage = function (e) {
var pixelLocation = e.data.msg;
self.postMessage({ 'msg': pixelLocation });
};
worker.onerror = function (e) {
alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
};
}