/// <summary> /// CONSTRUCTOR /// Pass both the original image and structure tensor because need to calculate derivatives as well as eigenvalues. /// Cannot easily derive the partial derivatives from the structure tensor because have lost the sign info. /// </summary> /// <param name="avImage"></param> /// <param name="avStructureTensor"></param> public static StructureTensorResult GetStructureTensorInfo(double[,] avImage, double[,] avStructureTensor) { int rowCount = avStructureTensor.GetLength(0); int colCount = avStructureTensor.GetLength(1); if (rowCount != 2 && colCount != 2) { throw new Exception("Structure tensor must be 2x2 matrix"); } double dx = avImage[1, 1] - avImage[1, 0]; double dy = avImage[0, 0] - avImage[1, 0]; var result = new StructureTensorResult(); result.Derivative = dy / dx; result.Magnitude = Math.Sqrt((dy * dy) + (dx * dx)); double radians = Math.Atan2(dy, dx); result.Radians = radians; result.Degrees = radians * (180 / Math.PI); double[] eigenValues = CalculateEigenValues(avStructureTensor); result.EigenValue1 = Math.Abs(eigenValues[0]); result.EigenValue2 = Math.Abs(eigenValues[1]); result.Dominance = Math.Abs((result.EigenValue1 - result.EigenValue2) / (result.EigenValue1 + result.EigenValue2)); //Console.WriteLine("Slope magnitude={0} dy/dx={1}", result.Magnitude, result.Derivative); //Console.WriteLine("Radians={0:f2} Angle={1:f1}", radians, result.Degrees); //Console.WriteLine("Eigenvalues = {0:f6} and {1:f6}. Dominance = {2:f2}", eigenValues[0], eigenValues[1], result.Dominance); return(result); }
public static void Test1StructureTensor() { // create a local image matrix double[,] image = { { 0.9, 10.0, }, { 10.0, 0.0, }, }; var structureTensorMatrix = CalculateStructureTensor(image); StructureTensorResult result = GetStructureTensorInfo(image, structureTensorMatrix); }