public void Apply()
        {
            string output_dir = @"C:\Users\yaoyichi\Desktop\";
            string inputPath  = output_dir + "1.png";

            Log.SetLogDir(output_dir);
            Log.SetOutputDir(output_dir);

            HoughCircleTransformation circleTransform = new HoughCircleTransformation(35);
            // apply Hough circle transform
            Bitmap srcimg = new Bitmap(inputPath);

            AForge.Imaging.Filters.BradleyLocalThresholding bradley = new AForge.Imaging.Filters.BradleyLocalThresholding();
            Image <Gray, Byte> img    = new Image <Gray, Byte>(inputPath);
            Bitmap             dstimg = bradley.Apply(img.Bitmap);

            circleTransform.ProcessImage(dstimg);
            Bitmap houghCirlceImage = circleTransform.ToBitmap();

            // get circles using relative intensity
            HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity(0.2);
            Graphics      g       = Graphics.FromImage(ImageUtils.AnyToFormat24bppRgb(srcimg));

            foreach (HoughCircle circle in circles)
            {
                //circle.RelativeIntensity
                g.DrawEllipse(new Pen(Color.Red), circle.X, circle.Y, circle.Radius, circle.Radius);
            }
            g.Dispose();
            srcimg.Save(output_dir + "1_.png");
        }
Пример #2
0
        private void houghCircle(Bitmap basicSaus)
        {
            Bitmap saus = ConvertToFormat(basicSaus);
            HoughCircleTransformation circleTransform = new HoughCircleTransformation(35);

            // apply Hough circle transform
            circleTransform.ProcessImage(saus);
            Bitmap houghCirlceImage = circleTransform.ToBitmap();

            // get circles using relative intensity
            HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity(0.1);

            foreach (HoughCircle circle in circles)
            {
                Console.WriteLine(JsonConvert.SerializeObject(circle, Formatting.Indented));
            }
            pictureBox2.Image = houghCirlceImage;
        }
        public void HughCircleTransform()
        {
            Grayscale filterGrayscale = new Grayscale(0.2125, 0.7154, 0.0721);

            ImageBitmap8pp = filterGrayscale.Apply(ImageBitmap);

            Blur filterBlur = new Blur();

            filterBlur.ApplyInPlace(ImageBitmap8pp);

            //ContrastStretch filterContrast = new ContrastStretch();
            //filterContrast.ApplyInPlace(ImageBitmap8pp);

            ImageBitmap8pp.Save("test0.bmp");

            CannyEdgeDetector filter = new CannyEdgeDetector();

            filter.ApplyInPlace(ImageBitmap8pp);

            HoughCircleTransformation circleTransform = new HoughCircleTransformation(35);

            circleTransform.LocalPeakRadius = 300;
            circleTransform.ProcessImage(ImageBitmap8pp);
            Bitmap houghCirlceImage = circleTransform.ToBitmap();

            HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity(0.6);

            foreach (HoughCircle circle in circles)
            {
                Pen redPen = new Pen(System.Drawing.Color.Red, 3);
                using (var graphics = Graphics.FromImage(ImageBitmap))
                {
                    graphics.DrawEllipse(redPen, circle.X - circle.Radius, circle.Y - circle.Radius, circle.Radius * 2, circle.Radius * 2);
                }
            }

            ImageBitmap8pp.Save("test1.bmp");
            houghCirlceImage.Save("test2.bmp");
            ImageBitmap.Save("test3.bmp");
        }
Пример #4
0
        private void button4_Click(object sender, EventArgs e)
        {
            Bitmap sourceImage = (Bitmap)pictureBox1.Image;
            HoughCircleTransformation circleTransform = new HoughCircleTransformation(35);

            // apply Hough circle transform
            circleTransform.ProcessImage(ConvertToFormat(sourceImage, PixelFormat.Format8bppIndexed));
            Bitmap houghCirlceImage = circleTransform.ToBitmap();

            // get circles using relative intensity
            HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity(0.5);
            Graphics      g;

            MessageBox.Show("Jumlah Lingkaran: " + circles.Length.ToString());

            foreach (HoughCircle circle in circles)
            {
                Pen pen = new Pen(Brushes.Black, 5);
                g = Graphics.FromImage(houghCirlceImage);
                g.DrawEllipse(pen, circle.X, circle.Y, 5, 5);
                g.Dispose();
            }
            pictureBox2.Image = sourceImage;
        }