/// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <returns>The <see cref="DenseMatrix{T}"/></returns>
        private DenseMatrix <float> CreateGaussianKernel()
        {
            int   size   = this.kernelSize;
            float weight = this.Sigma;
            var   kernel = new DenseMatrix <float>(size, 1);

            float sum      = 0F;
            float midpoint = (size - 1) / 2F;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum         += gx;
                kernel[0, i] = gx;
            }

            // Normalize kernel so that the sum of all weights equals 1
            for (int i = 0; i < size; i++)
            {
                kernel[0, i] /= sum;
            }

            return(kernel);
        }
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <param name="horizontal">Whether to calculate a horizontal kernel.</param>
        /// <returns>The <see cref="T:float[][]"/></returns>
        private float[][] CreateGaussianKernel(bool horizontal)
        {
            int   size   = this.kernelSize;
            float weight = this.sigma;

            float[][] kernel = horizontal ? new float[1][] : new float[size][];

            if (horizontal)
            {
                kernel[0] = new float[size];
            }

            float sum = 0.0f;

            float midpoint = (size - 1) / 2f;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum += gx;
                if (horizontal)
                {
                    kernel[0][i] = gx;
                }
                else
                {
                    kernel[i] = new[] { gx };
                }
            }

            // Normalise kernel so that the sum of all weights equals 1
            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[0][i] = kernel[0][i] / sum;
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[i][0] = kernel[i][0] / sum;
                }
            }

            return(kernel);
        }
示例#3
0
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <param name="horizontal">Whether to calculate a horizontal kernel.</param>
        /// <returns>The <see cref="Fast2DArray{T}"/></returns>
        private Fast2DArray <float> CreateGaussianKernel(bool horizontal)
        {
            int   size   = this.kernelSize;
            float weight = this.sigma;
            Fast2DArray <float> kernel = horizontal
                ? new Fast2DArray <float>(size, 1)
                : new Fast2DArray <float>(1, size);

            float sum      = 0F;
            float midpoint = (size - 1) / 2F;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum += gx;
                if (horizontal)
                {
                    kernel[0, i] = gx;
                }
                else
                {
                    kernel[i, 0] = gx;
                }
            }

            // Normalize kernel so that the sum of all weights equals 1
            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[0, i] = kernel[0, i] / sum;
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[i, 0] = kernel[i, 0] / sum;
                }
            }

            return(kernel);
        }
示例#4
0
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <returns>The <see cref="DenseMatrix{T}"/></returns>
        private DenseMatrix <float> CreateGaussianKernel()
        {
            int   size   = this.kernelSize;
            float weight = this.Sigma;
            var   kernel = new DenseMatrix <float>(size, 1);

            float sum = 0;

            float midpoint = (size - 1) / 2F;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum         += gx;
                kernel[0, i] = gx;
            }

            // Invert the kernel for sharpening.
            int midpointRounded = (int)midpoint;

            for (int i = 0; i < size; i++)
            {
                if (i == midpointRounded)
                {
                    // Calculate central value
                    kernel[0, i] = (2F * sum) - kernel[0, i];
                }
                else
                {
                    // invert value
                    kernel[0, i] = -kernel[0, i];
                }
            }

            // Normalize kernel so that the sum of all weights equals 1
            for (int i = 0; i < size; i++)
            {
                kernel[0, i] /= sum;
            }

            return(kernel);
        }
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function.
        /// </summary>
        /// <returns>The <see cref="DenseMatrix{T}"/>.</returns>
        internal static DenseMatrix <float> CreateGaussianBlurKernel(int size, float weight)
        {
            var kernel = new DenseMatrix <float>(size, 1);

            float sum      = 0F;
            float midpoint = (size - 1) / 2F;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum         += gx;
                kernel[0, i] = gx;
            }

            // Normalize kernel so that the sum of all weights equals 1
            for (int i = 0; i < size; i++)
            {
                kernel[0, i] /= sum;
            }

            return(kernel);
        }
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <param name="horizontal">Whether to calculate a horizontal kernel.</param>
        /// <returns>The <see cref="Fast2DArray{T}"/></returns>
        private Fast2DArray <float> CreateGaussianKernel(bool horizontal)
        {
            int   size   = this.kernelSize;
            float weight = this.sigma;
            Fast2DArray <float> kernel = horizontal
                ? new Fast2DArray <float>(size, 1)
                : new Fast2DArray <float>(1, size);

            float sum = 0;

            float midpoint = (size - 1) / 2f;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum += gx;
                if (horizontal)
                {
                    kernel[0, i] = gx;
                }
                else
                {
                    kernel[i, 0] = gx;
                }
            }

            // Invert the kernel for sharpening.
            int midpointRounded = (int)midpoint;

            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    if (i == midpointRounded)
                    {
                        // Calculate central value
                        kernel[0, i] = (2F * sum) - kernel[0, i];
                    }
                    else
                    {
                        // invert value
                        kernel[0, i] = -kernel[0, i];
                    }
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    if (i == midpointRounded)
                    {
                        // Calculate central value
                        kernel[i, 0] = (2 * sum) - kernel[i, 0];
                    }
                    else
                    {
                        // invert value
                        kernel[i, 0] = -kernel[i, 0];
                    }
                }
            }

            // Normalise kernel so that the sum of all weights equals 1
            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[0, i] = kernel[0, i] / sum;
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[i, 0] = kernel[i, 0] / sum;
                }
            }

            return(kernel);
        }
示例#7
0
        /// <summary>
        /// Create a 1 dimensional Gaussian kernel using the Gaussian G(x) function
        /// </summary>
        /// <param name="horizontal">Whether to calculate a horizontal kernel.</param>
        /// <returns>The <see cref="T:float[][]"/></returns>
        private float[][] CreateGaussianKernel(bool horizontal)
        {
            int   size   = this.kernelSize;
            float weight = this.sigma;

            float[][] kernel = horizontal ? new float[1][] : new float[size][];

            if (horizontal)
            {
                kernel[0] = new float[size];
            }

            float sum = 0;

            float midpoint = (size - 1) / 2f;

            for (int i = 0; i < size; i++)
            {
                float x  = i - midpoint;
                float gx = ImageMaths.Gaussian(x, weight);
                sum += gx;
                if (horizontal)
                {
                    kernel[0][i] = gx;
                }
                else
                {
                    kernel[i] = new[] { gx };
                }
            }

            // Invert the kernel for sharpening.
            int midpointRounded = (int)midpoint;

            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    if (i == midpointRounded)
                    {
                        // Calculate central value
                        kernel[0][i] = (2f * sum) - kernel[0][i];
                    }
                    else
                    {
                        // invert value
                        kernel[0][i] = -kernel[0][i];
                    }
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    if (i == midpointRounded)
                    {
                        // Calculate central value
                        kernel[i][0] = (2 * sum) - kernel[i][0];
                    }
                    else
                    {
                        // invert value
                        kernel[i][0] = -kernel[i][0];
                    }
                }
            }

            // Normalise kernel so that the sum of all weights equals 1
            if (horizontal)
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[0][i] = kernel[0][i] / sum;
                }
            }
            else
            {
                for (int i = 0; i < size; i++)
                {
                    kernel[i][0] = kernel[i][0] / sum;
                }
            }

            return(kernel);
        }