public Bitmap FiltroMedia(int n) { Median media = new Median(n); imagen = media.Apply(imagen); return(imagen); }
private void btnOperation(object sender, RoutedEventArgs e) { var master = sender as System.Windows.Controls.Button; switch (master.Name) { case ("btnThreshold"): var parmTh = (int)nudThreshold.Value; SrcMImg = SrcMImg.Add(Threshold.Apply(parmTh), StrThreshold.With(parmTh)); break; case ("btnAdpThreshold"): var parmAdTh = (int)nudAdpThreshold.Value; SrcMImg = SrcMImg.Add(AdpTHreshold.Apply(parmAdTh), StrAdpTHreashold.With(parmAdTh)); break; case ("btnMedian"): var parmMdn = (int)nudMedian.Value; SrcMImg = SrcMImg.Add(Median.Apply(parmMdn), StrMedian.With(parmMdn)); break; case ("btnNormalize"): var parmNorm = (int)nudNormalize.Value; SrcMImg = SrcMImg.Add(Normalize.Apply(parmNorm), StrNormalize.With(parmNorm)); break; } imgBack.Source = ToBitmapSource(SrcMImg.GetLastValue()); txbLog.Selection.Text = SrcMImg.GetLastPaper().Paper2TextHistory(); var temp = SrcMImg.GetLastPaper().Paper2TextHistory(); }
public Bitmap ToMedian(Bitmap Im) { AForge.Imaging.Filters.Median Img = new Median(); Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb); return(Img.Apply(bmImage)); }
public string decodeBitmap(Bitmap img) { /////////图像处理 //转为灰度图 Grayscale grayscaleFilter = new Grayscale(0.299, 0.587, 0.114); Bitmap bitmapGrayscale = grayscaleFilter.Apply(img); //二值化 Threshold thresholdFilter = new Threshold(128); Bitmap bitmapThreshold = thresholdFilter.Apply(bitmapGrayscale); ////////中值滤波 Median mediafil = new Median(); Bitmap medianBit = mediafil.Apply(bitmapThreshold); //锐化 Sharpen sharpPic = new Sharpen(); Bitmap sharpOut = sharpPic.Apply(medianBit); //统计点数 HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(sharpOut); Histogram histogram = his.Gray; int[] dato = histogram.Values; /////分割图像 charCut(dato); shunfengdecoder decode = new shunfengdecoder(); string backcode = decode.Decoder(sharpOut, div); return(backcode); }
public static Maybe <ProcFuncs> ConvertToPreProFunc(ProcRecipe src) { var name = src.Item1; var strparm = src.Item2; int parameter; if (!Int32.TryParse(strparm, out parameter)) { return(None); } switch (name) { case keyThreshold: return(Threshold.Apply(parameter)); case keyNormalize: return(Normalize.Apply(parameter)); case keyAdpThreshold: return(AdpThreshold.Apply(parameter)); case keyMedian: return(Median.Apply(parameter)); default: return(None); } }
public static Bitmap Median(Bitmap Imagem) { Median filter = new Median(); Imagem = Imagem.Clone(new Rectangle(0, 0, Imagem.Width, Imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb); Imagem = filter.Apply(Imagem); return(Imagem); }
//------------------------------------------------------------- private void process_imginput(Bitmap img, String Plate_Type) { //grayscale IFilter way_filt;//= new GrayscaleY(); //process_image = way_filt.Apply(img); //resize if (Plate_Type == "1hang") { way_filt = new ResizeBilinear(600, 120); //bien 1 hang } else { way_filt = new ResizeBilinear(300, 200); //bien 2 hang } process_image = way_filt.Apply(img); //process_image = get_plate(process_image, 10, 210, 30, 330); input_image = way_filt.Apply(input_image); p = process_image; //threshold way_filt = new Threshold(125); process_image = way_filt.Apply(process_image); //K-means process_image = kmean(process_image); //invert way_filt = new Invert(); process_image = way_filt.Apply(process_image); //liembt //UCM way_filt = new Median(); process_image = way_filt.Apply(process_image); //way_filt = new AdaptiveSmooth(); //process_image = way_filt.Apply(process_image); //end liembt //filter k BlobsFiltering filter = new BlobsFiltering(); filter.MinHeight = 25;//50 filter.MinWidth = 10; filter.MaxHeight = 100; filter.ApplyInPlace(process_image); //p = process_image; input_width = process_image.Width; input_height = process_image.Height; }
public void TratarImagem() { var imagemParaTratamento = Grayscale.CommonAlgorithms.BT709.Apply(captchaAntes); Median medianFilter = new Median(); try { captchaDepois = medianFilter.Apply(imagemParaTratamento); } catch (Exception ex) { Console.WriteLine($"Erro! {ex.Message}"); } }
private void QRWorkerMethod(object sender, CertificateScanner.WaiteWindow.WaitWindowEventArgs e) { try { var sourceimg = (Bitmap)e.Arguments[0]; ContrastStretch filter = new ContrastStretch(); sourceimg = filter.Apply(sourceimg); sourceimg = filter.Apply(sourceimg); sourceimg = filter.Apply(sourceimg); Median f1 = new Median(); sourceimg = f1.Apply(sourceimg); sourceimg = f1.Apply(sourceimg); sourceimg = f1.Apply(sourceimg); Blur filter2 = new Blur(); sourceimg = filter2.Apply(sourceimg); sourceimg = filter2.Apply(sourceimg); //sourceimg.Save("d:\\tst.jpg", ImageFormat.Jpeg); //System.Diagnostics.Process.Start("d:\\tst.jpg"); com.google.zxing.LuminanceSource source = new RGBLuminanceSource(sourceimg, sourceimg.Width, sourceimg.Height); com.google.zxing.Binarizer binarizer = new com.google.zxing.common.HybridBinarizer(source); com.google.zxing.qrcode.QRCodeReader reader = new com.google.zxing.qrcode.QRCodeReader(); var result = reader.decode(new com.google.zxing.BinaryBitmap(binarizer)); e.Result = result.Text; } catch (Exception ex) { e.Result = "12323123213123"; this.Warn(ex, this.Messages("qrFail")); } }
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); }
public void MedianClickHandler(object sender, EventArgs e) { if (image != null) { Bitmap img = new Bitmap(path); Median filter = new Median(); img = filter.Apply(img); //ImageEView if (mov != null) { this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Close(mov); } mov = this.WorkItem.SmartParts.AddNew <ImageEView>(); mov.panAndZoomPictureBox1.Image = img; SmartPartInfo spi = new SmartPartInfo("Median", "MyOwnDescription"); this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Show(mov, spi); } }
public override Bitmap ApplyFilter(List <Bitmap> bitmap) { Median filter = new Median(Size); return(filter.Apply(bitmap[0])); }
private void cBFilters_SelectedIndexChanged(object sender, EventArgs e) { Bitmap pictureTransform = (Bitmap)pbChoose.Image; if ((string)cBFilters.SelectedItem == "HSL_Filter") { AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Mediana") { AForge.Imaging.Filters.Median filter = new Median(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation") * { * Complex[] dst = new Complex[n]; * * AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform); * Bitmap newImage = filter.Apply(); * pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; * pBNew.Image = newImage; * }*/ if ((string)cBFilters.SelectedItem == "Binarization") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = pictureTransform; } if ((string)cBFilters.SelectedItem == "Grayscale") { AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "FillHoles") { pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform); Threshold threshold = new Threshold(127); threshold.ApplyInPlace(pictureTransform); AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles(); filter.MaxHoleHeight = 5; filter.MaxHoleWidth = 15; filter.CoupledSizeFiltering = false; Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Opening") { AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Closing") { AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Erosion") { AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Dilatation") { AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } if ((string)cBFilters.SelectedItem == "Edges") { AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges(); Bitmap newImage = filter.Apply(pictureTransform); pbChoose.SizeMode = PictureBoxSizeMode.CenterImage; pBNew.Image = newImage; } }
public static Bitmap FilterImage(Bitmap img, int filter) { Bitmap sourceImage = img; sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); IFilter myFilter; Bitmap filteredImage = sourceImage; if (filter == Filters.filters["Greyscale"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); filteredImage = sourceImage; } else if (filter == Filters.filters["Sepia"]) { myFilter = new Sepia(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Invert"]) { sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Invert(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["RotateChannel"]) { myFilter = new RotateChannels(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Threshold"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new Threshold(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["FloydFilter"]) { FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering(); filteredImage = myReduction.Apply(sourceImage); } else if (filter == Filters.filters["OrderedDithering"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new OrderedDithering(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Sharpen"]) { myFilter = new Sharpen(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["DifferenceEdgeDetector"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new DifferenceEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["HomogenityEdgeDetector"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new HomogenityEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Sobel"]) { sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new SobelEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Jitter"]) { myFilter = new Jitter(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["OilPainting"]) { sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new OilPainting(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["TextureFiltering"]) { sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Median"]) { sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Median(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Mean"]) { myFilter = new Mean(); filteredImage = myFilter.Apply(sourceImage); } else if (filter == Filters.filters["Blur"]) { myFilter = new GaussianBlur(); filteredImage = myFilter.Apply(sourceImage); } //Console.Write(filteredImage.PixelFormat.ToString()); //Console.Write(sourceImage.PixelFormat.ToString()); filteredImage = ImageUtil.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); return(filteredImage); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { Bitmap sourceImage = null; DA.GetData(0, ref sourceImage); string filter = ""; DA.GetData(1, ref filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); IFilter myFilter; Bitmap filteredImage = sourceImage; //Grayscale.CommonAlgorithms.Y.Apply switch (filter) { case "Greyscale": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); filteredImage = sourceImage; break; case "Sepia": Console.Write("Applying: " + filter); myFilter = new Sepia(); filteredImage = myFilter.Apply(sourceImage); break; case "Invert": Console.Write("Applying: " + filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Invert(); filteredImage = myFilter.Apply(sourceImage); break; case "RotateChannel": Console.Write("Applying: " + filter); myFilter = new RotateChannels(); filteredImage = myFilter.Apply(sourceImage); break; case "Threshold": //Need Extended Version Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new Threshold(); filteredImage = myFilter.Apply(sourceImage); break; case "FloydFilter": Console.Write("Applying: " + filter); //sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); //myFilter = new FloydSteinbergColorDithering(); FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering(); filteredImage = myReduction.Apply(sourceImage); //filteredImage = myFilter.Apply(sourceImage); break; case "OrderedDithering": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new OrderedDithering(); filteredImage = myFilter.Apply(sourceImage); break; case "Sharpen": Console.Write("Applying: " + filter); myFilter = new Sharpen(); filteredImage = myFilter.Apply(sourceImage); break; case "DifferenceEdgeDetector": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new DifferenceEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "HomogenityEdgeDetector": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new HomogenityEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "Sobel": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new SobelEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "Jitter": Console.Write("Applying: " + filter); myFilter = new Jitter(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "OilPainting": Console.Write("Applying: " + filter); myFilter = new OilPainting(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "TextureFiltering": Console.Write("Applying: " + filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "Median": Console.Write("Applying: " + filter); myFilter = new Median(); filteredImage = myFilter.Apply(sourceImage); break; case "Mean": Console.Write("Applying: " + filter); myFilter = new Mean(); filteredImage = myFilter.Apply(sourceImage); break; case "Blur": //Need Extended Version Console.Write("Applying: " + filter); myFilter = new GaussianBlur(); filteredImage = myFilter.Apply(sourceImage); break; default: Console.Write("No Filter"); break; } Console.Write(filteredImage.PixelFormat.ToString()); Console.Write(sourceImage.PixelFormat.ToString()); filteredImage = ImageUtilities.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); DA.SetData(0, filteredImage); }
static void Main(string[] args) { try { blacklist = new List <string>(); cache = new Dictionary <string, Rate>(); sb = new StringBuilder(); Thread thr = new Thread(() => { while (true) { try { File.WriteAllText("OCROUTPUT.csv", sb.ToString()); Thread.Sleep(20000); }catch (Exception e) { Console.WriteLine("Periodic write failed. {0}", e); Thread.Sleep(20000); } } }) { IsBackground = true }; thr.Start(); sb.Append("Heart Rate,Video ID,Game"); using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) { engine.DefaultPageSegMode = PageSegMode.SingleWord; foreach (FileInfo fi in new DirectoryInfo(@"D:\New folder (5)\videos").GetFiles("*.png", SearchOption.AllDirectories)) { try { Rate r = GetVideoInfo(fi.Directory.Name); r.VideoID = fi.Directory.Name; using (Image i = Image.FromFile(fi.FullName)) using (Bitmap og = new Bitmap(i, i.Width * 2, i.Height * 2)) using (Bitmap grays = SetGrayscale(og)) { Median m = new Median(6); using (Bitmap denoised = m.Apply(grays)) { using (var proc = engine.Process(denoised)) r.HeartRate = proc.GetText(); } } string s = $"{r.HeartRate.Replace(" ", "").Replace("\n", "").Replace("\r", "")},{r.VideoID},{r.Game}"; sb.AppendLine(s); } catch (Exception e) { Console.WriteLine("Inner loop error: {0}", e); } } } File.WriteAllText("OCROUTPUT.csv", sb.ToString()); Console.WriteLine("done"); foreach (string s in blacklist) { Console.WriteLine(s); } Console.ReadLine(); }catch (Exception e) { File.WriteAllText("OCROUTPUT.csv", sb.ToString()); Console.WriteLine("Outer error: {0}", e); Console.WriteLine("file written"); Console.ReadLine(); } }
private Bitmap ReduceNoise(Bitmap image) { var median = new Median(); return(median.Apply(image)); }
private void buttonMedian_Click(object sender, EventArgs e) { median = new Median(3); pictureBoxOutput.Image = median.Apply(AForge.Imaging.Image.Clone((Bitmap)pictureBoxOutput.Image, PixelFormat.Format24bppRgb)); }
public static Bitmap ApplyMedDenoisingFilter(Bitmap input) { Median medianDeNoisingFilter = new Median(); return(medianDeNoisingFilter.Apply(input)); }
public Bitmap MeanFilter(Bitmap img) { Median filter = new Median(); return(filter.Apply(img)); }