term-number-wp.js
3.18 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
var doneBRID = [];
var abc = 'hello';
var previousGrayImageDataList = [];
getLocationForMatchedTermsInWholeBody = function (termList, maskCanvasData, coloredImageData, grayImageData, bodyRegionId, canvasId) {
// console.log('for bodyRegionId: ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
var matchedRGBLocationInBodyRegion = [];
var matched;
// debugger;
var n = maskCanvasData.data.length;
var maskData = maskCanvasData.data;
for (var z = 0; z < termList.length; z++) {
if (previousGrayImageDataList[parseInt(bodyRegionId - 1)] != null) {
grayImageData = previousGrayImageDataList[parseInt(bodyRegionId - 1)];
}
var grayImageDataVar;
if (grayImageData != null) {
grayImageDataVar = grayImageData.data;
}
var coloredImageDataVar = coloredImageData.data;
for (var i = 0; i < n; i += 4) {
var RED = maskData[i] - 9;
var GREEN = maskData[i + 1] - 9;
var BLUE = maskData[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(termList[z]._TermNumber) == parseInt(Icolor)) {
// debugger;
// matchedRGBLocationInBodyRegion.push({ "BRId": bodyRegionId, "location": i });
// matched = true;
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;
}
}
// debugger;
previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageData;
// if (matched == true) {
// }
}
self.postMessage({
'bodyRegionId': bodyRegionId,
'value': grayImageData,
'canvasId': canvasId
});
}
self.onmessage = function (e) {
getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageData,
e.data.grayImageData, e.data.bodyRegionId, e.data.canvasId);
}