示例#1
0
        // 0 sigma, 1 gamma, 2 theta, 3 lambda, 4 psi

        public static ConvolutionKernel CalculateGaborKernel(List <double> param,
                                                             Func <int, int, List <double>, float> function)                     //todo check formula
        {
            int sm   = (int)param[0];
            int half = 3 * sm;
            int size = 6 * sm + 1;

            ConvolutionKernel kernel = new ConvolutionKernel();

            kernel.Kernel = new float[size * size];
            float sum = 0;

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    float val = function(i - half, j - half, param);
                    kernel.Kernel[j * size + i] = val;
                    sum += val;
                }
            }

            kernel.Sum = sum;
            return(kernel);
        }
示例#2
0
        public static List <ConvolutionKernel> CalculateKernelXY(double sigma,
                                                                 Func <int, int, double, float> function)                //todo check formula
        {
            int sm   = (int)sigma;
            int half = 3 * sm;
            int size = 6 * sm + 1;

            ConvolutionKernel kernelX = new ConvolutionKernel();

            kernelX.Kernel = new float[size * size];
            kernelX.Sum    = 0;

            ConvolutionKernel kernelY = new ConvolutionKernel();

            kernelY.Kernel = new float[size * size];
            kernelY.Sum    = 0;

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    var valX = function(i - half, j - half, sigma);
                    var valY = function(j - half, i - half, sigma);
                    kernelX.Kernel[j * size + i] = valX;
                    kernelY.Kernel[j * size + i] = valY;
                    kernelX.Sum += Math.Abs(valX);
                    kernelY.Sum += Math.Abs(valY);
                }
            }

            return(new List <ConvolutionKernel>()
            {
                kernelX, kernelY
            });
        }
示例#3
0
        public static ConvolutionKernel CalculateKernel(double sigma,
                                                        Func <int, int, double, float> function)                     //todo check formula
        {
            int sm   = (int)sigma;
            int half = 3 * sm;
            int size = 6 * sm + 1;

            ConvolutionKernel kernel = new ConvolutionKernel();

            kernel.Kernel = new float[size * size];
            float sum = 0;

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    float val = function(i - half, j - half, sigma);
                    kernel.Kernel[j * size + i] = val;
                    sum += val;
                }
            }

            kernel.Sum = sum;
            return(kernel);
        }
示例#4
0
        public static GrayscaleFloatImage Gabor(ColorFloatImage image, double sigma,
                                                double gamma, double theta, double lambda,
                                                double psi)
        {
            List <double> param = new List <double>();

            param.Add(sigma);
            param.Add(gamma);
            param.Add(DegreeToRadian(theta));
            param.Add(lambda);
            param.Add(psi);

            ConvolutionKernel kernel = CalculateGaborKernel(param, GaborPoint);

            return(GradientGrayscale(image, kernel.Kernel, 1));
        }
示例#5
0
        public static List <GrayscaleFloatImage> MagnitudeAndDirections(ColorFloatImage image,
                                                                        ConvolutionKernel xKernel, ConvolutionKernel yKernel)
        {
            var xWindow = xKernel.Kernel;
            var yWindow = yKernel.Kernel;
            GrayscaleFloatImage magn   = new GrayscaleFloatImage(image.Width, image.Height);
            GrayscaleFloatImage angles = new GrayscaleFloatImage(image.Width, image.Height);

            int windowSide     = (int)Math.Pow(xWindow.Length, 0.5);
            int halfWindowSide = (windowSide - 1) / 2;

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    List <int>   i   = NeighbourIndexes(x, image.Width - 1, halfWindowSide, FillMode.Reflection);
                    List <int>   j   = NeighbourIndexes(y, image.Height - 1, halfWindowSide, FillMode.Reflection);
                    List <float> pix = new List <float>();

                    for (int k = 0; k < windowSide; k++)
                    {
                        for (int n = 0; n < windowSide; n++)
                        {
                            pix.Add(RGB2GrayPix(image[i[n], j[k]]));
                        }
                    }

                    float xPix = ConvolveGray(xWindow, pix, xKernel.Sum);
                    float yPix = ConvolveGray(yWindow, pix, yKernel.Sum);

                    magn[x, y]   = (float)Math.Sqrt(Math.Pow(xPix, 2) + Math.Pow(yPix, 2));
                    angles[x, y] = FitAngleInBin(Math.Abs(Math.Atan2(yPix, xPix)));
                }
            }
            return(new List <GrayscaleFloatImage>()
            {
                magn, angles
            });
        }
示例#6
0
        public static GrayscaleFloatImage GaussMagnitude(ColorFloatImage image, float sigma)
        {
            ConvolutionKernel kernel = CalculateKernel(sigma, LoGPoint);

            return(GradientGrayscale(image, kernel.Kernel, 1));
        }
示例#7
0
        public static ColorFloatImage Gauss(ColorFloatImage image, float sigma)
        {
            ConvolutionKernel kernel = CalculateKernel(sigma, GaussPoint);

            return(Gradient(image, kernel.Kernel, kernel.Sum));
        }