private void InitializeFilters() { grayscaleFilter = new Grayscale(0.299, 0.587, 0.114); bradleyLocalFilter = new BradleyLocalThresholding(); bradleyLocalFilter.WindowSize = 9; bradleyLocalFilter.PixelBrightnessDifferenceLimit = 0.01f; plateBlobsFiltering = new BlobsFiltering(10, 20, 80, 66); blobCounter = new BlobCounter(); blobCounter.FilterBlobs = true; blobCounter.MinWidth = 50; blobCounter.MinHeight = 10; blobCounter.MaxWidth = 520; blobCounter.MaxHeight = 110; plateBlobCounter = new BlobCounter(); shapeChecker = new SimpleShapeChecker(); otsuThresholdFilter = new OtsuThreshold(); fillHoles = new FillHoles(); fillHoles.MaxHoleWidth = 100; fillHoles.MaxHoleHeight = 40; pen = new Pen(Color.GreenYellow, 4); openingFilter = new Opening(); contrastCorrectionFilter = new ContrastCorrection(80); colorFiltering = new ColorFiltering(); colorFiltering.Red = new IntRange(150, 255); colorFiltering.Green = new IntRange(150, 255); colorFiltering.Blue = new IntRange(150, 255); colorFiltering.FillOutsideRange = true; invert = new Invert(); }
private Mat Fill(Mat input, int maxWidth, int maxHeight) { Stopwatch w = new Stopwatch(); w.Start(); Bitmap bm = input.Bitmap; Image <Gray, byte> im = new Image <Gray, byte>(bm); FillHoles fh = new FillHoles(); im = im.Dilate(1); fh.MaxHoleWidth = maxWidth; fh.MaxHoleHeight = maxHeight; try { bm = fh.Apply(im.Bitmap); } catch (Exception e) { MessageBox.Show("" + e.ToString(), "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } im = new Image <Gray, byte>(bm); im = im.Erode(1); w.Stop(); input = im.Mat; return(input); }
private void timer4_Tick(object sender, EventArgs e) { pictureBox3.Image = (Bitmap)pictureBox2.Image.Clone(); // Pozisyon görüntüsü oluşturulur. p_1 = (Bitmap)pictureBox3.Image; islem = new Subtract(p_3).Apply(p_1); // Ana görüntüden pozisyon görüntüsü çıkartılır.Sadece pozisyon bilgisi elde edilir. islem = new FillHoles().Apply(islem); // Görüntüyü netleştirebilmek adına küçük boşluklar doldurulmuştur. Ve ardından opening işlemi yapılmıştır. islem = new Opening().Apply(islem); pictureBox5.Image = islem; timer3.Start(); }
static DiffCalculator() { threshold = new Threshold(THERSHOLD); fillHoles = new FillHoles(); fillHoles.MaxHoleHeight = 125; fillHoles.MaxHoleWidth = 125; fillHoles.CoupledSizeFiltering = true; gaussianBlur = new GaussianBlur(3, 11); }
public static Bitmap ProcessImage(string imagePath) { var img = AForge.Imaging.Image.FromFile(imagePath); ContrastStretch filterContrastStretch = new ContrastStretch(); filterContrastStretch.ApplyInPlace(img); try { img = Grayscale.CommonAlgorithms.BT709.Apply(img); } catch { System.Windows.Forms.MessageBox.Show("The image should not be grayscale"); } Opening filterOpening = new Opening(); filterOpening.ApplyInPlace(img); SobelEdgeDetector sobel = new SobelEdgeDetector(); sobel.ApplyInPlace(img); Closing filterClosing = new Closing(); filterClosing.ApplyInPlace(img); Threshold threshold = new Threshold(100); threshold.ApplyInPlace(img); FillHoles fillHoles = new FillHoles(); fillHoles.MaxHoleWidth = img.Width; fillHoles.MaxHoleHeight = img.Height; fillHoles.CoupledSizeFiltering = false; fillHoles.ApplyInPlace(img); filterOpening.ApplyInPlace(img); Erosion filterErosion = new Erosion(); filterErosion.ApplyInPlace(img); return(img); }
public mErosionFill(int maxWidth, int maxHeight, bool couple) { MaxWidth = maxWidth; MaxHeight = maxHeight; Couple = couple; BitmapType = mFilter.BitmapTypes.GrayscaleBT709; Effect = new FillHoles(); Effect.MaxHoleWidth = MaxWidth; Effect.MaxHoleHeight = MaxHeight; Effect.CoupledSizeFiltering = couple; filter = Effect; }
private void fillHoles() { Closing close = new Closing(); imageGot = close.Apply(imageGot); imageGot = close.Apply(imageGot); Opening opening = new Opening(); imageGot = opening.Apply(imageGot); FillHoles fillHoles = new FillHoles(); fillHoles.MaxHoleHeight = 20; fillHoles.MaxHoleWidth = 20; fillHoles.CoupledSizeFiltering = false; imageGot = fillHoles.Apply(imageGot); pictureBox1.Image = imageGot; }
/// <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); bool valueA = false; DA.GetData(2, ref valueA); int valueB = 1; DA.GetData(3, ref valueB); int valueC = 1; DA.GetData(4, ref valueC); Filter filter = new Filter(); switch ((FilterModes)mode) { case FilterModes.Closing: SetParameter(2); SetParameter(3); SetParameter(4); filter = new Closing(); image.Filters.Add(new Closing()); break; case FilterModes.Dilation: SetParameter(2); SetParameter(3); SetParameter(4); filter = new Dilation(); image.Filters.Add(new Dilation()); break; case FilterModes.DilationBinary: SetParameter(2); SetParameter(3); SetParameter(4); filter = new DilationBinary(); image.Filters.Add(new DilationBinary()); break; case FilterModes.Erosion: SetParameter(2); SetParameter(3); SetParameter(4); filter = new Erosion(); image.Filters.Add(new Erosion()); break; case FilterModes.ErosionBinary: SetParameter(2); SetParameter(3); SetParameter(4); filter = new ErosionBinary(); image.Filters.Add(new ErosionBinary()); break; case FilterModes.HatBottom: SetParameter(2); SetParameter(3); SetParameter(4); filter = new HatBottom(); image.Filters.Add(new HatBottom()); break; case FilterModes.HatTop: SetParameter(2); SetParameter(3); SetParameter(4); filter = new HatTop(); image.Filters.Add(new HatTop()); break; case FilterModes.Opening: SetParameter(2); SetParameter(3); SetParameter(4); filter = new Opening(); image.Filters.Add(new Opening()); break; case FilterModes.Skeletonization: SetParameter(2); SetParameter(3); SetParameter(4); filter = new Skeletonization(); image.Filters.Add(new Skeletonization()); break; case FilterModes.SkeletonizationZhangSuen: SetParameter(2); SetParameter(3); SetParameter(4); filter = new SkeletonizationZhangSuen(); image.Filters.Add(new SkeletonizationZhangSuen()); break; case FilterModes.HorizontalBands: SetParameter(2, "B", "Borders", "Process gaps"); SetParameter(3, "G", "Gap", "The pixel gap size"); SetParameter(4); filter = new BandsHorizontal(valueB, valueA); image.Filters.Add(new BandsHorizontal(valueB, valueA)); break; case FilterModes.VerticalBands: SetParameter(2, "B", "Borders", "Process gaps"); SetParameter(3, "G", "Gap", "The pixel gap size"); SetParameter(4); filter = new BandsVertical(valueB, valueA); image.Filters.Add(new BandsVertical(valueB, valueA)); break; case FilterModes.FillHoles: SetParameter(2, "B", "Borders", "Process gaps"); SetParameter(3, "W", "Width", "The pixel threshold"); SetParameter(4, "H", "Height", "The pixel threshold"); filter = new FillHoles(valueC, valueB, valueA); image.Filters.Add(new FillHoles(valueC, valueB, valueA)); break; } message = ((FilterModes)mode).ToString(); UpdateMessage(); DA.SetData(0, image); DA.SetData(1, filter); }
public Binarize(UISettings ui, FileData file) : base(ui, file) { try { Invert AFinvert = new Invert(); switch (ui.ThresholdIndex) // threshold method selection "Global mean" / "Local adaptive" { case 0: // Global if (ui.ThreshGlobalIsAbsolute) // use absolute { Threshold AFglobalbinary = new Threshold(ui.ThreshGlobalAbsolute); UnmanagedBlackWhite = AFglobalbinary.Apply(UnmanagedGray); } else // use relative { ImageStatistics stats = new ImageStatistics(UnmanagedGray, AFinvert.Apply(UnmanagedExclude)); Threshold AFglobalbinary = new Threshold(stats.Gray.Center2QuantileValue(1.0d * ui.ThreshGlobalRelative / 255.0d)); UnmanagedBlackWhite = AFglobalbinary.Apply(UnmanagedGray); } break; case 1: // Local BradleyLocalThresholdingX AFlocalbinary = new BradleyLocalThresholdingX() { PixelBrightnessDifferenceLimit = ui.ThreshLocalBrightnessDifference, WindowSize = ui.ThreshLocalWindowSize, UpperLimit = 250 }; UnmanagedBlackWhite = AFlocalbinary.Apply(UnmanagedGray); break; } if (ui.FillHoleAirspaceSwitch && ui.FillHoleAirspace != 0) // fill holes of airspaces { FillHoles AFfillinair = new FillHoles() { CoupledSizeFiltering = true, MaxHoleHeight = ui.FillHoleAirspace, MaxHoleWidth = ui.FillHoleAirspace }; //FillHolesArea AFfillinair=new FillHolesArea() { MaxHoleArea=ui.FillHoleAirspace }; AFfillinair.ApplyInPlace(UnmanagedBlackWhite); } UnmanagedBlackWhite = AFinvert.Apply(UnmanagedBlackWhite); if (ui.FillHoleTissueSwitch && ui.FillHoleTissue != 0) // fill holes of tissue { FillHoles AFfillintissue = new FillHoles() { CoupledSizeFiltering = true, MaxHoleHeight = ui.FillHoleTissue, MaxHoleWidth = ui.FillHoleTissue }; //FillHolesArea AFfillintissue=new FillHolesArea() { MaxHoleArea=ui.FillHoleTissue }; AFfillintissue.ApplyInPlace(UnmanagedBlackWhite); } if (ui.MorphoDilateSwitch && ui.MorphoDilate != 0) // Morphological Dilate { int n = (Math.Max(ui.MorphoDilate, 0) * 2 + 1); short[,] morphmatrix = new short[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { morphmatrix[i, j] = 1; } } Dilatation AFdilate = new Dilatation(morphmatrix); AFdilate.ApplyInPlace(UnmanagedBlackWhite); } if (ui.MorphoErodeSwitch && ui.MorphoErode != 0) // Morphological Erode { int n = (Math.Max(ui.MorphoErode, 0) * 2 + 1); short[,] morphmatrix = new short[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { morphmatrix[i, j] = 1; } } Erosion AFerode = new Erosion(morphmatrix); AFerode.ApplyInPlace(UnmanagedBlackWhite); } if (ui.ExcludeColorSwitch) { NonParen_SumArea = ui.um2px2 * UnmanagedExclude.NonBlackArea(); } if (ui.BlobMinSwitch) { Low_Threshold = Math.Pow(10.0d, ui.BlobMin) - 1; } else { Low_Threshold = 0.0d; } if (ui.BlobMaxSwitch) { High_Threshold = Math.Pow(10.0d, ui.BlobMax) - 1; } else { High_Threshold = int.MaxValue; } if (ui.BlobMinSwitch || ui.BlobMaxSwitch) { Merge AFmerge1 = new Merge(UnmanagedExclude); ExcludeSize AFexcsize = new ExcludeSize() { Low = (int)Math.Round(Low_Threshold / ui.um2px2), High = (int)Math.Round(Math.Min(int.MaxValue, High_Threshold / ui.um2px2)) }; Merge AFmerge2 = new Merge(AFexcsize.Apply(AFinvert.Apply(AFmerge1.Apply(UnmanagedBlackWhite)))); AFmerge2.ApplyInPlace(UnmanagedExclude); Low_SumArea = ui.um2px2 * AFexcsize.LowCount; High_SumArea = ui.um2px2 * AFexcsize.HighCount; } } catch { throw new Exception("Error Occured During Binarization"); } }