public void GetSumTest3()
{
// Example from Rainer Lienhart and Jochen Maydt:
// "An Extended Set of Haar-like Features for Rapid Object Detection"
int x = 6, y = 2, h = 4, w = 6;
byte[,] img =
{ // 0 1 2 3 4 5 6 7 8 9 A B C D E
/*0*/ { 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9 },
/*1*/ { 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9 },
/*2*/ { 9,9,9,9,9,1,1,9,9,9,9,9,9,9,9 },
/*3*/ { 9,9,9,9,1,1,1,1,9,9,9,9,9,9,9 },
/*4*/ { 9,9,9,1,1,1,1,1,1,9,9,9,9,9,9 },
/*5*/ { 9,9,1,1,1,1,1,1,1,1,9,9,9,9,9 },
/*6*/ { 9,9,9,1,1,1,1,1,1,1,1,9,9,9,9 },
/*7*/ { 9,9,9,9,1,1,1,1,1,1,1,1,9,9,9 },
/*8*/ { 9,9,9,9,9,1,1,1,1,1,1,9,9,9,9 },
/*9*/ { 9,9,9,9,9,9,1,1,1,1,9,9,9,9,9 },
/*A*/ { 9,9,9,9,9,9,9,1,1,9,9,9,9,9,9 },
/*B*/ { 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9 },
/*C*/ { 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9 },
};
// -RSAT(x-1,y-1) = [6-1,2-1] = [ 5, 1] => [ 1, 5] OK
// +RSAT(x+w-1,y+w-1) = [6+6-1,2+6-1] = [11, 7] => [ 7,11] OK
// -RSAT(x+w-1-h,y+w-1+h) = [6+6-1-4,2+6-1+4] = [ 7,11] => [11, 7] OK
// +RSAT(x-h-1, y+h-1) = [6-4-1,2+4-1] = [ 1, 5] => [ 5, 1] OK
// int sum = -iit[5,1] + iit[11,7] - iit[7,11] + iit[1,5];
// Create integral image
Bitmap bmp = Accord.Imaging.Tools.ToBitmap(img);
IntegralImage2 ii = IntegralImage2.FromBitmap(bmp, 0, true);
// Tilted rectangular feature
long[,] iit = tiltedIntegral3(img);
long expected = 48;
long sum = -(-iit[5 + (1), 1 + (2)] + iit[11 + (1), 7 + (2)]
- iit[7 + (1), 11 + (2)] + iit[1 + (1), 5 + (2)]);
long a = iit[y - 1 + (1), x - 1 + (2)];
long b = iit[y + w - 1 + (1), x + w - 1 + (2)];
long c = iit[y + w - 1 + h + (1), x + w - 1 - h + (2)];
long d = iit[y + h - 1 + (1), x - h - 1 + (2)];
long manual = -a + b - c + d;
Assert.AreEqual(expected, sum);
Assert.AreEqual(expected, manual);
long actual = ii.GetSumT(x, y, w, h);
Assert.AreEqual(expected, actual);
}