term-number-wp.js
4.32 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
var previousGrayImageDataList = [];
var abc = 'hello';
getLocationForMatchedTermsInWholeBody = function (TermList, maskCanvasData, coloredImageCanvasList, coloredImageMRCanvasList, grayImageDataList, grayImageMRDataList) {
var matchedRGBLocationInBodyRegion = [];
var matched;
for (var x = 0; x < maskCanvasData.length; x++) {
matched = false;
// alert('called for bodyRegionId: ' + $scope.MaskImageSRC[x].bodyRegionId);
var bodyRegionId = maskCanvasData[x].bodyRegionId;
var canvasId = maskCanvasData[x].canvasId;
var maskData = maskCanvasData[x].maskData;
var coloredImageDataVar1 = coloredImageCanvasList[bodyRegionId - 1];
var grayImageDataVar1 = grayImageDataList[bodyRegionId - 1];
var coloredImageDataVar = coloredImageDataVar1.data;
var grayImageDataVar = grayImageDataVar1.data;
var counter = 0;
var imageDataVar = maskData.data;
// var previousBRID;
var counter = 0;
var n = maskData.data.length;
for (var z = 0; z < TermList.length; z++)
{
if (previousGrayImageDataList[bodyRegionId - 1] != null) {
grayImageDataVar1 = previousGrayImageDataList[bodyRegionId - 1];
grayImageDataVar = grayImageDataVar1.data;
}
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(TermList[z]._TermNumber) == parseInt(Icolor)) {
counter++;
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;
}
}
previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageDataVar1;
}
if (matched == true) {
self.postMessage({
'bodyRegionId': bodyRegionId,
'value': grayImageDataVar1,
});
}
}
}
self.onmessage = function (e) {
getLocationForMatchedTermsInWholeBody(e.data.termList, e.data.maskCanvasData, e.data.coloredImageCanvasList,
e.data.coloredImageMRCanvasList, e.data.grayImageDataList, e.data.grayImageMRDataList);
}
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);
};
}