public Bitmap GrayScale(System.Drawing.Image imgOrigin) { Bitmap bmp = (Bitmap)imgOrigin.Clone(); Grayscale _filterGray = new Grayscale(0.2125, 0.7154, 0.0721); Threshold filter = new Threshold(100); //filter.ApplyInPlace(bmp); bmp = _filterGray.Apply(bmp); return(bmp); }
// The video_NewFrame used in the example above could be defined as: private void video_NewFrame2(object sender, NewFrameEventArgs eventArgs) { // get new frame Bitmap bitmap = eventArgs.Frame; // Apply the filter we have cached outside: Bitmap grayBitmap = grayscale.Apply(bitmap); // process the frame (you can do anything with it, such as running an // image processing filter, saving it to disk, showing on screen, etc) }
public Bitmap processImage(Bitmap img) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayimage = filter.Apply(img); Threshold th = new Threshold(); th.ApplyInPlace(grayimage); return(grayimage); }
private static Bitmap PreProcess(Bitmap bmp) { Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721); Invert ifilter = new Invert(); BradleyLocalThresholding thfilter = new BradleyLocalThresholding(); bmp = gfilter.Apply(bmp); thfilter.ApplyInPlace(bmp); ifilter.ApplyInPlace(bmp); return(bmp); }
public static BitmapImage MakeFFTMagnitude(Bitmap image) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter.Apply(image); ComplexImage compleximage = ComplexImage.FromBitmap(grayImage); compleximage.ForwardFourierTransform(); Bitmap fi = compleximage.ToBitmap(); return(ToBitmapImage(fi)); }
// source // http://stackoverflow.com/questions/35980717/why-doesnt-aforge-net-blobcounter-getobjectsinformation-detect-objects private Bitmap PreProcess(Bitmap bmp) { //Those are AForge filters "using Aforge.Imaging.Filters;" Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721); Invert ifilter = new Invert(); BradleyLocalThresholding thfilter = new BradleyLocalThresholding(); bmp = gfilter.Apply(bmp); thfilter.ApplyInPlace(bmp); ifilter.ApplyInPlace(bmp); return(bmp); }
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { Bitmap img = FilterResize.Apply((Bitmap)eventArgs.Frame.Clone()); pictureBox1.Image = (Bitmap)img.Clone(); Grayscale FilterGrayscale = new Grayscale(red, green, blue); img = FilterGrayscale.Apply((Bitmap)img.Clone()); pictureBox2.Image = (Bitmap)img.Clone(); SobelEdgeDetector FilterSobelEdgeDetector = new SobelEdgeDetector(); img = FilterSobelEdgeDetector.Apply((Bitmap)img.Clone()); pictureBox3.Image = (Bitmap)img.Clone(); pictureBox5.Image = (Bitmap)img.Clone(); pictureBox8.Image = (Bitmap)img.Clone(); if (mutex) { gest = (Bitmap)img.Clone(); mutex = false; pictureBox11.Image = (Bitmap)gest.Clone(); } float sim = 0; ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.5f); TemplateMatch[] matchings; Bitmap overlay = (Bitmap)img.Clone(); Add AddFilter = new Add(overlay); if (gest != null) { overlay = AddFilter.Apply((Bitmap)gest.Clone()); } pictureBox9.Image = (Bitmap)overlay.Clone(); matchings = tm.ProcessImage(img, overlay); if (matchings.Length > 0) { sim = matchings[0].Similarity; } this.label4.BeginInvoke((MethodInvoker)(() => this.label4.Text = Convert.ToString(sim))); }
//public void TranformImage(string outputFileName) //{ // /* // BaseUsingCopyPartialFilter[] detectors = new BaseUsingCopyPartialFilter[] // { // new HomogenityEdgeDetector(), // new CannyEdgeDetector(), // new DifferenceEdgeDetector(), // new SobelEdgeDetector() // }; // for (int i = 0; i < detectors.Length; i++) // { // BaseUsingCopyPartialFilter detector = detectors[i];*/ // //using (Bitmap newBmp = new Bitmap(image)) // List<IntPoint> corners; // using (Bitmap edgesBitmap = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format8bppIndexed)) // { // DifferenceEdgeDetector detector = new DifferenceEdgeDetector(); // detector.ApplyInPlace(edgesBitmap); // QuadrilateralFinder qf = new QuadrilateralFinder(); // corners = qf.ProcessImage(edgesBitmap); // // AdaptiveSmoothing filter = new AdaptiveSmoothing(); // //filter.ApplyInPlace(targetBmp); // //Threshold filter = new Threshold(100); // //filter.ApplyInPlace(targetBmp); // edgesBitmap.Save(@"D:\k\trash\CornersTest.jpg"); // //return; // } // //Invert invertFilter = new Invert(); // //Bitmap invertedImage = invertFilter.Apply(image); // //Bitmap edgesBitmap = new Bitmap(image); // //HomogenityEdgeDetector detector = new HomogenityEdgeDetector(); // //detector.ApplyInPlace(edgesBitmap); // int boundingSquareSideLength = GetBoundingSquareSideLength(corners); // QuadrilateralTransformation transformation = new QuadrilateralTransformation(corners, boundingSquareSideLength, boundingSquareSideLength); // Bitmap bmp2 = transformation.Apply(image); // Grayscale grayscale = new Grayscale(0.2125, 0.7154, 0.0721); // bmp2 = grayscale.Apply(bmp2); // //bmp2.Save(outputFileName); // //using (Bitmap bmp2 = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format16bppGrayScale)) // { // Threshold filter = new Threshold(220); // filter.ApplyInPlace(bmp2); // bmp2.Save(outputFileName); // } // //Bitmap newImage = transformation.Apply(image); // //newImage.Save(outputFileName); // //using (Graphics g = Graphics.FromImage(image)) // //{ // // int len = 2; // // foreach (IntPoint corner in corners) // // { // // image.SetPixel(corner.X, corner.Y, Color.White); // // //g. // // //g.FillEllipse(Brushes.Red, corner.X -len, corner.Y + len, corner.X + len, corner.Y - len); // // } // // //image.Save(@"D:\k\trash\CornersTest"+i+".jpg"); // //} // // } // //QuadrilateralTransformation transformation = new QuadrilateralTransformation(corners); // //QuadrilateralTransformation transformation = new QuadrilateralTransformation(corners, invertedImage.Width, invertedImage.Height); // //Bitmap newImage = transformation.Apply(image); // //newImage.Save(outputFileName); //} public static Bitmap ConvertToGreyscale(Bitmap bitmap) { Grayscale grayscale = new Grayscale(0.2125, 0.7154, 0.0721); if (bitmap.PixelFormat == PixelFormat.Format8bppIndexed) { return((Bitmap)(bitmap.Clone())); } return(grayscale.Apply(bitmap)); //return bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format8bppIndexed); }
/// <summary> /// 设置图片为黑白色 /// </summary> /// <param name="img"></param> /// <returns></returns> public static System.Drawing.Image BlackWhitePhoto(Bitmap map) { if (map.PixelFormat != PixelFormat.Format8bppIndexed) { var bitmap = ReplaceBackgroundColor(map, Color.White); Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721); bitmap = g.Apply(bitmap); BradleyLocalThresholding filter = new BradleyLocalThresholding(); filter.ApplyInPlace(bitmap); return(bitmap); } return(map); }
private Bitmap GetEdgedImage(WriteableBitmap writeableBitmap) { var edgeFilter = new CannyEdgeDetector(255, 0); var smoothFilter = new Median(); var grayFilter = new Grayscale(0.2125, 0.7154, 0.0721); var bitmap = (Bitmap)writeableBitmap; bitmap = grayFilter.Apply(bitmap); smoothFilter.ApplyInPlace(bitmap); edgeFilter.ApplyInPlace(bitmap); return(bitmap); }
public static Bitmap ConvertToGrayScale(this Bitmap sourceImage) { var filter = new Grayscale(0.2125, 0.7154, 0.0721); if (Image.IsGrayscale(sourceImage)) { return(sourceImage); } Bitmap converted = filter.Apply(sourceImage); return(converted); }
public static Bitmap ApplyPreProcessing(Bitmap image, int thresholdvalue) { Bitmap grayImage = image; if (!AForge.Imaging.Image.IsGrayscale(image)) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); grayImage = filter.Apply(image); } AForge.Imaging.Filters.Invert invert = new Invert(); AForge.Imaging.Filters.Threshold thresh_hold = new Threshold(thresholdvalue); image = invert.Apply(thresh_hold.Apply(grayImage)); return(image); }
public void Create(Bitmap img, string name) { Bitmap bmp = (Bitmap)img.Clone(); Grayscale FilterGrayscale = new Grayscale(Data.Red, Data.Green, Data.Blue); SobelEdgeDetector FilterSobelEdgeDetector = new SobelEdgeDetector(); bmp = FilterGrayscale.Apply(bmp); bmp = FilterSobelEdgeDetector.Apply(bmp); bmp.Save(Data.Path + "/" + name + ".jpg", ImageFormat.Jpeg); Gesture.Update_Base(); }
void kamera_ProsesFrame3(object sender, NewFrameEventArgs eventArgs) { frame = (Bitmap)eventArgs.Frame.Clone(); frame2 = (Bitmap)eventArgs.Frame.Clone(); pictureBox1.Image = frame; // create filter Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter.Apply(frame2); Threshold filter2 = new Threshold(100); // apply the filter pictureBox2.Image = filter2.Apply(grayImage); }
public Bitmap Filter(Bitmap input_image) { Grayscale gray_filter = new Grayscale(0.2125, 0.7154, 0.0721); BradleyLocalThresholding threshold_filter = new BradleyLocalThresholding(); threshold_filter.PixelBrightnessDifferenceLimit = 0.5f; ResizeBicubic scale_small_filter = new ResizeBicubic(28, 28); Crop crop_filter = new Crop(new Rectangle(51, 51, 199, 199)); BlobCounter blober = new BlobCounter(); blober.FilterBlobs = true; blober.ObjectsOrder = ObjectsOrder.Size; Bitmap image = gray_filter.Apply(input_image); image = threshold_filter.Apply(image); image = crop_filter.Apply(image); //blober.ProcessImage(image); //Blob[] blobs = blober.GetObjectsInformation(); //if (blobs.Length > 0) //{ // var bigger = blobs[0]; // UnmanagedImage img = UnmanagedImage.FromManagedImage(image); // blober.ExtractBlobsImage(img, bigger, false); // Accord.Point mc = bigger.CenterOfGravity; // Accord.Point ic = new Accord.Point((float)bigger.Image.Width / 2, (float)bigger.Image.Height / 2); // float AngleRad = (ic.Y - mc.Y) / (ic.X - mc.X); // float Angle = (float)(AngleRad * 180 / Math.PI); // image = img.ToManagedImage(); // RotateBicubic rot_filter = new RotateBicubic(Angle); // image = rot_filter.Apply(image); //} image = scale_small_filter.Apply(image); return(image); }
public static Bitmap Orient_Hough(Bitmap blob) { GC.Collect(); Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap documentImage = filter.Apply(blob); //Bitmap documentImage = AForge.Imaging.Image.Clone(blob, PixelFormat.Format16bppGrayScale); //force the jpgs // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = skewChecker.GetSkewAngle(documentImage); // rotate image applying the filter return(RotateImg(blob, (int)-angle, Color.Transparent)); }
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)); }
public Bitmap FindTextBitmap() { Bitmap textBmp = new Bitmap(sets.BmpTextWidth, sets.BmpTextHeight); textBmp = sourceImage.Clone(new Rectangle(match.X + sets.TextMarginRight, match.Y + sets.TextMarginTop, sets.BmpTextWidth, sets.BmpTextHeight), PixelFormat.Format24bppRgb); Grayscale gs = new Grayscale(0.2125, 0.7154, 0.0721); SISThreshold th = new SISThreshold(); BinaryErosion3x3 bs = new BinaryErosion3x3(); ColorFiltering cf = new ColorFiltering(); cf.Red = new IntRange(90, 160); cf.Green = new IntRange(55, 110); cf.Blue = new IntRange(15, 85); cf.ApplyInPlace(textBmp); //for (int i = 0; i < textBmp.Width; i++) //{ // for (int j = 0; j < textBmp.Height; j++) // { // if (((textBmp.GetPixel(i, j).R > 95) && (textBmp.GetPixel(i, j).R < 155)) && ((textBmp.GetPixel(i, j).G > 60) && (textBmp.GetPixel(i, j).G > 105)) && ((textBmp.GetPixel(i, j).B > 20 && (textBmp.GetPixel(i, j).B < 80)))) // { // textBmp.SetPixel(i, j, Color.Black); // } // else // { // textBmp.SetPixel(i, j, Color.White); // } // } //} BilateralSmoothing bss = new BilateralSmoothing(); bss.KernelSize = 7; bss.SpatialFactor = 5; bss.ColorFactor = 30; bss.ColorPower = 0.5; bss.ApplyInPlace(textBmp); textBmp = gs.Apply(textBmp); th.ApplyInPlace(textBmp); //bs.ApplyInPlace(textBmp); //erose.ApplyInPlace(textBmp); return(textBmp); }
public void ProcessImage(Bitmap input_image) { lock (balanceLock) { int side = Math.Min(input_image.Height, input_image.Width); Rectangle cropRect = new Rectangle(0, 0, side, side); // this is square that represents feed from camera g.DrawImage(input_image, new Rectangle(0, 0, input_image.Width, input_image.Height), cropRect, GraphicsUnit.Pixel); // place it on original bitmap // set new processed if (processed != null) { processed.Dispose(); } // Конвертируем изображение в градации серого processed = grayFilter.Apply(AForge.Imaging.UnmanagedImage.FromManagedImage(original)); // Пороговый фильтр применяем. Величина порога берётся из настроек, и меняется на форме threshldFilter.PixelBrightnessDifferenceLimit = ThresholdValue; threshldFilter.ApplyInPlace(processed); InvertFilter.ApplyInPlace(processed); Blober.ProcessImage(processed); AForge.Imaging.Blob[] blobs = Blober.GetObjectsInformation(); BlobCount = blobs.Length; if (blobs.Length > 0) { var BiggestBlob = blobs[0]; Recongnised = true; Blober.ExtractBlobsImage(processed, BiggestBlob, false); processed = BiggestBlob.Image; AForge.Point mc = BiggestBlob.CenterOfGravity; AForge.Point ic = new AForge.Point((float)BiggestBlob.Image.Width / 2, (float)BiggestBlob.Image.Height / 2); AngleRad = (ic.Y - mc.Y) / (ic.X - mc.X); Angle = (float)(Math.Atan(AngleRad) * 180 / Math.PI); } else { // TODO make arrengaments for No blobs case Recongnised = false; Angle = 0; AngleRad = -1; } if (number != null) { number.Dispose(); } number = processed.ToManagedImage(); } }
private void segmentTextToolStripMenuItem_Click(object sender, EventArgs e) { IOperation operation = new Grayscale(); m_image = operation.Apply(m_image); operation = new IncreaseContrast(); m_image = operation.Apply(m_image); operation = new LocalThreshold(10, 10); m_image = operation.Apply(m_image); pictureBox1.Image = m_image.ExportBitmap(); }
public void applyfilter1(IFilter filter) { try { Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721); image = g.Apply(image); Bitmap newImage = filter.Apply(image); pictureBox2.Image = newImage; } catch (ArgumentException) { MessageBox.Show("Selected filter can not be applied to the image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void edgeDetect(ushort j) { cvsbmp = UtilFn.BitmapImage2Bitmap(images[j]); Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = gfilter.Apply(cvsbmp); GaborFilter filter = new GaborFilter(); Bitmap output = filter.Apply(grayImage); imagesEdited.Add(converter.Convert(output, Type.GetType("BitmapImage"), null, null) as BitmapImage); }
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; }
private void ProcessImage() { m_selectedBlobs.Clear(); pictureBox1.Controls.Clear(); pictureBox1.Image = null; if (m_original != null) { m_original.Dispose(); } if (m_binarized != null) { m_binarized.Dispose(); } m_original = new Bitmap(txtFile.Text); // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); m_binarized = filter.Apply(m_original); // Binarize Picture. Threshold bin = new Threshold((int)txtBinThershold.Value); bin.ApplyInPlace(m_binarized); // create filter Invert inv = new Invert(); inv.ApplyInPlace(m_binarized); // create an instance of blob counter algorithm BlobCounter bc = new BlobCounter(); bc.ObjectsOrder = ObjectsOrder.XY; bc.ProcessImage(m_binarized); Rectangle[] blobsRect = bc.GetObjectsRectangles(); Dictionary <int, List <Rectangle> > orderedBlobs = ReorderBlobs(blobsRect); foreach (KeyValuePair <int, List <Rectangle> > orderedBlob in orderedBlobs) { orderedBlob.Value.ForEach(r => AddBlobPanel(orderedBlob.Key, r)); } pictureBox1.Image = chkShowBinarize.Checked ? m_binarized : m_original; pictureBox1.Invalidate(); }
void FinalFrame_NewFrame(object sender, NewFrameEventArgs eventArgs) { video = (Bitmap)eventArgs.Frame.Clone(); Bitmap video2 = (Bitmap)eventArgs.Frame.Clone(); if (mode == 1) { Grayscale gray = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap video3 = gray.Apply(video2); CannyEdgeDetector canny = new CannyEdgeDetector(0, 70); canny.ApplyInPlace(video3); pictureBox2.Image = video3; } pictureBox1.Image = video; }
/// <summary> /// Get binarized image /// </summary> public System.Drawing.Image GetBinarizedImage() { if (this.m_disposed) { throw new ObjectDisposedException("ImageProcessor"); } if (!this.IsScannable) { throw new InvalidOperationException("Form doesn't have sufficient control information to perform this operation"); } Grayscale grayFilter = new Grayscale(255, 255, 255); return(grayFilter.Apply(this.m_bitmap)); }
void GrayscaleToolStripMenuItemClick(object sender, EventArgs e) { //jika gambar kosong/null maka akan mengembalikan nilai kosong/null if (gambar == null) { return; } //membuat filter dari inisiasi class Grayscale() dengan 3 argumen pada objek grayscale Grayscale grayscale = new Grayscale(0.2125, 0.7154, 0.0721); //aplikasikan filter objek grayscale pada gambar lalu diinisiasi ke gambar2 gambar2 = grayscale.Apply(gambar); //tampilkan hasil gambar2 yang sudah diaplikasikan filter pada pictureBox2 pictureBox2.Image = gambar2; }
private void imageLoad_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog { Filter = "Pliki graficzne|*.bmp; *.png; *.jpg; *.gif; *.jpeg" }; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { Bitmap b = new Bitmap(dlg.FileName); Grayscale filterG = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = b; if (b.PixelFormat != PixelFormat.Format8bppIndexed) { grayImage = filterG.Apply(b); IterativeThreshold filter = new IterativeThreshold(2, 128); filter.ApplyInPlace(grayImage); } image.Source = BitmapToImageSource(grayImage); var path = Path.GetDirectoryName(dlg.FileName); var filename = Path.GetFileNameWithoutExtension(dlg.FileName); var extension = Path.GetExtension(dlg.FileName); imageFileName = new string[] { path, filename, extension }; Bitmap[] shares = null; if (twoPixels.IsChecked == true) { shares = twoPixelsF(grayImage); } else if (fourPixels.IsChecked == true) { shares = fourPixelsF(grayImage); } else { showAlert("Nieoczekiwany błąd. Pole obok nie zostało zaznaczone."); } showAlert("Udziały zostały automatycznie zapisane w folderze: " + imageFileName[0]); if (shares != null) { firstShare.Source = BitmapToImageSource(shares[0]); secondShare.Source = BitmapToImageSource(shares[1]); } } }
public Bitmap GreyImage(Bitmap bmp) { try { // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter Bitmap greyedImage = filter.Apply(bmp); return(greyedImage); } catch (AForge.Imaging.UnsupportedImageFormatException) { return(bmp); } }
private WriteableBitmap FindPlate(IEnumerable <Rect> rects, WriteableBitmap image) { WriteableBitmap bestCandidate = null; foreach (var rect in rects) { var croppedImage = image.Crop(rect); var edgeFilter = new CannyEdgeDetector(); var smoothFilter = new Median(); var grayFilter = new Grayscale(0.2125, 0.7154, 0.0721); var blobCounter = new BlobCounter(); var cutTop = croppedImage.PixelHeight * 0.3; croppedImage = croppedImage.Crop(new Rect(0, cutTop, croppedImage.PixelWidth, croppedImage.PixelHeight)); var bitmap = (Bitmap)croppedImage; var grayImage = grayFilter.Apply(bitmap); bitmap = smoothFilter.Apply(grayImage); edgeFilter.ApplyInPlace(bitmap); blobCounter.ProcessImage(bitmap); var blobs = blobCounter.GetObjectsInformation(); var possibleChars = new List <Rectangle>(); foreach (var blob in blobs) { var objRectangle = blob.Rectangle; var ratio = (double)objRectangle.Height / (double)objRectangle.Width; if (ratio >= 1.16d && ratio <= 6.3d) { possibleChars.Add(objRectangle); } } if (possibleChars.Count == 0) { continue; } bestCandidate = croppedImage; } return(bestCandidate); }