Example #1
0
        private static void Main()
        {
            var bmp    = (Bitmap)Image.FromFile("eurobot.bmp");
            var pixels = LoadPixels(bmp);

            var form = new Form
            {
                ClientSize = new Size(3 * ResizeRate * bmp.Width, 2 * ResizeRate * bmp.Height)
            };

            var panel = new TableLayoutPanel
            {
                RowCount    = 2,
                ColumnCount = 3,
                Dock        = DockStyle.Fill
            };

            form.Controls.Add(panel);

            panel.Controls.Add(CreateBox(ConvertToBitmap(pixels)), 0, 0);
            var grayscale = GrayscaleTask.ToGrayscale(pixels);

            panel.Controls.Add(CreateBox(ConvertToBitmap(grayscale)), 1, 0);
            var clear = MedianFilterTask.MedianFilter(grayscale);

            panel.Controls.Add(CreateBox(ConvertToBitmap(clear)), 2, 0);
            var sobell = SobelFilterTask.SobelFilter(clear, new double[, ] {
                { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 }
            });

            panel.Controls.Add(CreateBox(ConvertToBitmap(sobell)), 0, 1);
            var trashhold = ThresholdFilterTask.ThresholdFilter(sobell, 0.1);

            panel.Controls.Add(CreateBox(ConvertToBitmap(trashhold)), 1, 1);

            var bitmap = ConvertToBitmap(sobell);

            using (var g = Graphics.FromImage(bitmap))
            {
                var lines = HoughTransformTask.HoughAlgorithm(sobell);
                var pen   = new Pen(Color.Red, 2);
                foreach (var e in lines)
                {
                    g.DrawLine(pen, e.X0 * ResizeRate, e.Y0 * ResizeRate, e.X1 * ResizeRate, e.Y1 * ResizeRate);
                }
            }
            panel.Controls.Add(CreateBox(bitmap), 2, 1);
            Application.Run(form);

            /*var image = new double[1, 1];
             * image[0, 0] = 1;
             *
             * var filter = new double[1, 1];
             * filter[0, 0] = 2;
             *
             * var result = SobelFilterTask.SobelFilter(image, filter);
             *
             * Console.WriteLine(result[0,0]);
             * Console.ReadKey(true);*/
        }
Example #2
0
        private static void Main()
        {
            var bmp    = (Bitmap)Image.FromFile("eurobot.bmp"); //загрузка изображения
            var pixels = LoadPixels(bmp);                       // разбивка изображения на двумерный массив заполненный экземплярами класса Pixel

            var form = new Form                                 //создает новое окно
            {
                ClientSize = new Size(3 * ResizeRate * bmp.Width, 2 * ResizeRate * bmp.Height)
            };

            var panel = new TableLayoutPanel //разбивка окна на "сетку" для размещения элементов по ячейкам (без привязки коорд)
            {
                RowCount    = 2,
                ColumnCount = 3,
                Dock        = DockStyle.Fill
            };

            form.Controls.Add(panel);                                     //добавление сетки в окно

            panel.Controls.Add(CreateBox(ConvertToBitmap(pixels)), 0, 0); //вывод эталлоного изображения
            var grayscale = GrayscaleTask.ToGrayscale(pixels);

            panel.Controls.Add(CreateBox(ConvertToBitmap(grayscale)), 1, 0); //
            var clear = MedianFilterTask.MedianFilter(grayscale);

            panel.Controls.Add(CreateBox(ConvertToBitmap(clear)), 2, 0);
            var sobell = SobelFilterTask.SobelFilter(clear, new double[, ] {
                { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 }
            });

            //   var sobell = SobelFilterTask.SobelFilter(new double[,] { { 1 } }, new double[,] { { 2 } });
            panel.Controls.Add(CreateBox(ConvertToBitmap(sobell)), 0, 1);
            var trashhold = ThresholdFilterTask.ThresholdFilter(sobell, 0.2);

            panel.Controls.Add(CreateBox(ConvertToBitmap(trashhold)), 1, 1);

            var bitmap = ConvertToBitmap(sobell);

            using (var g = Graphics.FromImage(bitmap))
            {
                var lines = HoughTransformTask.HoughAlgorithm(sobell);
                var pen   = new Pen(Color.Red, 2);
                foreach (var e in lines)
                {
                    g.DrawLine(pen, e.X0 * ResizeRate, e.Y0 * ResizeRate, e.X1 * ResizeRate, e.Y1 * ResizeRate);
                }
            }

            panel.Controls.Add(CreateBox(bitmap), 2, 1);
            Application.Run(form);
        }