AForge.Math.Gaussian.Kernel2D C# (CSharp) Method

Kernel2D() private method

private Kernel2D ( int size ) : ].double[
size int
return ].double[
        public double[,] Kernel2D(int size)
        {
            return Normal.Kernel2D(sqrSigma, size);
        }
    }

Usage Example

        public void TestConvolutionGaussian()
        {
            var source = new double[][]
                {
                    new double[] { 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 1, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0 },
                    new double[] { 0, 0, 0, 0, 0 }
                };

            var gaussian = new Gaussian();
            var kernel = gaussian.Kernel2D(3);

            const bool useDynamicDivisorForEdges = false;

            var stopwatch = Stopwatch.StartNew();
            var convolution = Analysis.Math.Convolution(source, source.Length, source[0].Length, kernel, useDynamicDivisorForEdges);
            stopwatch.Stop();

            var sourceValues = string.Join("\n", Array.ConvertAll(source, row => string.Join(string.Empty, Array.ConvertAll(row, value => string.Format(CultureInfo.InvariantCulture, "   {0:0}", value)))));
            Console.WriteLine("\nSource = \n[\n" + sourceValues + "\n]");

            Console.WriteLine(string.Format(CultureInfo.InvariantCulture,
                    "\nKernel (Gaussian) = \n" +
                    "[\n" +
                    "   {0:0.000}   {1:0.000}   {2:0.000}\n" +
                    "   {3:0.000}   {4:0.000}   {5:0.000}\n" +
                    "   {6:0.000}   {7:0.000}   {8:0.000}\n" +
                    "]",
                    kernel[0, 0], kernel[0, 1], kernel[0, 2],
                    kernel[1, 0], kernel[1, 1], kernel[1, 2],
                    kernel[2, 0], kernel[2, 1], kernel[2, 2]));

            var resultValues = string.Join("\n", Array.ConvertAll(convolution, row => string.Join(string.Empty, Array.ConvertAll(row, value => string.Format(CultureInfo.InvariantCulture, "   {0:0.00}", value)))));
            Console.WriteLine("\nConvolution (duration: " + stopwatch.ElapsedMilliseconds + " ms) = \n[\n" + resultValues + "\n]");
        }