public Matrix int setIntegralImage if grayImage null Matrix int Integr

 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
public Matrix<int> setIntegralImage() {
if (grayImage != null) {
Matrix<int> IntegralImage = new Matrix<int>(grayImage.Size);
Matrix<int> IntegralImageSquare = new Matrix<int>(grayImage.Size);
for (int i = 0; i < IntegralImage.Height; i++) {
for (int j = 0; j < IntegralImage.Width; j++) {
IntegralImage.Data[i, j] = grayImage.Data[i, j, 0];
IntegralImageSquare.Data[i, j] = grayImage.Data[i, j, 0] * grayImage.Data[i, j, 0];
if (i > 0 && j > 0) {
IntegralImage.Data[i, j] += IntegralImage.Data[i - 1, j - 1];
IntegralImageSquare.Data[i, j] += IntegralImageSquare.Data[i - 1, j - 1];
}
if (i > 0) {
IntegralImage.Data[i, j] += -IntegralImage.Data[i - 1, j];
IntegralImageSquare.Data[i, j] += -IntegralImageSquare.Data[i - 1, j];
}
if (j > 0) {
IntegralImage.Data[i, j] += -IntegralImage.Data[i, j - 1];
IntegralImageSquare.Data[i, j] += IntegralImageSquare.Data[i, j - 1];
}
}
}
// set values
this.IntegralImage = IntegralImage;
this.IntegralImageSquare = IntegralImageSquare;
// return result
return IntegralImage;
}
// set null values
this.IntegralImage = null;
this.IntegralImageSquare = null;
// return null
return null;
}