示例#1
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     ImageFactory imageFactory = new ImageFactory();
     imageFactory.Load(pictureBox1.BackgroundImage);
     IEdgeFilter edgeFilter = new SobelEdgeFilter();
     imageFactory.DetectEdges(edgeFilter, true);
     pictureBox1.BackgroundImage = imageFactory.Image;
 }
        /// <summary>
        /// Performs the DetectEdges effect from the ImageProcessor library.
        /// </summary>
        /// <param name="image">The image with which to apply the effect.</param>
        /// <param name="filter">The IEdgeFilter object that will detect the edges.</param>
        /// <param name="greyscale">Whether or not the resulting image will be greyscale.</param>
        /// <returns>A new image with the DetectEdges effect applied.</returns>
        public Image DetectEdges(Image image, IEdgeFilter filter, bool greyscale = true)
        {
            using var factory = new ImageFactory();

            factory.Load(image);
            factory.DetectEdges(filter, greyscale);

            var result = factory.Image;

            return(new Bitmap(result));
        }
示例#3
0
        public bool processImages()
        {
            collectImmages(startDir);
            IEdgeFilter filter          = new KirschEdgeFilter();
            int         threshold_value = 150; //0-255

            for (int i = 0; i < filePaths.Length; i++)
            {
                string aimDirThis    = aimDir + "/res" + i + ".png";
                string aimDirThisPre = aimDir + "/respre" + i + ".png";

                Image  original = Image.FromFile((filePaths[i]));
                Bitmap resized  = new Bitmap(original, new Size(aimWidth, aimHeight));

                Bitmap       greyscale = MakeGrayscale3(resized);
                MemoryStream outStream = new MemoryStream();
                imageProcessor.Load(greyscale);
                imageProcessor.DetectEdges(filter, false);
                imageProcessor.Save(aimDir + "/temp" + "/res" + i + ".png");
                imageProcessor.Save(outStream);


                //Als nächstes eine Binärisierung mit Threshhold auf dem Kanten Bild
                //Dann alles im greyscale Bild nur Pixel behalten, die im Binär = 1
                Image <Gray, Byte> img = new Image <Gray, Byte>(aimDir + "/temp" + "/res" + i + ".png");

                img = img.ThresholdBinary(new Gray(threshold_value), new Gray(255)).Dilate(1).Erode(1);
                var labels    = new Mat();
                var stats     = new Mat();
                var centroids = new Mat();
                var nLabels   = CvInvoke.ConnectedComponentsWithStats(img, labels, stats, centroids);

                int   biggestIndex = 0;
                int   biggestArea  = 0;
                int[] statsData    = new int[stats.Rows * stats.Cols];
                stats.CopyTo(statsData); // Inhalt der 2-D Matrix in 1D Array umwandeln

                //Suche größter weißer Bereich
                for (int j = 5; j < statsData.Length; j = j + 5)  //erste Component ist meistens das Schwarze, kann deswegen ignoriert werden
                {
                    var area = statsData[j + 4];
                    if (area > biggestArea)
                    {
                        biggestArea  = area;
                        biggestIndex = j;
                    }
                }



                /*
                 *   var x = statsData[i * stats.Cols + 0];
                 *   var y = statsData[i * stats.Cols + 1];
                 *   var width = statsData[i * stats.Cols + 2];
                 *   var height = statsData[i * stats.Cols + 3];
                 *   var area = statsData[i * stats.Cols + 4];
                 */

                //Bitmap source = greyscale;
                Bitmap edges = new Bitmap(outStream);

                int componentX      = statsData[biggestIndex + 0];
                int componentY      = statsData[biggestIndex + 1];
                int componentWidth  = statsData[biggestIndex + 2];
                int componentHeight = statsData[biggestIndex + 3];



                Bitmap CroppedColor = cropping(componentX, componentY, componentWidth, componentHeight, resized, true);

                Bitmap CroppedImage = cropping(componentX, componentY, componentWidth, componentHeight, greyscale, false);

                string color = determineColor(CroppedColor);

                CroppedImage.Save(aimDir + "/res" + i + color + ".png", ImageFormat.Png);
                //CroppedColor.Save(aimDir + "/resC" + i + color + ".png", ImageFormat.Png);

                edges = null;

                CroppedImage = null;

                img = null;
            }



            return(true);
        }
示例#4
0
 public override void Apply(ImageFactory fs)
 {
     fs = fs.DetectEdges(filter, greyscale);
 }