示例#1
0
        private void ProcessSharp(int m)
        {
            var cho = _image[_fChoose.ChoosedFile];

            byte[,,] res = null;
            string type = "";

            switch (m)
            {
            case 0:
                res  = new Robert(cho).RobertData;
                type = "-罗伯特锐化最终图";
                break;

            case 1:
                res  = new Sobel(cho).SobelData;
                type = "-Sobel锐化最终图";
                break;

            case 2:
                res  = new Lap(cho).Lapla;
                type = "-拉普拉斯锐化最终图";
                break;
            }

            AddNewPic(res, cho.FileName + type, false);
        }
示例#2
0
        private EnergyFunctionBase GetEnergyAlgorithm()
        {
            EnergyFunctionBase function;

            switch (algorithmDropDown.SelectedIndex)
            {
            case 1:
                function = new Sobel();
                break;

            case 2:
                function = new Prewitt();
                break;

            case 3:
                function = new PrewittSlanting();
                break;

            case 4:
                function = new Laplacian();
                break;

            default:
                function = new RobertsCross();
                break;
            }
            return(function);
        }
示例#3
0
        //public void ApplyCanny(double threshold = 50.0, double thresholdLink = 20.0)
        //{
        //    if (_ImageInput == null)
        //    {
        //        return;
        //    }

        //    Image<Gray, byte> imgCanny = new Image<Gray, byte>(_ImageInput.Width, _ImageInput.Height, new Gray(0));
        //    imgCanny = _ImageInput.Canny(threshold, thresholdLink);
        //    imageBox1.Image = imgCanny;
        //}
        private void sobelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Sobel sobel = new Sobel();

            sobel.setSobelInput(_ImageInput);
            imageBox1.Image = sobel.ApplySobel();
        }
示例#4
0
        private void btnProcessImage_Click(object sender, EventArgs e)
        {
            _algoryths["Собеля"]          = new Sobel(_parameterSettingForm.SobelLimit);
            _algoryths["Гаусса"]          = new Gauss(_parameterSettingForm.Sigma);
            _algoryths["Медианный"]       = new MedianFilter(_parameterSettingForm.WindowSize);
            _algoryths["Скользящее окно"] = new SlidingWindow(_parameterSettingForm.WindowSize);
            if (_imageIsLoaded)
            {
                pictureBoxResult.Image = _algoryths[cmbBox.Text].Process(new Bitmap(pictureBoxResult.Image));
                return;
            }

            MessageBox.Show("Load image first!");
        }
示例#5
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Find out which devices we have installed in the system.
                IReadOnlyList <IGorgonVideoAdapterInfo> deviceList = GorgonGraphics.EnumerateAdapters();

                if (deviceList.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "There are no suitable video adapters available in the system. This example is unable to continue and will now exit.");
                    GorgonApplication.Quit();
                    return;
                }

                _graphics = new GorgonGraphics(deviceList[0]);
                _renderer = new GraphicsRenderer(_graphics);
                _renderer.SetPanel(PanelDisplay);

                // Load the compute shader.
#if DEBUG
                _sobelShader = GorgonShaderFactory.Compile <GorgonComputeShader>(_graphics, Resources.ComputeShader, "SobelCS", true);
#else
                _sobelShader = GorgonShaderFactory.Compile <GorgonComputeShader>(_graphics, Resources.ComputeShader, "SobelCS");
#endif
                _sobel = new Sobel(_graphics, _sobelShader);

                GorgonApplication.IdleMethod = Idle;
            }
            catch (Exception ex)
            {
                GorgonExample.HandleException(ex);
                GorgonApplication.Quit();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
示例#6
0
        /// <summary>
        /// Edge detection using the Sobel algorithm. Here we create a new window from where we implement the algorithm.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sobel_Click(object sender, RoutedEventArgs e) {
            if (m_data.M_inputFilename == string.Empty || m_data.M_bitmap == null) {
                MessageBox.Show("Open image first!", "ArgumentsNull", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try {
                Sobel sobelWindow = new Sobel(m_data, m_vm);
                sobelWindow.Owner = this;
                sobelWindow.Show();
            } catch (FileNotFoundException ex) {
                MessageBox.Show(ex.Message, "FileNotFoundException", MessageBoxButton.OK, MessageBoxImage.Error);
            } catch (ArgumentException ex) {
                MessageBox.Show(ex.Message, "ArgumentException", MessageBoxButton.OK, MessageBoxImage.Error);
            } catch (InvalidOperationException ex) {
                MessageBox.Show(ex.Message, "InvalidOperationException", MessageBoxButton.OK, MessageBoxImage.Error);
            } catch (IndexOutOfRangeException ex) {
                MessageBox.Show(ex.Message, "IndexOutOfRangeException", MessageBoxButton.OK, MessageBoxImage.Error);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#7
0
        private void Sobel_Click(object sender, EventArgs e)
        {
            Sobel s = new Sobel();

            this.img.Image = s.Executar(mainImage.Imagem);
        }
示例#8
0
        private Bitmap Compute(Bitmap inputImage)
        {
            // Define output array
            int[,] output;

            // Get the grayscale image from src
            int[,] grayscale = Grayscale.FromBitmap(inputImage);
            int width  = grayscale.GetLength(0);
            int height = grayscale.GetLength(1);

            // Detect edges using sobel
            int[,] edges = Sobel.Compute(grayscale);


            bool[,] strucElem =
            {
                { false, true, false },
                { true,  true, true  },
                { false, true, false }
            };

            // Calculate white top-hat (WTH) with plus-shaped structuring element
            int[,] wth = Defaults.Combine(edges, Morphologicals.Opening(edges, strucElem), (a, b) => a - b);

            // Create thresholds from the WTH
            int[,] wth60 = Threshold.Compute(wth, 60);
            int[,] wth30 = Threshold.Compute(wth, 30);

            // Calculate Hough transform
            const double STEP_SIZE = 0.25;

            int[,] hough       = Hough.Compute(wth60, STEP_SIZE);
            int[,] houghWindow = Window.Compute(hough, 20000, int.MaxValue);

            // Find and filter lines from hough transform
            SortedSet <Line> lines = Lines.FindLines(houghWindow, STEP_SIZE);

            lines = Lines.FilterLines(lines);

            strucElem = new bool[, ]
            {
                { false, false, true, false, false },
                { false, true, true, true, false },
                { true, true, true, true, true },
                { false, true, true, true, false },
                { false, false, true, false, false }
            };

            // Find all rectangles that somewhat resemble a card shape
            IList <Card> cards = Lines.FindCardShapedRectangles(lines, width, height);

            // Filter all card shaped rectangles with enough line support
            int[,] dilation = Morphologicals.Dilation(wth60, strucElem);
            IList <Card> filteredCards = Lines.FilterCardShapedRectangles(dilation, cards);

            // Set the output image, convert it to a bitmap and create a graphics object so we can draw on it
            switch (outputSelector.SelectedIndex)
            {
            default:
            case 0:
                output = grayscale;
                break;

            case 1:
                output = edges;
                break;

            case 2:
                output = wth;
                break;

            case 3:
                output = wth60;
                break;

            case 4:
                output = wth30;
                break;

            case 5:
                output = dilation;
                break;

            case 6:
                output = hough;
                break;
            }
            Bitmap outputImage = Grayscale.ToBitmap(Defaults.Normalize(output));

            if (output == hough)
            {
                return(outputImage);
            }

            Graphics g = Graphics.FromImage(outputImage);

            // Draw the filtered lines
            if (drawFilteredLinesCheckbox.Checked)
            {
                DrawLines(lines, g, outputImage.Width, outputImage.Height);
            }

            // Draw the potential cards (card-shaped rectangles)
            if (drawFoundRectanglesCheckbox.Checked)
            {
                foreach (Card card in cards)
                {
                    card.Draw(g, Pens.Yellow);
                }
            }

            if (drawFilteredRectanglesCheckbox.Checked)
            {
                foreach (Card card in filteredCards)
                {
                    card.Draw(g, Pens.Red);
                }
            }

            // Classify and draw all filtered cards
            foreach (Card card in filteredCards)
            {
                List <ShapeInfo> shapes = Shapes.Find(wth30, card);

                if (shapes.Count > 10)
                {
                    continue;
                }

                Suit suit = Shapes.ClassifyShapes(shapes);
                if (suit != Suit.Unknown)
                {
                    // Draw the bboxes of the shapes
                    if (drawBBCheckbox.Checked)
                    {
                        DrawShapes(shapes, g);
                    }

                    // Draw the card outline
                    if (drawFoundCardsCheckbox.Checked)
                    {
                        card.Draw(g);
                    }

                    // Format the card name and print it on the card
                    string cardName = String.Format("{0} of {1}", shapes.Count == 1 ? "Ace" : shapes.Count.ToString(), suit);
                    g.DrawString(cardName, new Font("Arial", 14), Brushes.Orange, new PointF(card.bottomLeft.X, card.bottomLeft.Y + 4));

                    Console.WriteLine(cardName);
                }
            }
            return(outputImage);
        }
示例#9
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo goo   = null;
            Image   image = new Image();

            if (!DA.GetData(0, ref goo))
            {
                return;
            }
            if (!goo.TryGetImage(ref image))
            {
                return;
            }

            int mode = 0;

            DA.GetData(1, ref mode);

            double numValA = 1.0;

            DA.GetData(2, ref numValA);

            int numValB = 1;

            DA.GetData(3, ref numValB);

            int numValC = 1;

            DA.GetData(4, ref numValC);

            int numValD = 1;

            DA.GetData(5, ref numValD);

            Filter filter = new Filter();

            int[] indices = new int[] { 2, 3, 4, 5 };

            switch ((FilterModes)mode)
            {
            case FilterModes.Canny:
                SetParameter(2, "X", "Sigma", "Gaussian sigma");
                SetParameter(3, "S", "Size", "Gaussian size");
                SetParameter(4, "L", "Low Threshold", "High threshold value used for hysteresis");
                SetParameter(5, "H", "High Threshold", "Low threshold value used for hysteresis");
                filter = new Canny(numValA, numValB, numValC, numValD);
                image.Filters.Add(new Canny());
                break;

            case FilterModes.Difference:
                ClearParameter(indices);
                filter = new Difference();
                image.Filters.Add(new Difference());
                break;

            case FilterModes.Homogeneity:
                ClearParameter(indices);
                filter = new Homogeneity();
                image.Filters.Add(new Homogeneity());
                break;

            case FilterModes.Kirsch:
                ClearParameter(indices);
                filter = new Kirsch();
                image.Filters.Add(new Kirsch());
                break;

            case FilterModes.Robinson:
                ClearParameter(indices);
                filter = new Robinson();
                image.Filters.Add(new Robinson());
                break;

            case FilterModes.Sobel:
                ClearParameter(indices);
                filter = new Sobel();
                image.Filters.Add(new Sobel());
                break;
            }

            message = ((FilterModes)mode).ToString();
            UpdateMessage();

            DA.SetData(0, image);
            DA.SetData(1, filter);
        }