private void button1_Click(object sender, EventArgs e) { ImageNode rootNode = new ImageNode(new Bitmap(pictureBox1.Image)); Multiply mulr = new Multiply(1f / 3f); Multiply mulg = new Multiply(1f / 3f); Multiply mulb = new Multiply(1f / 3f); rootNode.GetOutput("r").register(mulr); rootNode.GetOutput("g").register(mulg); rootNode.GetOutput("b").register(mulb); Sum sum = new Sum(); mulr.GetOutput().register(sum); mulg.GetOutput().register(sum); mulb.GetOutput().register(sum); SobelEdge sx = new SobelEdge(); sum.GetOutput().register(sx); rootNode.Update(null); Bitmap bmp = new Bitmap(sx.GetOutput().Image.Width, sx.GetOutput().Image.Height); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color c = Color.FromArgb(255, sx.GetOutput("out").Image.Data[x, y], sx.GetOutput("out").Image.Data[x, y], sx.GetOutput("out").Image.Data[x, y]); bmp.SetPixel(x, y, c); } } pictureBox2.Image = bmp; }
internal static void SobelEdges(Graphics g) { try { if (_imgGray == null) { _imgInput = new Image <Bgr, byte>(_processor.Frame); _imgGray = _imgInput.Convert <Gray, byte>(); _imgSobel = new Image <Gray, float>(_imgInput.Width, _imgInput.Height, new Gray(0)); } if (sobel == null) { sobel = new SobelEdge(); sobel.ShowDialog(); } paintPos = 0; _imgSobel = _imgGray.Sobel(_xorder, _yorder, _apertureSize); g.DrawImage(_imgSobel.ToBitmap(_imgInput.Width, _imgInput.Height), new Rectangle(0, 0, _imgInput.Width, _imgInput.Height)); g.DrawString($"X: {_xorder}, Y: {_yorder}, Aperture size: {_apertureSize}", font, Brushes.Green, 5, paintPos * height); } catch (Exception) { } }