Newer
Older
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
import * as G from"./globals"
// round to the 3rd decimal digit
export function round3(val: number)
{
return (Math.round(val * Math.pow(10, 3)) / Math.pow(10, 3));
}
// sum the elements of the array in the range [from, to]
export function sumVect(vect: number[], from: number, to: number)
{
let sum: number = 0;
for (let i: number = from; i < to; i++) { sum += vect[i]; }
return sum;
}
// find the max in the sub-matrix specified by the two coordinates
export function findMax(matrix: number[][], pixel1: G.coordinates, pixel2: G.coordinates)
{
let max = 0;
for (let i = pixel1.x; i <= pixel2.x; i++) {
for (let j = pixel1.y; j <= pixel2.y; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
}
return max;
}
// prepara i dati per il grafico completo
export function setDataForCompleteChart(image: G.Image, chart: G.Chart): number[]
{
// per ogni pixel sommo i conteggi di tutti i canali rilevati
let data: number[] = [];
data.length = image.depth;
for (let i = 0; i < image.depth; i++) {
data[i] = 0;
}
for (let i = 0; i < image.width; i++) {
for (let j = 0; j < image.height; j++) {
for (let k = 0; k < image.depth; k++) {
data[k] += image.DataMatrix[i][j][k];
}
}
}
// riempio le stringhe con i dati per il grafico
for (let i = 0; i < image.depth; i++) {
chart.dataCompleteChart += (i + 1) + "," + data[i] + "\n";
chart.dataCompleteChartCalibrated += round3(((i + 1) * image.calibration.a - image.calibration.b) / 1000) + "," + data[i] + "\n";
}
return data;
}