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");
        }
 public static string ApplyBradleyLocalThresholding(string inputPath, string outputPath)
 {
     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);
     dstimg.Save(outputPath);
     dstimg.Dispose();
     dstimg = null;
     img.Dispose();
     img = null;
     return outputPath;
 }
コード例 #3
0
        public static string ApplyBradleyLocalThresholding(string inputPath, string outputPath)
        {
            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);

            dstimg.Save(outputPath);
            dstimg.Dispose();
            dstimg = null;
            img.Dispose();
            img = null;
            return(outputPath);
        }
        public static void test(String directory)
        {
            ColorSegmentationWorker cs = new ColorSegmentationWorker();
            //cs.Apply(@"C:\Users\yaoyichi\Desktop\", @"C:\Users\yaoyichi\Desktop\", "WMSImage_ms.png");

            //            AForge.Imaging.Filters.OtsuThreshold otsu = new AForge.Imaging.Filters.OtsuThreshold();
            AForge.Imaging.Filters.BradleyLocalThresholding bradley = new AForge.Imaging.Filters.BradleyLocalThresholding();
            Image<Gray, Byte> img = new Image<Gray, Byte>(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64.png");
            Bitmap dstimg =bradley.Apply(img.Bitmap);

            dstimg.Save(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64-2.png");
              //  Image<Gray, Byte> img = new Image<Gray, Byte>(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64.png");

            img = img.ThresholdAdaptive(new Gray(255),
              Emgu.CV.CvEnum.ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_GAUSSIAN_C,Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY,15,new Gray(0));

            img.Save(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64-1.png");
        }
コード例 #5
0
        public static void test(String directory)
        {
            ColorSegmentationWorker cs = new ColorSegmentationWorker();

            //cs.Apply(@"C:\Users\yaoyichi\Desktop\", @"C:\Users\yaoyichi\Desktop\", "WMSImage_ms.png");

//            AForge.Imaging.Filters.OtsuThreshold otsu = new AForge.Imaging.Filters.OtsuThreshold();
            AForge.Imaging.Filters.BradleyLocalThresholding bradley = new AForge.Imaging.Filters.BradleyLocalThresholding();
            Image <Gray, Byte> img    = new Image <Gray, Byte>(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64.png");
            Bitmap             dstimg = bradley.Apply(img.Bitmap);

            dstimg.Save(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64-2.png");
            //  Image<Gray, Byte> img = new Image<Gray, Byte>(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64.png");


            img = img.ThresholdAdaptive(new Gray(255),
                                        Emgu.CV.CvEnum.ADAPTIVE_THRESHOLD_TYPE.CV_ADAPTIVE_THRESH_GAUSSIAN_C, Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY, 15, new Gray(0));

            img.Save(@"C:\Users\yaoyichi\Desktop\Images-22-10\576800_mc1024_k64-1.png");
        }
コード例 #6
0
ファイル: Preprocessor.cs プロジェクト: NoxHarmonium/enform
        public Bitmap Process(Bitmap image)
        {
            Bitmap filteredImage = convertFormatTo32(image);

            if (filterLevel >= 0)
            {
                filteredImage = resize(filteredImage, ImageSize.Width, ImageSize.Height);
            }
            if (filterLevel >= 1)
            {

                if (ContrastStretch)
                {
                    AForge.Imaging.Filters.ContrastStretch stretcher = new AForge.Imaging.Filters.ContrastStretch();
                    filteredImage = stretcher.Apply(filteredImage);

                }

                if (Histogram)
                {
                    AForge.Imaging.Filters.HistogramEqualization histogrammer = new AForge.Imaging.Filters.HistogramEqualization();
                    filteredImage = histogrammer.Apply(filteredImage);

                }

                if (Gaussian)
                {
                    AForge.Imaging.Filters.GaussianBlur blurrer = new AForge.Imaging.Filters.GaussianBlur();
                    blurrer.Size = (int)GaussianStrength;
                    filteredImage = blurrer.Apply(filteredImage);
                }

                if (ContrastAdjustment)
                {
                    AForge.Imaging.Filters.ContrastCorrection contraster = new AForge.Imaging.Filters.ContrastCorrection();
                    contraster.Factor = (float)ContrastStrength;
                    filteredImage = contraster.Apply(filteredImage);
                }

                if (Greyscale)
                {
                    filteredImage = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(filteredImage);
                    //Greyscale downgrades format
                    // filteredImage  = convertFormatTo32(filteredImage.InternalBitmap);
                }
                if (Threshold)
                {
                    //filteredImage.InternalBitmap = convertFormatToGS(filteredImage.InternalBitmap);
                    AForge.Imaging.Filters.Threshold thresholder = new AForge.Imaging.Filters.Threshold();
                    thresholder.ThresholdValue = (int)(((double)ThresholdStrength / 10.0) * 255.0);
                    filteredImage = thresholder.Apply(filteredImage);

                }
                if (Bradley)
                {
                    AForge.Imaging.Filters.BradleyLocalThresholding bradlifier = new AForge.Imaging.Filters.BradleyLocalThresholding();

                    filteredImage = bradlifier.Apply(filteredImage);

                }
            }

            return filteredImage;
        }