public void MagnitudeDirectionTest()
{
byte[,] gradient = new byte[255, 255];
for (int i = 0; i < 255; i++)
for (int j = 0; j < 255; j++)
gradient[i, j] = (byte)j;
UnmanagedImage output;
new MatrixToImage().Convert(gradient, out output);
//ImageBox.Show(output);
HistogramsOfOrientedGradients hog = new HistogramsOfOrientedGradients();
var result = hog.ProcessImage(output);
float[,] actualDir = hog.Direction;
Assert.AreEqual(255, actualDir.GetLength(0));
Assert.AreEqual(255, actualDir.GetLength(1));
for (int i = 0; i < 255; i++)
for (int j = 0; j < 255; j++)
Assert.AreEqual(0, actualDir[i, j]);
float[,] actualMag = hog.Magnitude;
Assert.AreEqual(255, actualMag.GetLength(0));
Assert.AreEqual(255, actualMag.GetLength(1));
for (int i = 0; i < 255; i++)
{
for (int j = 0; j < 255; j++)
{
if (i == 0 || j == 0 || i == 254 || j == 254)
Assert.AreEqual(0, actualMag[i, j]);
else
Assert.AreEqual(1, actualMag[i, j]);
}
}
}
}