Accord.Math.Normal.Kernel2D C# (CSharp) Method

Kernel2D() public static method

2-D Gaussian kernel.

The function calculates 2-D Gaussian kernel, which is array of Gaussian function's values in the [-r, r] range of x,y values, where r=floor(size/2).

Wrong kernel size.
public static Kernel2D ( double sigmaSquared, int size ) : ].double[
sigmaSquared double The variance parameter σ² (sigma squared).
size int Kernel size (should be odd), [3, 101].
return ].double[
        public static double[,] Kernel2D(double sigmaSquared, int size)
        {
            // check for evem size and for out of range
            if (((size % 2) == 0) || (size < 3))
                throw new ArgumentOutOfRangeException("size", "Kernel size must be odd and higher than 2.");

            int r = size / 2;

            double[,] kernel = new double[size, size];
            for (int y = -r, i = 0; i < size; y++, i++)
                for (int x = -r, j = 0; j < size; x++, j++)
                    kernel[i, j] = Gaussian2D(sigmaSquared, x, y);

            return kernel;
        }
    }