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; } }
private Bitmap preProcessImage(Bitmap image, Grayscale gScale, SobelEdgeDetector sEgDetector, SimplePosterization posterization) { Bitmap temp = image; temp = gScale.Apply(temp); posterization.ApplyInPlace(temp); return temp; }
private void grayscaleButton_Click(object sender, RoutedEventArgs e) { Bitmap temp = Compatibility.Compatibility.BitmapImageToBitmap((BitmapImage)image1.Source.Clone()); // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter grayImage = filter.Apply(temp); bi = Compatibility.Compatibility.BitmapToBitmapImage(grayImage); image1.Source = bi; }
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; }
private Bitmap filter() { Bitmap filtered_image; AForge.Imaging.Filters.Grayscale gr = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721); AForge.Imaging.Filters.Threshold th = new AForge.Imaging.Filters.Threshold(100); AForge.Imaging.Filters.Invert invert = new AForge.Imaging.Filters.Invert(); filtered_image = gr.Apply(scanned_image); filtered_image = invert.Apply(filtered_image); filtered_image = th.Apply(filtered_image); return filtered_image; }
private Bitmap filter() { Bitmap filtered_image; AForge.Imaging.Filters.Grayscale gr = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721); AForge.Imaging.Filters.Threshold th = new AForge.Imaging.Filters.Threshold(100); AForge.Imaging.Filters.Invert invert = new AForge.Imaging.Filters.Invert(); filtered_image = gr.Apply(scanned_image); filtered_image = invert.Apply(filtered_image); filtered_image = th.Apply(filtered_image); return(filtered_image); }
public static Bitmap DoIt(Bitmap bmp) { GaussianBlur blur = new GaussianBlur(10, 50); Bitmap blurred = blur.Apply(bmp); Bitmap ret = new Bitmap(blurred.Width, blurred.Height, blurred.PixelFormat); for (int y = 0; y < blurred.Height; y++) { for (int x = 0; x < blurred.Width; x++) { Color blurredColor = blurred.GetPixel(x, y); Color orinalColor = bmp.GetPixel(x, y); Color newColor = Color.FromArgb((blurredColor.R + orinalColor.R * 2) / 3, (blurredColor.G + orinalColor.G * 2) / 3, (blurredColor.B + orinalColor.B * 2) / 3); ret.SetPixel(x, y, newColor); } } GammaCorrection gc = new GammaCorrection(.8); gc.ApplyInPlace(ret); Sharpen sharpen = new Sharpen(); sharpen.ApplyInPlace(ret); Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap gray = filter.Apply(ret); CannyEdgeDetector canny = new CannyEdgeDetector(); gray = canny.Apply(gray); for (int y = 0; y < gray.Height; y++) { for (int x=0;x < gray.Width; x++) { if(gray.GetPixel(x,y).R > 0) { Color retColor = ret.GetPixel(x, y); Color newColor = Color.FromArgb( (int)(retColor.R * .7), (int)(retColor.G * .7), (int)(retColor.B * .7)); ret.SetPixel(x, y, newColor); } } } return ret; }
public static Bitmap EscalaGrises(Bitmap image) { try { AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.30, 0.59, 0.11); System.Drawing.Bitmap newImage = filter.Apply(image); return(newImage); } catch (ArgumentException ex) { MessageBox.Show("No se puede apllicar el filtro" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private void initiateButton_Click(object sender, RoutedEventArgs e) { // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter img1 = filter.Apply(img1); img2 = filter.Apply(img2); Stopwatch st = new Stopwatch(); st.Start(); // collect reference points using corners detector (for example) SusanCornersDetector scd = new SusanCornersDetector(30, 18); List<IntPoint> points = scd.ProcessImage(img1); // create block matching algorithm's instance ExhaustiveBlockMatching bm = new ExhaustiveBlockMatching(12, 36); // process images searching for block matchings List<BlockMatch> matches = bm.ProcessImage(img1, points, img2); st.Stop(); TimeSpan elapsed = st.Elapsed; timedisp.Text = "Elapsed time = " + elapsed.ToString(); // draw displacement vectors BitmapData data = img1.LockBits( new System.Drawing.Rectangle(0, 0, img1.Width, img1.Height), ImageLockMode.ReadWrite, img1.PixelFormat); foreach (BlockMatch match in matches) { // highlight the original point in source image AForge.Imaging.Drawing.FillRectangle(data, new System.Drawing.Rectangle(match.SourcePoint.X - 1, match.SourcePoint.Y - 1, 3, 3), System.Drawing.Color.Yellow); // draw line to the point in search image AForge.Imaging.Drawing.Line(data, match.SourcePoint, match.MatchPoint, System.Drawing.Color.Red); // check similarity if (match.Similarity > 0.98f) { // process block with high similarity } } img1.UnlockBits(data); bi = Compatibility.Compatibility.BitmapToBitmapImage(img1); image1.Source = bi; }
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 bool applyGrayscale() { if (currentImage != null) { try { // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter currentImage = filter.Apply(currentImage); return true; } catch (Exception) { } } return false; }
/// <summary> /// processes Frame for Motion Detection based on background generation /// </summary> /// <param name="frame"> /// Takes in 2 Bitmap parameters, currentFrame and backgroundFrame /// </param> /// <returns> /// frame in which motion is marked /// </returns> public Bitmap processFrame(params Bitmap[] frame) { Bitmap currentFrame = frame[0]; // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap GScurrentFrame = filter.Apply(currentFrame); if (this.backgroundFrame == null) { this.backgroundFrame = (Bitmap)GScurrentFrame.Clone(); GScurrentFrame.Dispose(); return currentFrame; } else { Morph filterx = new Morph(GScurrentFrame); filterx.SourcePercent = 0.75; Bitmap tmp = filterx.Apply(backgroundFrame); // dispose old background backgroundFrame.Dispose(); backgroundFrame = tmp; // create processing filters sequence FiltersSequence processingFilter = new FiltersSequence(); processingFilter.Add(new Difference(backgroundFrame)); processingFilter.Add(new Threshold(threshold_val)); processingFilter.Add(new Opening()); processingFilter.Add(new Edges()); // apply the filter Bitmap tmp1 = processingFilter.Apply(GScurrentFrame); IFilter extractChannel = new ExtractChannel(RGB.R); Bitmap redChannel = extractChannel.Apply(currentFrame); Merge mergeFilter = new Merge(); mergeFilter.OverlayImage = tmp1; Bitmap t3 = mergeFilter.Apply(redChannel); ReplaceChannel rc = new ReplaceChannel(RGB.R, t3); t3 = rc.Apply(currentFrame); redChannel.Dispose(); tmp1.Dispose(); GScurrentFrame.Dispose(); return t3; } }
public double GetTemperature() { var temp = 0.0; var image = Image.FromFile(filename); var grayscale = new Grayscale(0.2125, 0.7154, 0.0721); image = grayscale.Apply(image); var invert = new Invert(); image = invert.Apply(image); var stats = new ImageStatistics(image); var levelsLinear = new LevelsLinear { InGray = stats.Gray.GetRange(2.90) }; image = levelsLinear.Apply(image); var contrast = new ContrastStretch(); image = contrast.Apply(image); var erosion = new Erosion(); image = erosion.Apply(image); var blur = new GaussianBlur(2, 3); image = blur.Apply(image); var threshold = new Threshold(79); image = threshold.Apply(image); image.Save(processedFileName, System.Drawing.Imaging.ImageFormat.Jpeg); image.Dispose(); var text = Recognise(); double.TryParse(text.Replace(',', '.'), out temp); return temp; }
/// <summary> /// processes Frame for Motion Detection based on frame comparison /// </summary> /// <param name="frame"> /// Takes in 2 Bitmap parameters, currentFrame and backgroundFrame /// </param> /// <returns> /// frame in which motion is marked /// </returns> public Bitmap processFrame(params Bitmap[] frame) { Bitmap currentFrame = frame[0]; // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap GScurrentFrame = filter.Apply(currentFrame); if (this.backgroundFrame == null) { this.backgroundFrame = (Bitmap)GScurrentFrame.Clone(); GScurrentFrame.Dispose(); return currentFrame; } else { Difference differenceFilter = new Difference(); IFilter thresholdFilter = new Threshold(15); // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = backgroundFrame; Bitmap tmp = thresholdFilter.Apply(differenceFilter.Apply(GScurrentFrame)); //reduce noise IFilter erosionFilter = new Erosion(); Bitmap tmp1 = erosionFilter.Apply(tmp); tmp.Dispose(); // Highlight Motions IFilter extractChannel = new ExtractChannel(RGB.G); Bitmap redChannel = extractChannel.Apply(currentFrame); Merge mergeFilter = new Merge(); mergeFilter.OverlayImage = tmp1; Bitmap t3 = mergeFilter.Apply(redChannel); ReplaceChannel rc = new ReplaceChannel(RGB.G, t3); t3 = rc.Apply(currentFrame); this.backgroundFrame = (Bitmap)GScurrentFrame.Clone(); redChannel.Dispose(); tmp1.Dispose(); GScurrentFrame.Dispose(); return t3; } }
public void Dilatate() { var se = new short[,] { {1, 1, 1}, {1, 1, 1}, {1, 1, 1} }; Grayscale grayScaler = new Grayscale(0.2125, 0.7154, 0.0721); Dilatation dilatationFilter = new Dilatation(se); _digit = dilatationFilter.Apply(grayScaler.Apply(new Bitmap(_digit))); }
public void ClosingMorfology() { Grayscale grayScaler = new Grayscale(0.2125, 0.7154, 0.0721); Closing closingFilter = new Closing(); _digit = closingFilter.Apply(grayScaler.Apply(new Bitmap(_digit))); }
public Histogram DigitHistogram() { Grayscale grayScaler = new Grayscale(0.2125, 0.7154, 0.0721); ImageStatistics stat = new ImageStatistics(grayScaler.Apply(new Bitmap(_digit))); return stat.Gray; }
public static System.Drawing.Image AforgeAutoCrop(Bitmap selectedImage, DetectBorderParam param) { // 一些参数的默认值 if (param.MinObjectWidth == 0) param.MinObjectWidth = 500; if (param.MinObjectHeight == 0) param.MinObjectHeight = 500; Bitmap autoCropImage = null; try { autoCropImage = selectedImage; // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter.Apply(autoCropImage); // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = skewChecker.GetSkewAngle(grayImage); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(grayImage); new ContrastStretch().ApplyInPlace(rotatedImage); new Threshold(100).ApplyInPlace(rotatedImage); BlobCounter bc = new BlobCounter(); bc.FilterBlobs = true; bc.MinWidth = param.MinObjectWidth; // 500; bc.MinHeight = param.MinObjectHeight; // 500; bc.ProcessImage(rotatedImage); Rectangle[] rects = bc.GetObjectsRectangles(); if (rects.Length == 0) { System.Windows.Forms.MessageBox.Show("No rectangle found in image "); } else if (rects.Length == 1) { autoCropImage = rotatedImage.Clone(rects[0], rotatedImage.PixelFormat); } else if (rects.Length > 1) { // get largets rect Console.WriteLine("Using largest rectangle found in image "); var r2 = rects.OrderByDescending(r => r.Height * r.Width).ToList(); autoCropImage = rotatedImage.Clone(r2[1], rotatedImage.PixelFormat); } else { Console.WriteLine("Huh? on image "); } } catch (Exception ex) { // MessageBox.Show(ex.Message); throw ex; } return autoCropImage; }
// ========================================================= Contrast_scretchFunc private void GrayscaleFunc(ref Bitmap frame, int par_int, double par_d, int par_R, int par_G, int par_B) { Grayscale toGrFilter = new Grayscale(0.2125, 0.7154, 0.0721); // create grayscale MirrFilter (BT709) Bitmap fr = toGrFilter.Apply(frame); GrayscaleToRGB toColFilter = new GrayscaleToRGB(); frame = toColFilter.Apply(fr); }
public static Image ToGrayScale(Image img) { var filterGreyScale = new Grayscale(0.2125, 0.7154, 0.0721); return filterGreyScale.Apply((Bitmap)img); }
public virtual void GetLiveImage() { if (_operInProgress) { // Log.Error("OperInProgress"); return; } if (DelayedStart) { //Log.Error("Start is delayed"); return; } if (FreezeImage) return; _operInProgress = true; _totalframes++; if ((DateTime.Now - _framestart).TotalSeconds > 0) Fps = (int)(_totalframes / (DateTime.Now - _framestart).TotalSeconds); try { LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice); } catch (Exception ex) { Log.Error("Error geting lv", ex); _operInProgress = false; return; } if (LiveViewData == null) { _operInProgress = false; return; } if (!LiveViewData.IsLiveViewRunning && !IsFocusStackingRunning) { DelayedStart = true; _restartTimerStartTime = DateTime.Now; _restartTimer.Start(); _operInProgress = false; return; } if (LiveViewData.ImageData == null) { // Log.Error("LV image data is null !"); _operInProgress = false; return; } Recording = LiveViewData.MovieIsRecording; try { if (LiveViewData != null && LiveViewData.ImageData != null) { MemoryStream stream = new MemoryStream(LiveViewData.ImageData, LiveViewData. ImageDataPosition, LiveViewData.ImageData. Length - LiveViewData. ImageDataPosition); LevelAngle = (int)LiveViewData.LevelAngleRolling; SoundL = LiveViewData.SoundL; SoundR = LiveViewData.SoundR; PeakSoundL = LiveViewData.PeakSoundL; PeakSoundR = LiveViewData.PeakSoundR; HaveSoundData = LiveViewData.HaveSoundData; MovieTimeRemain = decimal.Round(LiveViewData.MovieTimeRemain, 2); if (NoProcessing) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.StreamSource = stream; bi.EndInit(); bi.Freeze(); Bitmap = bi; ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = stream.ToArray(); _operInProgress = false; return; } using (var res = new Bitmap(stream)) { Bitmap bmp = res; if (PreviewTime > 0 && (DateTime.Now - _photoCapturedTime).TotalSeconds <= PreviewTime) { var bitmap = ServiceProvider.Settings.SelectedBitmap.DisplayImage.Clone(); //var dw = (double)bmp.Width / bitmap.PixelWidth; //bitmap = bitmap.Resize((int)(bitmap.PixelWidth * dw), (int)(bitmap.PixelHeight * dw), // WriteableBitmapExtensions.Interpolation.NearestNeighbor); // flip image only if the prview not fliped if (FlipImage && !ServiceProvider.Settings.FlipPreview) bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical); bitmap.Freeze(); ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(bitmap); Bitmap = bitmap; return; } if (DetectMotion) { ProcessMotionDetection(bmp); } if (_totalframes % DesiredFrameRate == 0 && ShowHistogram) { ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bmp); LuminanceHistogramPoints = ConvertToPointCollection( hslStatistics.Luminance.Values); ImageStatistics statistics = new ImageStatistics(bmp); RedColorHistogramPoints = ConvertToPointCollection( statistics.Red.Values); GreenColorHistogramPoints = ConvertToPointCollection( statistics.Green.Values); BlueColorHistogramPoints = ConvertToPointCollection( statistics.Blue.Values); } if (HighlightUnderExp) { ColorFiltering filtering = new ColorFiltering(); filtering.Blue = new IntRange(0, 5); filtering.Red = new IntRange(0, 5); filtering.Green = new IntRange(0, 5); filtering.FillOutsideRange = false; filtering.FillColor = new RGB(Color.Blue); filtering.ApplyInPlace(bmp); } if (HighlightOverExp) { ColorFiltering filtering = new ColorFiltering(); filtering.Blue = new IntRange(250, 255); filtering.Red = new IntRange(250, 255); filtering.Green = new IntRange(250, 255); filtering.FillOutsideRange = false; filtering.FillColor = new RGB(Color.Red); filtering.ApplyInPlace(bmp); } var preview = BitmapFactory.ConvertToPbgra32Format( BitmapSourceConvert.ToBitmapSource(bmp)); DrawFocusPoint(preview, true); if (Brightness != 0) { BrightnessCorrection filter = new BrightnessCorrection(Brightness); bmp = filter.Apply(bmp); } Bitmap newbmp = bmp; if (EdgeDetection) { var filter = new FiltersSequence( Grayscale.CommonAlgorithms.BT709, new HomogenityEdgeDetector() ); newbmp = filter.Apply(bmp); } WriteableBitmap writeableBitmap; if (BlackAndWhite) { Grayscale filter = new Grayscale(0.299, 0.587, 0.114); writeableBitmap = BitmapFactory.ConvertToPbgra32Format( BitmapSourceConvert.ToBitmapSource( filter.Apply(newbmp))); } else { writeableBitmap = BitmapFactory.ConvertToPbgra32Format( BitmapSourceConvert.ToBitmapSource(newbmp)); } DrawGrid(writeableBitmap); switch (RotationIndex) { case 0: Rotation = 0; break; case 1: Rotation = 90; break; case 2: Rotation = 180; break; case 3: Rotation = 270; break; case 4: Rotation = LiveViewData.Rotation; break; } if (CameraDevice.LiveViewImageZoomRatio.Value == "All") { preview.Freeze(); Preview = preview; if (ShowFocusRect) DrawFocusPoint(writeableBitmap); } if (FlipImage) { writeableBitmap = writeableBitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical); } if (CropRatio > 0) { CropOffsetX = (int) ((writeableBitmap.PixelWidth/2.0)*CropRatio/100); CropOffsetY = (int) ((writeableBitmap.PixelHeight/2.0)*CropRatio/100); writeableBitmap = writeableBitmap.Crop(CropOffsetX, CropOffsetY, writeableBitmap.PixelWidth - (2*CropOffsetX), writeableBitmap.PixelHeight - (2*CropOffsetY)); } writeableBitmap.Freeze(); Bitmap = writeableBitmap; //if (_totalframes%DesiredWebFrameRate == 0) ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(writeableBitmap); } stream.Close(); } } catch (Exception exception) { Log.Error(exception); _operInProgress = false; } finally { _operInProgress = false; } _operInProgress = false; }
public Bitmap ConvertTOGrayScale(double cr, double cg, double cb) { Grayscale grayScaleFilter = new Grayscale(cr, cg, cb); Bitmap convertedImage = grayScaleFilter.Apply(ImageBitmap); ImageBitmap = convertedImage; return convertedImage; }
public static Bitmap ApplyGrayScaleFilter(Bitmap pBitmap) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); return filter.Apply(pBitmap); }
// Process image private void ProcessImage(Bitmap bitmap) { // create filter HistogramEqualization hisFilter = new HistogramEqualization(); // process image //hisFilter.ApplyInPlace(Image); // create filter ContrastCorrection contrastFilter = new ContrastCorrection(4); // apply the filter contrastFilter.ApplyInPlace(bitmap); //QuantizeImage(bitmap); Grayscale grayscaleFilter = new Grayscale(0.33, 0.33, 0.34); // apply the filter Bitmap grayImage = grayscaleFilter.Apply(bitmap); // create filter SobelEdgeDetector sobelFilter = new SobelEdgeDetector(); // apply the filter sobelFilter.ApplyInPlace(grayImage); Threshold filter = new Threshold(110); // apply the filter filter.ApplyInPlace(grayImage); if (GetIntersect(grayImage, bitmap, intersectPoint)) { //MessageBox.Show("draw"); Graphics g = Graphics.FromImage(bitmap); //Sorting for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if (Math.Abs(intersectPoint[1, i, k]) > Math.Abs(intersectPoint[1, i, k + 1])) { int tempX = Math.Abs(intersectPoint[0, i, k]); int tempY = Math.Abs(intersectPoint[1, i, k]); intersectPoint[0, i, k] = Math.Abs(intersectPoint[0, i, k + 1]); intersectPoint[1, i, k] = Math.Abs(intersectPoint[1, i, k + 1]); intersectPoint[0, i, k + 1] = tempX; intersectPoint[1, i, k + 1] = tempY; //MessageBox.Show(i + " " + k +" " +tempX + " " + tempY + " " + intersectPoint[0, i, k] + " " + intersectPoint[1, i, k] ,"ok", MessageBoxButtons.OK); } } } } for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { for (int k = 0; k < 19 - 1; k++) { if (Math.Abs(intersectPoint[0, k, i]) > Math.Abs(intersectPoint[0, k + 1, i])) { int tempX = Math.Abs(intersectPoint[0, k, i]); int tempY = Math.Abs(intersectPoint[1, k, i]); intersectPoint[0, k, i] = intersectPoint[0, k + 1, i]; intersectPoint[1, k, i] = intersectPoint[1, k + 1, i]; intersectPoint[0, k + 1, i] = tempX; intersectPoint[1, k + 1, i] = tempY; } } } } Pen redPen = new Pen(Color.Red, 4); for (int i = 0; i < 19; i++) { for (int j = 0; j < 19; j++) { g.DrawEllipse(redPen, Math.Abs(intersectPoint[0, i, j]) , Math.Abs(intersectPoint[1, i, j]) , (int)5, (int)5); //g.DrawEllipse(redPen, 0, 0, (int)5, (int)5); //Debug.WriteLine((Math.Abs(intersectPoint[0, i, j]) - 2) + " " + (Math.Abs(intersectPoint[1, i, j]) - 2)); } } Pen greenPen = new Pen(Color.Green, 4); greenPen.Dispose(); redPen.Dispose(); g.Dispose(); // Initializes the variables to pass to the MessageBox.Show method. EspacioCamera.Image = bitmap; string message = "Do you accecpt this detection?"; string caption = "The system found totally 38 lines."; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(message, caption, buttons); if (result == System.Windows.Forms.DialogResult.Yes) { // Closes the parent form. locked = true; } } EspacioCamera.Image = bitmap; }
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 skew(Bitmap source) { // create grayscale filter (BT709) Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // 8비트 grayscale 로 바꾸고 // apply the filter Bitmap grayImage = filter.Apply(source); // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // 8비트 grayscale 로 넣어줘야 함 // // get documents skew angle double angle = skewChecker.GetSkewAngle(grayImage); // 기울어진 각도를 얻고 Bitmap tmp = source; // convert to 24 bits per pixel source = ImageProcess.Clone(tmp, PixelFormat.Format24bppRgb); // 로테이션 전에 24비트로 바꿔주고 // delete old image tmp.Dispose(); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter Bitmap rotatedImage = rotationFilter.Apply(source); // 원래 이미지를 가져다가 각도만큼 돌리고(원래 이미지는 24비트로 넣어줘야함) return rotatedImage; }
private void LoadFileButton_Click(object sender, EventArgs e) { pictureBoxCutPlate.Image = null; pictureboxEditPicture.Image = null; String input = string.Empty; OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "BMP | *.bmp"; // dialog.InitialDirectory = "D:/Studia/BIAI/Tablice/Tablice/bin/Debug"; //dialog.InitialDirectory = "C:"; dialog.InitialDirectory = "C:/Users/k/Documents/GitHub/BIAI_PROJ/BIAI_PROJ/Tablice/Tablice/Images"; dialog.Title = "Select a text file"; if (dialog.ShowDialog() == DialogResult.OK) input = dialog.FileName; if (input == String.Empty) return; //user didn't select a file to opena toEdit = new Bitmap(dialog.FileName); toEdit = frame.scaleImage(pictureboxEditPicture.Width, pictureboxEditPicture.Height, toEdit); pictureboxEditPicture.Image = toEdit; //CUT PLATE List<IntPoint> corners = blob.getCorners(toEdit); if (corners.Count > 0) { int maxY, minY, maxX, minX; if (corners[1].Y < corners[0].Y) maxY = corners[1].Y; else maxY = corners[0].Y; if (corners[3].Y > corners[2].Y) minY = corners[3].Y; else minY = corners[2].Y; if (corners[0].X < corners[3].X) minX = corners[0].X; else minX = corners[3].X; if (corners[1].X < corners[2].X) maxX = corners[2].X; else maxX = corners[1].X; Rectangle rectangle = new Rectangle(minX, maxY, maxX - minX, minY - maxY); System.Drawing.Image img = (System.Drawing.Image)toEdit; System.Drawing.Image cropped = frame.cropImage(img, rectangle); croppedBmp = new Bitmap(cropped); croppedBmp = frame.scaleImage(pictureBoxCutPlate.Width, pictureBoxCutPlate.Height, croppedBmp); pictureBoxCutPlate.Image = croppedBmp; //GREYSCALE & THRESEHOLD Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter croppedBmp = filter.Apply(croppedBmp); OtsuThreshold thr = new OtsuThreshold(); // apply the filter thr.ApplyInPlace(croppedBmp); pictureBoxCutPlate.Image = croppedBmp; croppedBmp = frame.cutCorners(croppedBmp); croppedBmp = frame.scaleImage(pictureBoxCutPlate.Width, pictureBoxCutPlate.Height, croppedBmp); pictureBoxCutPlate.Image = croppedBmp; // pictureBox1.Image = croppedBmp; status.Text = "Plate found"; bmp = pictureBoxCutPlate.Image as Bitmap; frame = new ManageImage(bmp); frame.getBlack(); if (frame.images.Count() > 0) { status.Text = "Characters found and saved"; } else status.Text = "No characters found"; } else status.Text = "Plate not found"; toEdit = blob.ProcessImage(toEdit); pictureboxEditPicture.Image = toEdit; }
/// <summary> /// Convert RGB colour space to grayscale when applicable. /// </summary> /// <param name="bitmap">The bitmap.</param> public static Bitmap Grayscale(this Bitmap bitmap) { if ((bitmap = bitmap.Channel()) != null) { var imageStatisticsHSL = new ImageStatisticsHSL(bitmap); if (imageStatisticsHSL.Saturation.Max == 0) { var grayscale = new Grayscale(0.2125, 0.7154, 0.0721); var result = grayscale.Apply(bitmap); bitmap.Dispose(); return result; } } return bitmap; }
public void HitAndMiss() { var se = new short[,] { { -1, -1, -1 }, { 1, 1, 0 }, { -1, -1, -1 } }; HitAndMiss filter = new HitAndMiss(se, AForge.Imaging.Filters.HitAndMiss.Modes.Thinning); Grayscale grayScaler = new Grayscale(0.2125, 0.7154, 0.0721); _digit = filter.Apply(grayScaler.Apply(new Bitmap(_digit))); }
private void ToGrayScale() { Grayscale gf = new Grayscale(0.2125, 0.7154, 0.0721); _recogimg = gf.Apply(_recogimg); }
public static Bitmap ToBlackAndWhite(this Bitmap bitmap) { AForge.Imaging.Filters.Grayscale filter = Grayscale.CommonAlgorithms.Y; return(filter.Apply(AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format24bppRgb))); }
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; }
private Bitmap Threshold(Bitmap original, int value = 100) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap image = filter.Apply(original); Threshold filtera = new Threshold(value); return filtera.Apply(image); }
public void processVideo() { //CUT PLATE Bitmap toEditVideo = pictureboxCatched.Image as Bitmap; List<IntPoint> corners = blob.getCorners(toEditVideo); if (corners.Count > 0) { int maxY, minY, maxX, minX; if (corners[1].Y < corners[0].Y) maxY = corners[1].Y; else maxY = corners[0].Y; if (corners[3].Y > corners[2].Y) minY = corners[3].Y; else minY = corners[2].Y; if (corners[0].X < corners[3].X) minX = corners[0].X; else minX = corners[3].X; if (corners[1].X < corners[2].X) maxX = corners[2].X; else maxX = corners[1].X; Rectangle rectangle = new Rectangle(minX, maxY, maxX - minX, minY - maxY); System.Drawing.Image img = (System.Drawing.Image)toEditVideo; System.Drawing.Image cropped = frame.cropImage(img, rectangle); croppedVideo = new Bitmap(cropped); croppedVideo = frame.scaleImage(pictureBox1.Width, pictureBox1.Height, croppedVideo); pictureBox1.Image = croppedVideo; //GREYSCALE & THRESEHOLD Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); // apply the filter croppedVideo = filter.Apply(croppedVideo); OtsuThreshold thr = new OtsuThreshold(); // apply the filter thr.ApplyInPlace(croppedVideo); pictureBox1.Image = croppedVideo; croppedVideo = frame.cutCorners(croppedVideo); croppedVideo = frame.scaleImage(pictureBox1.Width, pictureBox1.Height, croppedVideo); pictureBox1.Image = croppedVideo; statusVideo.Text = "Plate found"; bmp = pictureBox1.Image as Bitmap; frame = new ManageImage(bmp); frame.getBlack(); if (frame.images.Count() > 0) { status.Text = "Characters found and saved"; } else status.Text = "No characters found"; } else statusVideo.Text = "Plate not found"; toEditVideo = blob.ProcessImage(toEditVideo); pictureboxCatched.Image = toEditVideo; }