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(); }
public static Bitmap MorphologySimpleBinarization(this Bitmap image, int morphologyKernel, byte morphologyThreshold) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Filter can be applied to binary 8bpp images only"); } Erosion morphologyErosion = new Erosion(); Bitmap tempMorphologyImage = morphologyErosion.Apply(image); for (int i = 0; i < morphologyKernel - 1; i++) { tempMorphologyImage = morphologyErosion.Apply(tempMorphologyImage); } SimpleGrayImage morphologyImage = new SimpleGrayImage(tempMorphologyImage); OtsuThreshold thresholdFilter = new OtsuThreshold(); SimpleGrayImage otcuImage = new SimpleGrayImage(thresholdFilter.Apply(image)); for (int i = 0; i < morphologyImage.Cols; i++) { for (int j = 0; j < morphologyImage.Rows; j++) { if (morphologyImage.Data[j, i] > morphologyThreshold) { morphologyImage.Data[j, i] = 255; } else { morphologyImage.Data[j, i] = otcuImage.Data[j, i]; } } } return(morphologyImage.Bitmap); }
public static int GetThreshold(Bitmap image) { var unmanagedImage = UnmanagedImage.FromManagedImage(image); UnmanagedImage grayImage; if (unmanagedImage.PixelFormat == PixelFormat.Format8bppIndexed) { grayImage = unmanagedImage; } else { grayImage = UnmanagedImage.Create(unmanagedImage.Width, unmanagedImage.Height, PixelFormat.Format8bppIndexed); Grayscale.CommonAlgorithms.BT709.Apply(unmanagedImage, grayImage); unmanagedImage.Dispose(); } var otsuThresholdFilter = new OtsuThreshold(); otsuThresholdFilter.ApplyInPlace(grayImage); var threshold = otsuThresholdFilter.ThresholdValue; grayImage.Dispose(); return(threshold); }
public Bitmap DocumentAlign(Bitmap image) { try { // get grayscale image from current image Bitmap grayImage = (image.PixelFormat == PixelFormat.Format8bppIndexed) ? AForge.Imaging.Image.Clone(image) : AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(image); // threshold it using adaptive Otsu thresholding OtsuThreshold threshold = new OtsuThreshold(); threshold.ApplyInPlace(grayImage); // get skew angle DocumentSkewChecker skewChecker = new DocumentSkewChecker(); double angle = skewChecker.GetSkewAngle(grayImage); if ((angle < -skewChecker.MaxSkewToDetect) || (angle > skewChecker.MaxSkewToDetect)) { throw new ApplicationException(); } // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter return(rotationFilter.Apply(image)); } catch { Console.WriteLine("Failed determining skew angle. Is it reallly a scanned document?"); return(image); } }
private void detectObjectsToolStripMenuItem_Click(object sender, EventArgs e) { var img = (Bitmap)currentImage.Clone(); var showImg = (Bitmap)currentImage.Clone(); // img = Grayscale.CommonAlgorithms.Y.Apply(img); img = new OtsuThreshold().Apply(img); img = new Erosion().Apply(img); img = new Invert().Apply(img); BlobCounter bc = new BlobCounter(); bc.BackgroundThreshold = Color.Black; bc.ProcessImage(img); MessageBox.Show(String.Format("The image contains {0} objects.", bc.ObjectsCount)); Rectangle rect = new Rectangle(0, 0, showImg.Width, showImg.Height); BitmapData bmpData = showImg.LockBits(rect, ImageLockMode.ReadWrite, showImg.PixelFormat); bc.GetObjectsRectangles().ToList().ForEach(i => { Drawing.Rectangle(bmpData, i, Color.GreenYellow); }); showImg.UnlockBits(bmpData); pictureBox.Image = showImg; }
private void hücreSayToolStripMenuItem_Click(object sender, EventArgs e) { islem = new ExtractNormalizedRGBChannel(RGB.G).Apply(kaynak); islem = new OtsuThreshold().Apply(islem); islem = new Invert().Apply(islem); islem = new Opening().Apply(islem); BlobCounter bc = new BlobCounter(); bc.FilterBlobs = false; bc.MinHeight = 5; bc.MinWidth = 5; bc.ProcessImage(islem); Rectangle[] rects = bc.GetObjectsRectangles(); listBox1.Items.Add(rects.Length + " tane hücre var"); Bitmap cizim = new Bitmap(islem.Width, islem.Height); Graphics g = Graphics.FromImage(cizim); g.DrawImage(islem, 0, 0); Pen cerceve = new Pen(Color.Red, 2); foreach (Rectangle rect in rects) { listBox1.Items.Add(rect.Location + " " + rect.Size); g.DrawRectangle(cerceve, rect); } g.Dispose(); kaynakBox.Image = cizim; }
void ThresholdingToolStripMenuItemClick(object sender, EventArgs e) { //jika gambar kosong/null maka akan mengembalikan nilai kosong/null if (gambar == null) { return; } //clone variable gambar ke variable gambar2 dan menginisiasi class Rectangle //dan menerapkan format pixel 24bppRgb gambar2 = gambar.Clone(new Rectangle(0, 0, gambar.Width, gambar.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); //convert ke grayscale terlebih dahulu lalu aplikasikan filter thresholding. //inisiasi filter grayscale disertai argumen Grayscale grayscaleF = new Grayscale(0.2125, 0.7154, 0.0721); //aplikasikan filter grayscale ke gambar2 gambar2 = grayscaleF.Apply(gambar2); //inisiasi filter thresholding OtsuThreshold otsuThreshold = new OtsuThreshold( ); //aplikasikan filter pada gambar2 otsuThreshold.ApplyInPlace(gambar2); //tampilkan pada picturebox2 pictureBox2.Image = gambar2; }
public IImage Apply(IImage image) { var grayScale = ToGrayScale(image); var filter = new OtsuThreshold(); var bmp = filter.Apply(grayScale.ToBgr().Lock().AsAForgeImage()); return(bmp.AsImage()); }
public override Bitmap ApplyFilter(Bitmap imgThreshold) { //Threshold filterThreshold = new Threshold(this._iThreshold); OtsuThreshold filterThreshold = new OtsuThreshold(); this._imgOriginalThreshold = filterThreshold.Apply(imgThreshold); return(this._imgOriginalThreshold); }
public mThresholdOtsu() { BitmapType = BitmapTypes.GrayscaleBT709; Effect = new OtsuThreshold(); filter = Effect; }
/* * 1- gray scale transform; * */ public void ToGray(ref Bitmap image) { image = (Bitmap)ResizeImage((System.Drawing.Image)image); // Create a blank bitmap with the same dimensions Bitmap imageGray = new Bitmap(image); Median medianFilter = new Median(); // apply the filter medianFilter.ApplyInPlace(image); // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter image = filter.Apply(imageGray); // create filter Invert invertFilter = new Invert(); // apply the filter invertFilter.ApplyInPlace(image); // create filter OtsuThreshold filterOtsuThreshold = new OtsuThreshold(); // apply the filter filterOtsuThreshold.ApplyInPlace(image); // check threshold value int t = filterOtsuThreshold.ThresholdValue; /* * // create and configure the filter * FillHoles holesFilter = new FillHoles(); * holesFilter.MaxHoleHeight = 2; * holesFilter.MaxHoleWidth = 2; * holesFilter.CoupledSizeFiltering = false; * // apply the filter * Bitmap result = holesFilter.Apply(image); * * * BinaryDilatation3x3 bd = new BinaryDilatation3x3(); * bd.ApplyInPlace(image); * bd.ApplyInPlace(image); * * // create filter * BlobsFiltering filterBlobsFiltering = new BlobsFiltering(); * // configure filter * filterBlobsFiltering.CoupledSizeFiltering = true; * filterBlobsFiltering.MinWidth = 5; * filterBlobsFiltering.MinHeight = 5; * // apply the filter * filterBlobsFiltering.ApplyInPlace(image); */ }
public Bitmap otsu(Bitmap kaynakresim) { Bitmap filtreliResim; OtsuThreshold otsuFiltre = new OtsuThreshold(); filtreliResim = otsuFiltre.Apply(kaynakresim.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(kaynakresim) : kaynakresim); return(filtreliResim); }
private void button3_Click(object sender, EventArgs e) { Grayscale grayfilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImg = grayfilter.Apply(img1); OtsuThreshold filter = new OtsuThreshold(); img2 = filter.Apply(grayImg); pictureBox2.Image = img2; }
private void btnOtsuAlgoritmasiUygula_Click(object sender, EventArgs e) { Bitmap image = new Bitmap(pictureBox1.Image); OtsuThreshold otsuFiltre = new OtsuThreshold(); //Bitmap filtreliResim = otsuFiltre.Apply(image.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(image) : image); Bitmap filtreliResim = otsuFiltre.Apply(Grayscale.CommonAlgorithms.BT709.Apply(image)); pictureBox4.Image = filtreliResim; this.Text = "Threshold Değeri : " + otsuFiltre.ThresholdValue.ToString(); }
private void sketchFilterButton_Click(object sender, EventArgs e) { Grayscale grayfilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImg = grayfilter.Apply(originImage); OtsuThreshold filter = new OtsuThreshold(); processedImage = filter.Apply(grayImg); processedPictureBox.Image = processedImage; }
private void button1_Click(object sender, EventArgs e) { Bitmap FiltreliResim, KaynakResim; OtsuThreshold OtsuFiltre = new OtsuThreshold(); KaynakResim = (Bitmap)pictureBox1.Image; FiltreliResim = OtsuFiltre.Apply(KaynakResim.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(KaynakResim) : KaynakResim); pictureBox2.Image = FiltreliResim; this.Text = "Threshold Değeri : " + OtsuFiltre.ThresholdValue.ToString(); }
private void button1_Click(object sender, EventArgs e) { OtsuThreshold filter = new OtsuThreshold(); Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap srcBitmap = new Bitmap(sourcePictureBox.Image); Bitmap grayImage = grayFilter.Apply(srcBitmap); filter.ApplyInPlace(grayImage); resultPictureBox.Image = grayImage; chart1.Series[0].Points.DataBindY(calculateChart(grayImage)); }
/// <summary> /// Binarize image with Otsu threshold filter /// </summary> /// <param name="image"></param> public static Image OtsuThreshold(this Bitmap image) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new NotSupportedException("Filter can be applied to binary 8bpp images only"); } OtsuThreshold thresholdFilter = new OtsuThreshold(); return(thresholdFilter.Apply(image)); }
public Util() { w = new CryptoQrUtilities.QrUtilitiesWrapper(); filter = new EuclideanColorFiltering(); filter.CenterColor = new AForge.Imaging.RGB(Color.Black); filter.Radius = 0; bw = new OtsuThreshold(); ecR = new ExtractChannel(RGB.R); ecG = new ExtractChannel(RGB.G); ecB = new ExtractChannel(RGB.B); }
public void Execute() { Console.WriteLine("Execute OCR"); OCR.Statistics.Clear(); OCR.Statistics.AddCounter("Processors", System.Environment.ProcessorCount); SISThreshold filter = new SISThreshold(); int Threshold = filter.CalculateThreshold(m_Image.Image, m_Image.Area); OtsuThreshold filterOtsu = new OtsuThreshold(); Threshold = filterOtsu.CalculateThreshold(m_Image.Image, m_Image.Area); PreprocessPage Processor = new PreprocessPage(); Processor.Image = m_Image; Processor.Treshold = m_Image.CalculateOtsuThreshold(); m_Image.Threshold = 170; Processor.Execute(); resultBitmap = PageImage.CreateBitmapFromByteArray(m_Image.BinaryBytes, new Size(m_Image.Width, m_Image.Height)); DetectComponents Step2 = new DetectComponents(); Step2.Image = m_Image; Step2.Execute(); AnalyseComponents Step3 = new AnalyseComponents(); Step3.Image = m_Image; Step3.Execute(); DetectSentences Step4 = new DetectSentences(); Step4.Image = m_Image; Step4.Execute(); ExtractFeatures Step5 = new ExtractFeatures(); Step5.Image = m_Image; Step5.Execute(); RecogniseComponent Step6 = new RecogniseComponent(); Step6.Image = m_Image; Step6.Execute(); ProcessSentences Step7 = new ProcessSentences(); Step7.Image = m_Image; Step7.Execute(); }
private void OtsuThreshold_Click(object sender, RoutedEventArgs e) { System.Drawing.Bitmap temp = canvasTool.getBitmapFromCanvas(); temp = Grayscale.CommonAlgorithms.RMY.Apply(temp); OtsuThreshold filter = new OtsuThreshold(); // apply the filter filter.ApplyInPlace(temp); // check threshold value int t = filter.ThresholdValue; canvasTool.SetBmpImageToCanvas(temp); MessageBox.Show("OtsuThreshold Calculated Vaule: " + t, "ThresholdValue", MessageBoxButton.OK, MessageBoxImage.Information); }
private void otsuToolStripMenuItem_Click(object sender, EventArgs e) { OtsuThreshold otsuFilter = new OtsuThreshold(); //Фильтр, котор Grayscale grayFilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap srcBitmap = new Bitmap(sourcePictureBox.Image); Bitmap grayImage = grayFilter.Apply(srcBitmap); int threshold = otsuFilter.CalculateThreshold(grayImage, new Rectangle(0, 0, grayImage.Width, grayImage.Height)) + trackBar1.Value; int delta = 10; Threshold filter = new Threshold(threshold - delta); filter.ApplyInPlace(grayImage); resultPictureBox.Image = grayImage; chart1.Series[0].Points.DataBindY(calculateChart(grayImage)); }
private void button4_Click(object sender, EventArgs e) { Grayscale grayfilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap edgeImg = grayfilter.Apply(img1); OtsuThreshold filter = new OtsuThreshold(); filter.ApplyInPlace(edgeImg); CannyEdgeDetector filter2 = new CannyEdgeDetector(); img2 = filter2.Apply(edgeImg); pictureBox2.Image = img2; }
public void CreateFilters() { grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721); sobelFilter = new SobelEdgeDetector(); dilitationFilter = new Dilatation3x3(); thresholdFilter = new Threshold(100); blobCounter = new BlobCounter {MinHeight = 200, MinWidth = 200, FilterBlobs = true, ObjectsOrder = ObjectsOrder.Size}; shapeChecker = new SimpleShapeChecker(); binaryGlyphRecognizer = new SquareBinaryGlyphRecognizer(5); // 5x5 matrica invertFilter = new Invert(); rotateFilter = new RotateBilinear(90); pen = new Pen(Color.CornflowerBlue, 4); mirrorFilter = new Mirror(false, true); hullFinder = new GrahamConvexHull(); otsuThresholdFilter = new OtsuThreshold(); }
private void processo2() { var img = (Bitmap)pictureBox1.Image.Clone(); var showImg = (Bitmap)pictureBox1.Image.Clone(); //img = Grayscale.CommonAlgorithms.Y.Apply(img); img = new OtsuThreshold().Apply(img); img = new Erosion().Apply(img); img = new Invert().Apply(img); BlobCounter bc = new BlobCounter(); bc.BackgroundThreshold = Color.Black; bc.ProcessImage(img); Rectangle rect = new Rectangle(0, 0, showImg.Width, showImg.Height); BitmapData bmpData = showImg.LockBits(rect, ImageLockMode.ReadWrite, showImg.PixelFormat); bc.GetObjectsRectangles().ToList().ForEach(i => { Crop filter = new Crop(new Rectangle(i.X, i.Y, 230, 75)); var img2 = (Bitmap)filter.Apply(img); img2 = new Invert().Apply(img2); var ocr = new tessnet2.Tesseract(); ocr.SetVariable("tesseract_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVXWYZ-1234567890"); ocr.Init(@"tessdata", "eng", false); var result = ocr.DoOCR(img2, Rectangle.Empty); StringBuilder sb = new StringBuilder(); foreach (tessnet2.Word word in result) { sb.Append(word.Text + " "); } //cliente para servidor string aux; aux = sb.ToString(); if (aux.Length >= 6) { placas.Add(aux); } pictureBox1.Image = img2; }); showImg.UnlockBits(bmpData); pictureBox1.Image = img; }
// New frame event handler, which is invoked on each new available video frame private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { Invoke((MethodInvoker) delegate() { optChose = comboBox2.SelectedIndex; }); Bitmap bmp = (Bitmap)eventArgs.Frame.Clone(); Bitmap bmpPrc = (Bitmap)eventArgs.Frame.Clone(); switch (optChose) { case 0: Grayscale filter0 = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter0.Apply(bmpPrc); OtsuThreshold filter1 = new OtsuThreshold(); pictureBox1.Image = bmp; pictureBox2.Image = filter1.Apply(grayImage); break; case 1: Sepia filter2 = new Sepia(); pictureBox1.Image = bmp; pictureBox2.Image = filter2.Apply(bmpPrc); break; case 2: ChannelFiltering filter3 = new ChannelFiltering(); filter3.Red = new IntRange(0, 255); filter3.Green = new IntRange(100, 255); filter3.Blue = new IntRange(100, 255); pictureBox1.Image = bmp; pictureBox2.Image = filter3.Apply(bmpPrc); break; case 3: HSLFiltering filter4 = new HSLFiltering(); filter4.Hue = new IntRange(340, 20); filter4.UpdateLuminance = false; filter4.UpdateHue = false; pictureBox1.Image = bmp; pictureBox2.Image = filter4.Apply(bmpPrc); break; } }
/// <summary> /// This method binarize image. /// </summary> /// <param name="image"></param> /// <returns></returns> private Bitmap Binarize(Bitmap image) { Median median = new Median(); median.ApplyInPlace(image); var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image); OtsuThreshold OtsuThreshold = new OtsuThreshold(); OtsuThreshold.ApplyInPlace(bmp8bpp); //bmp8bpp.Save(@"C:\Users\Maor\Desktop\mode\BinarizeWithoutDilation.jpeg"); Closing closing = new Closing(); closing.ApplyInPlace(bmp8bpp); return(bmp8bpp); }
//ilk önce bu butona tıklanmalı private void button1_Click(object sender, EventArgs e) { sayac = 1; kaynakResim = (Bitmap)System.Drawing.Image.FromFile("sample2.jpg"); //Otsu Threshold uygulandı OtsuThreshold otsuFiltre = new OtsuThreshold(); //resim eğer renkliyse önce griye çeviriyor sonra filtre uyguluyor //resim zaten griyse direk filtreyi uyguluyor siyahBeyazResim = otsuFiltre.Apply(kaynakResim.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(kaynakResim) : kaynakResim); BlobCounterBase bc = new BlobCounter(); bc.FilterBlobs = true; bc.MinHeight = 5; bc.MinWidth = 5; bc.ProcessImage(siyahBeyazResim); blobs = bc.GetObjectsInformation(); label2.Text = "Toplam Şekil Sayısı = " + bc.ObjectsCount.ToString(); toplamSekilSayisi = bc.ObjectsCount; /*aşağıdaki for döngüsü yerine buradaki koşul ifadesi kullanısaydı eğer, * resimdeki en büyük şekil bulunacaktı. * if (blobs.Length > 0) * { * bc.ExtractBlobsImage(siyahBeyazResim, blobs[0], true); * } * Bitmap xxx = blobs[0].Image.ToManagedImage(); */ //bütün şekiller bulunuyor for (int i = 0, n = blobs.Length; i < n; i++) { if (blobs.Length > 0) { bc.ExtractBlobsImage(siyahBeyazResim, blobs[i], true); pictureBox1.Image = siyahBeyazResim; pictureBox1.Refresh(); } } }
private void button3_Click(object sender, EventArgs e) { Bitmap kaynakResmi, filtreliResim; OtsuThreshold otsuFiltre = new OtsuThreshold(); kaynakResmi = KesilenResim; //orjinal resim gösteriliyor pictureBox2.Image = kaynakResmi; //resmi eğer renkliyse önce griye çeviriyor sonra filtre uyguluyor //resim zaten griyse direk filtre uyguluyor filtreliResim = otsuFiltre.Apply(kaynakResmi.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(kaynakResmi) : kaynakResmi); //filtre uygulanan resim gösteriliyor pictureBox3.Image = filtreliResim; //Uygulanan Threshold Değeri form başlığında görünüyor this.Text = "Threshold Değeri : " + otsuFiltre.ThresholdValue.ToString(); button1.Enabled = true; }
private void socketadd_Click(object sender, EventArgs e) { OpenFileDialog rs = new OpenFileDialog(); rs.Title = "Resim Seç"; rs.Filter = "(*.jpg)|*.jpg|(*.png)|*.png"; if (rs.ShowDialog() == DialogResult.OK) { this.pictureBox1.Image = new Bitmap(rs.OpenFile()); } sayac = 1; Bitmap kaynakResim = new Bitmap(pictureBox1.Image); //Otsu Threshold uygulandı OtsuThreshold otsuFiltre = new OtsuThreshold(); //resim eğer renkliyse önce griye çeviriyor sonra filtre uyguluyor //resim zaten griyse direk filtreyi uyguluyor siyahBeyazResim = otsuFiltre.Apply(kaynakResim.PixelFormat != PixelFormat.Format8bppIndexed ? Grayscale.CommonAlgorithms.BT709.Apply(kaynakResim) : kaynakResim); BlobCounterBase bc = new BlobCounter(); bc.FilterBlobs = true; bc.MinHeight = 5; bc.MinWidth = 5; bc.ProcessImage(siyahBeyazResim); blobs = bc.GetObjectsInformation(); for (int i = 0, n = blobs.Length; i < n; i++) { if (blobs.Length > 0) { bc.ExtractBlobsImage(siyahBeyazResim, blobs[i], true); pictureBox1.Image = siyahBeyazResim; pictureBox1.Refresh(); } } }