Exemplo n.º 1
0
        /// <summary>
        /// Pass a vertical and horizontal gabor filter over the superimposed images
        /// </summary>
        /// <param name="combinedPixels"></param>
        /// <returns></returns>
        public static double GaborFilter(Matrix <double> combinedPixels)
        {
            //convert to grayscale
            var bm = BitmapFromPixels(combinedPixels, 200);
            //bm = ToGrayscale(bm);

            var gaborFilter = new GaborFilter();

            //get the vertical gabor edges
            gaborFilter.Theta = 0.0;
            var vertBitmap = gaborFilter.Apply(bm);
            var pixels     = Array1DFromBitmap(vertBitmap).Select(x => x / 255.0).ToArray();
            var vert       = GetVerticalEdges(pixels);

            //get the horizontal gabor edges
            gaborFilter.Theta = Math.PI / 2;
            var horizBitmap = gaborFilter.Apply(bm);

            pixels = Array1DFromBitmap(horizBitmap).Select(x => x / 255.0).ToArray();;
            var horiz = GetHorizontalEdges(pixels);

            var sum = vert.Sum() + horiz.Sum();// + left.Sum();

            return(sum);
        }
Exemplo n.º 2
0
        public Bitmap gaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta)
        {
            GaborFilter filter = new GaborFilter();
            Random      random = new Random();
            Boolean     flaga  = true;



            filter.Gamma  = gamma;
            filter.Lambda = lambda;
            filter.Psi    = psi;
            filter.Sigma  = sigma;
            filter.Theta  = theta;

            Bitmap bx = ImageSupporter.ColorToGrayscale(b);

            var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx))));

            okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta;
            okno.Show();


            filter.Gamma = 3.0;
            filter.Theta = 0.0;
            GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB();

            return(grayscaleToRGB.Apply(filter.Apply(ImageSupporter.ColorToGrayscale(b))));
        }
Exemplo n.º 3
0
        public static Bitmap gaborFilter(Bitmap b, GaborFilter gf)
        {
            // Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);



            /*filter.Gamma = random.Next(1,5);
             * filter.Lambda=random.Next(1,5);
             * filter.Psi=random.Next(1,5);
             * filter.Sigma=random.Next(1,5);
             * filter.Theta=random.Next(1,5);*/

            Bitmap bx = ImageSupporter.ColorToGrayscale(b);

            gf.Apply(ImageSupporter.ColorToGrayscale(bx));
            //  var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx))));
            // okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta;
            // okno.Show();



            GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB();

            return(grayscaleToRGB.Apply(gf.Apply(ImageSupporter.ColorToGrayscale(b))));
        }
Exemplo n.º 4
0
        public void ProcessImageTest()
        {
            double[,] diag = Matrix.Magic(5);

            Bitmap input;

            new MatrixToImage().Convert(diag, out input);

            // Create a new Gabor filter
            GaborFilter gabor = new GaborFilter();

            // Apply the filter
            Bitmap output = gabor.Apply(input);

            double[,] actual;

            new ImageToMatrix().Convert(output, out actual);

            double[,] expected =
            {
                { 0.192156862745098, 0.176470588235294, 0.254901960784314, 0.396078431372549, 0.529411764705882 },
                {  0.16078431372549, 0.305882352941176, 0.494117647058824, 0.635294117647059, 0.654901960784314 },
                { 0.407843137254902, 0.623529411764706, 0.737254901960784, 0.701960784313725, 0.564705882352941 },
                { 0.752941176470588, 0.815686274509804, 0.713725490196078, 0.541176470588235, 0.403921568627451 },
                { 0.847058823529412, 0.694117647058824, 0.505882352941176, 0.380392156862745, 0.329411764705882 }
            };

            Assert.IsTrue(expected.IsEqual(actual, 1e-6));
        }
Exemplo n.º 5
0
        public static void GaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta)
        {
            GaborFilter gb     = new GaborFilter();
            Random      random = new Random();
            Bitmap      bx;



            gb.Gamma  = gamma;
            gb.Lambda = lambda;
            gb.Psi    = psi;
            gb.Sigma  = sigma;

            gb.Theta = theta;
            bx       = ImageSupporter.ColorToGrayscale((Bitmap)b.Clone());


            Bitmap tmp = bx;

            tmp = gb.Apply(bx);

            ImageWindow iw = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(tmp));

            iw.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta;
            iw.Show();
        }
Exemplo n.º 6
0
        public void GaborTest1()
        {
            Bitmap image = Properties.Resources.lena512;

            GaborFilter gabor = new GaborFilter();

            Bitmap result = gabor.Apply(image);

            // ImageBox.Show(result);
            Assert.IsNotNull(result);
        }
Exemplo n.º 7
0
        public void GaborTest1()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Resources.lena512);

            GaborFilter gabor = new GaborFilter();

            Bitmap result = gabor.Apply(image);

            // ImageBox.Show(result);
            Assert.IsNotNull(result);
        }
Exemplo n.º 8
0
        public static Bitmap GaborFilter(Bitmap b, float angle)
        {
            Bitmap      bz       = (Bitmap)b.Clone();
            GaborBank   gb       = new GaborBank();
            GaborFilter gf       = gb.GetGaborFilterFromBank(angle);
            Bitmap      bx       = ImageSupporter.ColorToGrayscale((Bitmap)bz.Clone());
            Bitmap      filtered = gf.Apply(bx);


            return(ImageSupporter.GrayScaleToColor(filtered));
        }
Exemplo n.º 9
0
        private double Runal(GaborFilter gaborFilter, Bitmap b)
        {
            try
            {
                Bitmap output = gaborFilter.Apply(b);

                Accord.Imaging.ImageStatistics statistics = new Accord.Imaging.ImageStatistics(output);
                var histogram = statistics.Gray;
                return(histogram.Mean);
            }
            catch (Exception e) { return(0); }
            //    featuredata = featuredata + mean + ",";
        }
Exemplo n.º 10
0
        private void edgeDetect(ushort j)
        {
            cvsbmp = UtilFn.BitmapImage2Bitmap(images[j]);

            Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721);

            Bitmap grayImage = gfilter.Apply(cvsbmp);

            GaborFilter filter = new GaborFilter();

            Bitmap output = filter.Apply(grayImage);

            imagesEdited.Add(converter.Convert(output, Type.GetType("BitmapImage"), null, null) as BitmapImage);
        }
Exemplo n.º 11
0
        public static Bitmap gaborFilter(Bitmap b, float gamma, float lambda, float psi, float sigma, float theta)
        {
            // Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);

            GaborFilter filter = new GaborFilter();
            Random      random = new Random();
            Boolean     flaga  = true;



            filter.Gamma  = gamma;
            filter.Lambda = lambda;
            filter.Psi    = psi;
            filter.Sigma  = sigma;
            filter.Theta  = theta;


            /*filter.Gamma = random.Next(1,5);
             * filter.Lambda=random.Next(1,5);
             * filter.Psi=random.Next(1,5);
             * filter.Sigma=random.Next(1,5);
             * filter.Theta=random.Next(1,5);*/

            Bitmap bx = ImageSupporter.ColorToGrayscale(b);

            filter.Apply(ImageSupporter.ColorToGrayscale(bx));
            //  var okno = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(filter.Apply(ImageSupporter.ColorToGrayscale(bx))));
            // okno.Title = filter.Gamma + " " + filter.Lambda + " " + filter.Psi + " " + filter.Sigma + " " + filter.Theta;
            // okno.Show();



            GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB();

            return(grayscaleToRGB.Apply(filter.Apply(ImageSupporter.ColorToGrayscale(b))));
        }
Exemplo n.º 12
0
        //metoda zwracająca bank filtrów gabora dla zadanej bitmapy
        public static List <Bitmap> gaborFilterMyBank(Bitmap bs)
        {
            List <SetValuesForGabor> bank = new List <SetValuesForGabor>();

            bank.Add(new SetValuesForGabor(4, 8, 0.5f, 9.2f, 0));
            bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(15)));
            bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(30)));
            bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(45)));
            bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(60)));
            bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(75)));
            bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.6f, (float)ImageSupporter.DegreeToRadian(90)));
            bank.Add(new SetValuesForGabor(4, 7.3f, 0.5f, 4.4f, (float)ImageSupporter.DegreeToRadian(105)));
            bank.Add(new SetValuesForGabor(4, 6.2f, 0.5f, 3.7f, (float)ImageSupporter.DegreeToRadian(120)));
            bank.Add(new SetValuesForGabor(4, 7, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(135)));
            bank.Add(new SetValuesForGabor(4, 6.5f, 0.5f, 4.3f, (float)ImageSupporter.DegreeToRadian(150)));
            bank.Add(new SetValuesForGabor(4, 8, 0.5f, 4.8f, (float)ImageSupporter.DegreeToRadian(165)));



            GaborFilter gb     = new GaborFilter();
            Random      random = new Random();
            Bitmap      bx;
            Bitmap      b = (Bitmap)bs.Clone();

            List <Bitmap> gaborBank = new List <Bitmap>();

            bx = ImageSupporter.ColorToGrayscale(b);

            for (int i = 0; i < bank.Count; i++)
            {
                bank[i].SetGaborFilter(gb);
                gaborBank.Add(gb.Apply((Bitmap)bx.Clone()));

                ImageWindow im = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(gaborBank[i]));

                im.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta;
                im.Show();
            }

            return(gaborBank);
        }
Exemplo n.º 13
0
        public static void gaborFilterRandom(Bitmap b)
        {
            GaborFilter gb     = new GaborFilter();
            Random      random = new Random();
            Bitmap      bx;



            for (int i = 1; i < 100; i++)
            {
                gb.Gamma  = random.NextDouble() * random.Next(1, 10);;
                gb.Lambda = random.Next(1, 10);
                gb.Psi    = random.NextDouble();
                gb.Sigma  = random.Next(1, 10);

                gb.Theta = 0;
                bx       = ImageSupporter.ColorToGrayscale(b);
                if (gb.Gamma == 0)
                {
                    gb.Gamma = 0.01;
                }
                Console.WriteLine(gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta);
                try
                {
                    ImageWindow iw = new ImageWindow(ImageSupporter.Bitmap2BitmapImage(gb.Apply(bx)));
                    iw.Title = gb.Gamma + " " + gb.Lambda + " " + gb.Psi + " " + gb.Sigma + " " + gb.Theta;
                    iw.Show();
                }
                catch (Exception e)
                {
                    e.GetBaseException();
                }
            }
        }