Esempio n. 1
0
        public void ThresholdFilterOneXTwo() // 1x2
        {
            var original = new double[, ] {
                { 1, 0 }
            };
            var expected = new double[, ] {
                { 1.0, 0.0 }
            };
            var actual = ThresholdFilterClass.ThresholdFilter(original, 0.5);

            Assert.AreEqual(expected, actual);
        }
        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 = Grayscale.ToGrayscale(pixels);

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

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

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

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

            var bitmap = ConvertToBitmap(sobell);

            using (var g = Graphics.FromImage(bitmap))
            {
                var lines = HoughTransform.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);
        }