Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Integral.cs
2{
6 public static partial class StatisticsOperations
7 {
12 public static Matrix<float> Integral(this Matrix<float> M)
13 {
14 int y, h = M.Height;
15 int x, w = M.Width;
16 int SrcIndex = M.Start;
17 int SrcSkip = M.Skip;
18 int DestIndex = 0;
19 float[] SrcData = M.Data;
20 float[] Dest = new float[w * h];
21 float RowSum;
22
23 Dest[DestIndex++] = SrcData[SrcIndex++];
24 for (x = 1; x < w; x++, DestIndex++)
25 Dest[DestIndex] = Dest[DestIndex - 1] + SrcData[SrcIndex++];
26
27 SrcIndex += SrcSkip;
28
29 for (y = 1; y < h; y++, SrcIndex += SrcSkip)
30 {
31 RowSum = SrcData[SrcIndex++];
32 Dest[DestIndex] = Dest[DestIndex - w] + RowSum;
33 DestIndex++;
34
35 for (x = 1; x < w; x++, DestIndex++)
36 {
37 RowSum += SrcData[SrcIndex++];
38 Dest[DestIndex] = Dest[DestIndex - w] + RowSum;
39 }
40 }
41
42 return new Matrix<float>(w, h, Dest);
43 }
44
49 public static Matrix<long> Integral(this Matrix<int> M)
50 {
51 int y, h = M.Height;
52 int x, w = M.Width;
53 int SrcIndex = M.Start;
54 int SrcSkip = M.Skip;
55 int DestIndex = 0;
56 int[] SrcData = M.Data;
57 long[] Dest = new long[w * h];
58 long RowSum;
59
60 Dest[DestIndex++] = SrcData[SrcIndex++];
61 for (x = 1; x < w; x++, DestIndex++)
62 Dest[DestIndex] = Dest[DestIndex - 1] + SrcData[SrcIndex++];
63
64 SrcIndex += SrcSkip;
65
66 for (y = 1; y < h; y++, SrcIndex += SrcSkip)
67 {
68 RowSum = SrcData[SrcIndex++];
69 Dest[DestIndex] = Dest[DestIndex - w] + RowSum;
70 DestIndex++;
71
72 for (x = 1; x < w; x++, DestIndex++)
73 {
74 RowSum += SrcData[SrcIndex++];
75 Dest[DestIndex] = Dest[DestIndex - w] + RowSum;
76 }
77 }
78
79 return new Matrix<long>(w, h, Dest);
80 }
81 }
82}
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Definition: Matrix.cs:12
int Height
Height of matrix (number of rows)
Definition: Matrix.cs:136
T[] Data
Underlying data on which the matrix is defined.
Definition: Matrix.cs:114
int Width
Width of matrix (number of columns)
Definition: Matrix.cs:120
int Skip
Number of elements to skip from the right edge in the underlying data to the left edge of the new row...
Definition: Matrix.cs:233
int Start
Start offset of matrix in underlying data.
Definition: Matrix.cs:228
static Matrix< long > Integral(this Matrix< int > M)
Computes the integral image of a matrix.
Definition: Integral.cs:49
static Matrix< float > Integral(this Matrix< float > M)
Computes the integral image of a matrix.
Definition: Integral.cs:12