private void blurToolStripMenuItem_Click(object sender, EventArgs e) { GaussianBlur gb = new GaussianBlur(); newImg = gb.Apply(orgImg); pictureBox6.Image = newImg; }
public Bitmap ToGaussianBlur(Bitmap Im) { AForge.Imaging.Filters.GaussianBlur Img = new GaussianBlur(); Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb); return(Img.Apply(bmImage)); }
/// <summary> /// Creates a comic rendered copy of the input image. /// </summary> public override Bitmap Render(Bitmap sourceImage) { // Converters GrayscaleY convertGray = new GrayscaleY(); GrayscaleToRGB convertColor = new GrayscaleToRGB(); // Convert grayscal images if (sourceImage.PixelFormat == PixelFormat.Format8bppIndexed) { sourceImage = convertColor.Apply(sourceImage); } Bitmap comicImage = AForge.Imaging.Image.Clone(sourceImage); Bitmap edgeLayer = null; Bitmap glowLayer = null; // Glow for smooth colors GaussianBlur filterBlur = new GaussianBlur(); filterBlur.Sigma = 2.0; filterBlur.Size = 4; glowLayer = filterBlur.Apply(comicImage); //SmartBlur filterBlur = new SmartBlur(10, 0.2); //glowLayer = filterBlur.Apply(comicImage); ContrastCorrection filterContrast = new ContrastCorrection(1 - (-this.Coloring * 0.1)); filterContrast.ApplyInPlace(glowLayer); BrightnessCorrection filterBrightness = new BrightnessCorrection((-this.Coloring * 0.1) + 0.1); filterBrightness.ApplyInPlace(glowLayer); Screen blendScreen = new Screen(glowLayer); blendScreen.ApplyInPlace(comicImage); // Create a layer for edges Convolution filterConvolution = new Convolution(ConvolutionKernel); edgeLayer = filterConvolution.Apply(comicImage); // Convert to grayscale edgeLayer = convertGray.Apply(edgeLayer); // Threshold (edge thickness) Threshold filterThreshold = new Threshold((byte)(this.Edging * 255 / 100)); filterThreshold.ApplyInPlace(edgeLayer); edgeLayer = convertColor.Apply(edgeLayer); // intersect comic with top layer (Darken blend) Intersect blendIntersect = new Intersect(edgeLayer); blendIntersect.ApplyInPlace(comicImage); return(comicImage); }
public Bitmap GetNewFrame(Bitmap source) { var newFrame = gaussianBlur.Apply(source); source.Dispose(); return(newFrame); }
private void loadImage(string imageFileName) { // Clear everything radUpdateManual.Checked = true; m_snake.deleteAllPoints(); if (m_bmpOrig != null) { m_bmpOrig.Dispose(); m_bmpOrig = null; } if (m_bmpGray != null) { m_bmpGray.Dispose(); m_bmpGray = null; } if (m_bmpSmoo != null) { m_bmpSmoo.Dispose(); m_bmpSmoo = null; } if (m_bmpEdge != null) { m_bmpEdge.Dispose(); m_bmpEdge = null; } // Load image m_bmpOrig = (Bitmap)System.Drawing.Image.FromFile(imageFileName); m_imageFI = new FileInfo(imageFileName); this.Text = "Snake Demo: " + m_imageFI.Name + " (" + m_bmpOrig.Width.ToString() + "x" + m_bmpOrig.Height.ToString() + ", Scale: " + m_imageScale.ToString("0") + ")"; // Build grayscale image if (m_bmpOrig.PixelFormat == PixelFormat.Format8bppIndexed) { m_bmpGray = (Bitmap)m_bmpOrig.Clone(); } else { Grayscale filterGray = new Grayscale(0.257, 0.504, 0.098); m_bmpGray = filterGray.Apply(m_bmpOrig); } // Build smoothed imgage with a gaussian blur filter GaussianBlur filterGauss = new GaussianBlur(1, (int)numGauss.Value); m_bmpSmoo = filterGauss.Apply(m_bmpGray); // Build edges with a Sobel filter SobelEdgeDetector filterSobel = new SobelEdgeDetector(); m_bmpEdge = filterSobel.Apply(m_bmpSmoo); filterGauss.ApplyInPlace(m_bmpEdge); // Enabel controls btnDeleteSnake.Enabled = false; btnDoublePoints.Enabled = false; btnHalfPoints.Enabled = false; grpSnakeForces.Enabled = true; grpImageForce.Enabled = true; grpDisplay.Enabled = true; grpUpdate.Enabled = true; }
public Bitmap GaussianBlur(Bitmap bSource) { GaussianBlur gaussianBlur = new GaussianBlur(4, 11);//11 Bitmap bTemp = gaussianBlur.Apply(bSource); return(bTemp); }
//apply random gaussian blur private static Bitmap Blur(Bitmap image) { // create filter var filter = new GaussianBlur(r.NextDouble() / 2.0, 3); // apply the filter return(filter.Apply(image)); }
public static Bitmap CleanUpUpscaledImage(Bitmap image) { var blurFilter = new GaussianBlur { Sigma = 5.0 }; return(blurFilter.Apply(image)); }
public static Bitmap BlurBitmap(Bitmap bitmap) { using (Bitmap newBitm = new Bitmap(bitmap, new Size(128, 128))) { GaussianBlur blur = new GaussianBlur(2, 10); using (Bitmap blurredImage = blur.Apply(newBitm)) return(new Bitmap(blurredImage, new Size(bitmap.Width, bitmap.Height))); } }
private static void GaussianBlurTest(string imagePath, string outputPath) { var image = new Bitmap(imagePath); var outputImage = new Bitmap(image.Width, image.Height); var gaussianBlur = new GaussianBlur(); var rectangle = new Rectangle(0, 0, image.Width, image.Height); gaussianBlur.Apply(outputImage, image, rectangle, 0, image.Height - 1); outputImage.Save(outputPath, ImageFormat.Png); }
private void numGauss_ValueChanged(object sender, EventArgs e) { GaussianBlur filterGauss = new GaussianBlur(1, (int)numGauss.Value); m_bmpSmoo = filterGauss.Apply(m_bmpGray); SobelEdgeDetector filterSobel = new SobelEdgeDetector(); m_bmpEdge = filterSobel.Apply(m_bmpSmoo); filterGauss.ApplyInPlace(m_bmpEdge); Invalidate(); }
public static ImageMatrix ExtractSkeletonImage(Bitmap image, OrientationImage orientationImage) { var matrix = new ImageMatrix(image); var gb = new GaussianBlur(); matrix = gb.Apply(matrix); matrix = GetBinaryImage(matrix, orientationImage); ApplyThinning(matrix, orientationImage); RemoveSpikes(matrix, orientationImage); FixBifurcations(matrix, orientationImage); RemoveSmallSegments(matrix, orientationImage); return(matrix); }
void Start() { // get maintexture from source renderer var sourceTexture = (Texture2D)sourceRenderer.material.mainTexture; // create system bitmap System.Drawing.Bitmap accordImage = new System.Drawing.Bitmap(sourceTexture.width, sourceTexture.height); // copy our texture pixels to that system bitmap for (int x = 0; x < accordImage.Width; x++) { for (int y = 0; y < accordImage.Height; y++) { var c = (Color32)sourceTexture.GetPixel(x, y); var nc = System.Drawing.Color.FromArgb(c.r, c.g, c.b, c.a); accordImage.SetPixel(x, y, nc); } } // These 2 lines are the only Accord.NET code used here, create filter and then apply it to bitmap IFilter gaussianFilter = new GaussianBlur(2.0, 20); var resultsAccordImage = gaussianFilter.Apply(accordImage); // copy result pixels into our color32 array from system.drawing.bitmap var colors = new Color32[resultsAccordImage.Width * resultsAccordImage.Height]; for (int x = 0; x < resultsAccordImage.Width; x++) { for (int y = 0; y < resultsAccordImage.Height; y++) { var c = resultsAccordImage.GetPixel(x, y); colors[y * resultsAccordImage.Width + x] = new Color32(c.A, c.R, c.G, c.B); // colors are flipped in System.Drawing.Color } } // create new results texture from that color32 array var targetTexture = new Texture2D(sourceTexture.width, sourceTexture.height, sourceTexture.format, false); targetTexture.SetPixels32(colors); targetTexture.Apply(false); // assign it to another object targetRenderer.material.mainTexture = targetTexture; }
public PreProcess(UISettings ui, FileData file) { try { ExtendFileData(file); BitmapOriginal = (ui.WorkDirectory + "\\" + FileName).FileTo24bbpRgb(ResizeRatio: ui.ResizeValue, FrameCrop: ui.CropValue, ImageZoom: 1, RotateDegree: ui.RotateDegree); UnmanagedMarkup = UnmanagedImage.FromManagedImage(BitmapOriginal); ImageStatistics stats = null; Threshold AFbinary = new Threshold(1); Grayscale AFgray = new Grayscale(0.1, 0.7, 0.2); if (ui.ExcludeColorSwitch && ui.ExcludeColorRadius > 0) { System.Windows.Media.Color excolor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ui.ExcludeColorHex); EuclideanColorFiltering AFexcolor = new EuclideanColorFiltering(new RGB(excolor.R, excolor.G, excolor.B), (short)ui.ExcludeColorRadius); UnmanagedExclude = AFbinary.Apply(AFgray.Apply(AFexcolor.Apply(UnmanagedMarkup))); } else { UnmanagedExclude = UnmanagedImage.Create(UnmanagedMarkup.Width, UnmanagedMarkup.Height, PixelFormat.Format8bppIndexed); } if (ui.WhiteBalanceSwitch || ui.BlackBalanceSwitch) // need to apply auto white/black balance { Invert AFinvert = new Invert(); stats = new ImageStatistics(UnmanagedMarkup, AFinvert.Apply(UnmanagedExclude)); int lowend = (ui.BlackBalanceSwitch) ? (int)Math.Round(0.333d * (stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance))):0; LevelsLinear levelsLinear = new LevelsLinear { InRed = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), InGreen = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), InBlue = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255), }; //LevelsLinear levelsLinear = new LevelsLinear { // InRed=new IntRange((ui.BlackBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), // InGreen=new IntRange((ui.BlackBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), // InBlue=new IntRange((ui.BlackBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255), //}; levelsLinear.ApplyInPlace(UnmanagedMarkup); } if (ui.GaussianBlurSwitch && ui.GaussianBlur != 0) // Gaussian Blur and Darken { GaussianBlur AFgblur = new GaussianBlur(11.0, Math.Max(ui.GaussianBlur, 0) * 2 + 1); // Gaussian Blur sigma = 8.0 kernel size = 7 Intersect AFintersect = new Intersect(AFgblur.Apply(UnmanagedMarkup)); UnmanagedMarkup = AFintersect.Apply(UnmanagedMarkup); } UnmanagedGray = AFgray.Apply(UnmanagedMarkup); // directly turn into gray } catch { throw new Exception("Error Occured During PreProcessing"); } }
public void doGaussian(int sigma, int kernel) { Bitmap imx = new Bitmap(path); GaussianBlur gb = new GaussianBlur((sigma / 10), (kernel * 2 + 1)); imx = gb.Apply(imx); // ImageEView if (mov != null) { this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Close(mov); } mov = this.WorkItem.SmartParts.AddNew <ImageEView>(); mov.panAndZoomPictureBox1.Image = imx; SmartPartInfo spi = new SmartPartInfo("Gaussian", "MyOwnDescription"); this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Show(mov, spi); }
/// <summary> /// Filters the image using a tone map operator. /// Uses a Gaussian filter to anti-alias the image. /// </summary> /// <returns>Filtered bitmap.</returns> public Bitmap Filter(IToneMapOperator _operator, bool blur) { Bitmap _image = null; if (_operator != null) { _image = _operator.CreateImage(this.m_shadowBitmap, this.Width, this.Height); } else { throw new ArgumentNullException("_operator", "Cannot filter the texture map without a tone mapping operator!"); } if (blur) { GaussianBlur _blurFilter = new GaussianBlur(); return(_blurFilter.Apply(_image)); } return(_image); }
private int[] CalcDifferenceOfGaussian2(UnmanagedImage srcImage) { //difference of gaussian var image1 = Filter1.Apply(srcImage); var image2 = Filter2.Apply(srcImage); var diff = image1.Subtract(image2); image1.Dispose(); var image3 = Filter3.Apply(srcImage); var diff2 = image2.Subtract(image3); image2.Dispose(); image3.Dispose(); for (var i = 0; i < diff.Length; i++) { diff[i] -= diff2[i]; } return(diff); }
/// <summary> /// Creates a comic rendered copy of the input image. /// </summary> public override Bitmap Render(Bitmap sourceImage) { Bitmap sketchImage = AForge.Imaging.Image.Clone(sourceImage); GrayscaleY convertGray = new GrayscaleY(); // Blur GaussianBlur filterBlur = new GaussianBlur(); filterBlur.Sigma = this.PencilTipSize; filterBlur.Size = this.PencilTipSize; Bitmap overLayer = filterBlur.Apply(sketchImage); // Invert over layer Invert sketchInvert = new Invert(); sketchInvert.ApplyInPlace(overLayer); BrightnessCorrection filterBrightness = new BrightnessCorrection(-this.Range * 0.01); filterBrightness.ApplyInPlace(overLayer); ContrastCorrection filterContrast = new ContrastCorrection(1 - (-this.Range * 0.01)); filterContrast.ApplyInPlace(overLayer); // Convert to grayscale sketchImage = convertGray.Apply(sketchImage); overLayer = convertGray.Apply(overLayer); // Dodge blending for the win! ColorDodge dodgeBlend = new ColorDodge(overLayer); dodgeBlend.ApplyInPlace(sketchImage); return(sketchImage); }
/// <summary> Blob Detection /// This method for color object detection by Blob counter algorithm. /// If you using this method, then you can detecting as follows: /// red circle, rectangle, triangle /// blue circle, rectangle, triangle /// green circle, rectangle, triangle /// the process of this method as follow: /// 1. color filtering by Euclidean filtering(R, G, B). /// 2. the grayscale filtering based on color filtered image. /// 3. In this step, you can choose the blur option. Applied blur option(or not), /// this method donging Sobel edge filtering based on grayscale(or grayscale + blur) image. /// 4. the binary filtering based on edge filter image. /// 5. Finally, detecting object, distance from the camera and degree are expreed on picturebox 1. /// </summary> private Bitmap BlobDetection(Bitmap _bitmapSourceImage) { #region Color filtering by Euclidean filtering switch (iColorMode) { case 1: //_colorFilter.CenterColor = new RGB(230, 30, 30); iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; case 2: iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; case 3: iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; } #endregion Grayscale _grayscale = new Grayscale(0.2125, 0.7154, 0.0721); _bitmapGreyImage = _grayscale.Apply(_colorFilterImage); #region blur option with Edge filter //create a edge detector instance if (_blurFlag == true) { //Blur _blurfilter = new Blur(); GaussianBlur _blurfilter = new GaussianBlur(1.5); _bitmapBlurImage = _blurfilter.Apply(_bitmapGreyImage); _bitmapEdgeImage = _edgeFilter.Apply(_bitmapBlurImage); } else if (_blurFlag == false) { _bitmapEdgeImage = _edgeFilter.Apply(_bitmapGreyImage); } #endregion Threshold _threshold = new Threshold(iThreshold); _bitmapBinaryImage = _threshold.Apply(_bitmapEdgeImage); /// /// blob counter algorithm initailze. /// BlobCounter.MinWidth and MinHeight -> for the defined minimum region /// BlobCounter _blobCounter = new BlobCounter(); //Configure Filter _blobCounter.MinWidth = 70; _blobCounter.MinHeight = 70; _blobCounter.FilterBlobs = true; _blobCounter.ProcessImage(_bitmapBinaryImage); Blob[] _blobPoints = _blobCounter.GetObjectsInformation(); Graphics _g = Graphics.FromImage(_bitmapSourceImage); SimpleShapeChecker _shapeChecker = new SimpleShapeChecker(); for (int i = 0; i < _blobPoints.Length; i++) { List <IntPoint> _edgePoint = _blobCounter.GetBlobsEdgePoints(_blobPoints[i]); List <IntPoint> _corners = null; AForge.Point _center; float _radius; //#region detecting Rectangle ///// ///// _corners: the corner of Quadrilateral ///// //if (_shapeChecker.IsQuadrilateral(_edgePoint, out _corners)) //{ // //Drawing the reference point of the picturebox // _g.DrawEllipse(_PictureboxPen, (float)(pictureBox1.Size.Width), // (float)(pictureBox1.Size.Height), // (float)10, (float)10); // // Drawing setting for outline of detected object // Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); // System.Drawing.Point[] _coordinates = ToPointsArray(_corners); // Pen _pen = new Pen(Color.Blue, ipenWidth); // int _x = _coordinates[0].X; // int _y = _coordinates[0].Y; // // Drawing setting for centroid of detected object // int _centroid_X = (int)_blobPoints[0].CenterOfGravity.X; // int _centroid_Y = (int)_blobPoints[0].CenterOfGravity.Y; // //Drawing the centroid point of object // _g.DrawEllipse(_pen, (float)(_centroid_X), (float)(_centroid_Y), (float)10, (float)10); // //Degree calculation // int _deg_x = (int)_centroid_X - pictureBox1.Size.Width; // int _deg_y = pictureBox1.Size.Height - (int)_centroid_Y; // textBox1.Text = ("Degree: (" + _deg_x + ", " + _deg_y + ")"); // /// // /// Drawing outline of detected object // /// // if (_coordinates.Length == 4) // { // string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); // _g.DrawString(_shapeString, _font, _brush, _x, _y); // _g.DrawPolygon(_pen, ToPointsArray(_corners)); // } // //size of rectange // foreach (Rectangle rc in _rects) // { // ///for debug // //System.Diagnostics.Debug.WriteLine( // // string.Format("Rect size: ({0}, {1})", rc.Width, rc.Height)); // iFeatureWidth = rc.Width; // //check the FindDistance method. // double dis = FindDistance(iFeatureWidth); // _g.DrawString(dis.ToString("N2") + "cm", _font, _brush, _x, _y + 60); // } //} //#endregion #region detecting Circle /// /// _center: the center of circle /// _radius: the radius of circle /// if (_shapeChecker.IsCircle(_edgePoint, out _center, out _radius)) { //Drawing the reference point _g.DrawEllipse(_PictureboxPen, (float)(pictureBox1.Size.Width), (float)(pictureBox1.Size.Height), (float)10, (float)10); // Drawing setting for outline of detected object Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); Pen _pen = new Pen(Color.Red, ipenWidth); string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); int _x = (int)_center.X; int _y = (int)_center.Y; /// /// Drawing outline of detected object /// _g.DrawString(_shapeString, _font, _brush, _x, _y); _g.DrawEllipse(_pen, (float)(_center.X - _radius), (float)(_center.Y - _radius), (float)(_radius * 2), (float)(_radius * 2)); //Drawing the centroid point of object int _centroid_X = (int)_blobPoints[0].CenterOfGravity.X; int _centroid_Y = (int)_blobPoints[0].CenterOfGravity.Y; _g.DrawEllipse(_pen, (float)(_centroid_X), (float)(_centroid_Y), (float)10, (float)10); //Degree calculation //int _deg_x = _centroid_X - pictureBox1.Size.Width; //int _deg_y = pictureBox1.Size.Height - _centroid_Y; float _deg_x = _center.X * 100 / pictureBox1.Image.Width; float _deg_y = _center.Y * 100 / pictureBox1.Image.Height; textBox2.Text = _deg_x + ""; textBox3.Text = _deg_y + ""; textBox1.Text = ("Degree: (" + _deg_x + ", " + _deg_y + ")"); //size of rectange foreach (Rectangle rc in _rects) { ///for debug //System.Diagnostics.Debug.WriteLine( // string.Format("Circle size: ({0}, {1})", rc.Width, rc.Height)); iFeatureWidth = rc.Width; double dis = FindDistance(iFeatureWidth); _g.DrawString(dis.ToString("N2") + "cm", _font, _brush, _x, _y + 60); } } #endregion //#region detecting Triangle ///// ///// _corners: the corner of Triangle ///// //if (_shapeChecker.IsTriangle(_edgePoint, out _corners)) //{ // //Drawing the reference point // _g.DrawEllipse(_PictureboxPen, (float)(pictureBox1.Size.Width), // (float)(pictureBox1.Size.Height), // (float)10, (float)10); // // Drawing setting for outline of detected object // Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); // Pen _pen = new Pen(Color.Green, ipenWidth); // string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); // int _x = (int)_center.X; // int _y = (int)_center.Y; // // Drawing setting for centroid of detected object // int _centroid_X = (int)_blobPoints[0].CenterOfGravity.X; // int _centroid_Y = (int)_blobPoints[0].CenterOfGravity.Y; // /// // /// Drawing outline of detected object // /// // _g.DrawString(_shapeString, _font, _brush, _x, _y); // _g.DrawPolygon(_pen, ToPointsArray(_corners)); // //Drawing the centroid point of object // _g.DrawEllipse(_pen, (float)(_centroid_X), (float)(_centroid_Y), (float)10, (float)10); // //Degree calculation // int _deg_x = (int)_centroid_X - pictureBox1.Size.Width; // int _deg_y = pictureBox1.Size.Height - (int)_centroid_Y; // textBox1.Text = ("Degree: (" + _deg_x + ", " + _deg_y + ")"); // //size of rectange // foreach (Rectangle rc in _rects) // { // ///for debug // //System.Diagnostics.Debug.WriteLine( // // string.Format("Triangle Size: ({0}, {1})", rc.Width, rc.Height)); // iFeatureWidth = rc.Width; // double dis = FindDistance(iFeatureWidth); // _g.DrawString(dis.ToString("N2") + "cm", _font, _brush, _x, _y + 60); // } //} //#endregion } return(_bitmapSourceImage); }
public static Bitmap BlurImage(Bitmap img, float sigma, int range) { IFilter myFilter = new GaussianBlur(sigma, range); return(myFilter.Apply(img)); }
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); }
public Bitmap edgeDetection() { Bitmap colorImg = (Bitmap)videoSourcePlayer1.GetCurrentVideoFrame(); Grayscale grayfilter = new Grayscale(cr, cg, cb); GaussianBlur blurFilter = new GaussianBlur(); GaussianSharpen sharpenFilter = new GaussianSharpen(); Bitmap originalImage; if (gausianToggle == 0) { originalImage = (Bitmap)grayfilter.Apply(colorImg); } else if (gausianToggle == 1) { originalImage = sharpenFilter.Apply((Bitmap)colorImg); originalImage = (Bitmap)grayfilter.Apply(originalImage); } else { originalImage = blurFilter.Apply((Bitmap)colorImg); originalImage = (Bitmap)grayfilter.Apply(originalImage); } switch (caseValue) { case 1: //canny scrollableImagePanel1.Image = originalImage; CannyEdgeDetector edgeDectector = new CannyEdgeDetector(); edgeDectector.HighThreshold = (byte)cannyUpperThresholdSlider.Value; edgeDectector.LowThreshold = (byte)cannyLowerThresholdSlider.Value; edgeDectector.ApplyInPlace(scrollableImagePanel1.Image); return((Bitmap)scrollableImagePanel1.Image); case 2: //gray scale scrollableImagePanel3.Image = originalImage; Grayscale customGrayScale = new Grayscale((cr * (graySlider.Value / 100)), (cb * (graySlider.Value / 100)), (cg * (graySlider.Value / 100))); originalImage = customGrayScale.Apply(colorImg); return(originalImage); case 3: //Black and White scrollableImagePanel2.Image = originalImage; Threshold thresholdFilter = new Threshold(); thresholdFilter.ThresholdValue = hScrollBar1.Value; thresholdFilter.ApplyInPlace(scrollableImagePanel2.Image); return((Bitmap)scrollableImagePanel2.Image); case 4: //Mixed Color Edits scrollableImagePanel5.Image = colorImg; ChannelFiltering colorChannelFilter = new ChannelFiltering(); colorChannelFilter.Red = new IntRange(0, redSlider.Value); colorChannelFilter.Blue = new IntRange(0, blueSlider.Value); colorChannelFilter.Green = new IntRange(0, greenSlider.Value); colorChannelFilter.ApplyInPlace((Bitmap)scrollableImagePanel5.Image); return((Bitmap)scrollableImagePanel5.Image); case 5: //Specific Color edits ColorFiltering colorFilter = new ColorFiltering(); if (colorToggle == 1) { Console.WriteLine("Red disabled"); colorFilter.Red = new IntRange(0, 0); colorFilter.Blue = new IntRange(0, 255); colorFilter.Green = new IntRange(0, 255); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else if (colorToggle == 2) { Console.WriteLine("Blue disabled"); colorFilter.Red = new IntRange(0, 255); colorFilter.Blue = new IntRange(0, 0); colorFilter.Green = new IntRange(0, 255); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else if (colorToggle == 3) { Console.WriteLine("Green disabled"); colorFilter.Red = new IntRange(0, 255); colorFilter.Blue = new IntRange(0, 255); colorFilter.Green = new IntRange(0, 0); colorFilter.Apply(colorImg); originalImage = colorImg; return(originalImage); } else { return(colorImg); } } return(originalImage); }
/// <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); }
//Detect Shapes private Bitmap Mark_all_Shapes(Bitmap input) { if (windowOpen) { myDetaildWindow.Set_PictureOriginal(input); } //Bitmap zwischenspeiche Bitmap help = input; //1. Farbilter input = myRGB_Filter.Apply(input); if (windowOpen) { myDetaildWindow.Set_PictureColorFilter(input); } //Graustufen-Bild input = myGrayScale.Apply(input); if (windowOpen) { myDetaildWindow.Set_PictureGreyScale(input); } //Blur Filter input = blurfilter.Apply(input); //Kantenfilter input = myEdge_Filter.Apply(input); if (windowOpen) { myDetaildWindow.Set_PictureEdge(input); } //Threshold-Filter input = myThreshold.Apply(input); if (windowOpen) { myDetaildWindow.Set_PictureThreshold(input); } //Create a instance of blob counter algorithm BlobCounter blobCounter = new BlobCounter() { MinWidth = 70, MinHeight = 70, FilterBlobs = true, }; //Objekte finden blobCounter.ProcessImage(input); Blob[] objectFound = blobCounter.GetObjectsInformation(); Graphics _g = Graphics.FromImage(help); //Shapes überprüfen SimpleShapeChecker _shapeChecker = new SimpleShapeChecker(); //Liste meiner Objeckte MyObjects = new List <Detected_Object>(); foreach (Blob element in objectFound) { List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(element); Pen _pen = new Pen(Color.Red, 5); //Kreis if (_shapeChecker.IsCircle(edgePoints, out AForge.Point mittelPunkt, out float radius)) { Detected_Object _object = new Circile(mittelPunkt, radius); _object.DrawInGraphic(_pen, _g); MyObjects.Add(_object); }
public static Bitmap ApplyGaussianBlurFilter(Bitmap input, int kernelSize, double sigma) { GaussianBlur gaussianBlurFilter = new GaussianBlur(sigma, kernelSize); return(gaussianBlurFilter.Apply(input)); //} //else { // if (blurOutside) // { // int distanceToBlur = Math.Min(Math.Min(selectionX, selectionY), kernelSize); // int pixelStep = Math.Max(3, distanceToBlur / kernelSize); // int currentStep = pixelStep; // int kernelReduction = distanceToBlur / pixelStep; // Bitmap temp = (Bitmap)input.Clone(); // input = gaussianBlurFilter.Apply(input); // while (kernelSize > 0) // { // if (kernelSize - kernelReduction < 1) // { // gaussianBlurFilter.Size = 2; // input = gaussianBlurFilter.Apply(input); // Rectangle rect1 = new Rectangle(selectionX, selectionY, selectionWidth, selectionHeight); // Bitmap selectedPortion1 = new Bitmap(rect1.Width, rect1.Height); // using (Graphics g = Graphics.FromImage(selectedPortion1)) // { // g.DrawImage(temp, new Rectangle(0, 0, rect1.Width, rect1.Height), rect1, GraphicsUnit.Pixel); // } // //selectedPortion = gaussianBlurFilter.Apply(selectedPortion); // using (Graphics g = Graphics.FromImage(input)) // { // g.DrawImage(selectedPortion1, rect1); // } // break; // } // Rectangle rect = new Rectangle(selectionX-currentStep,selectionY- currentStep, input.Width+currentStep, input.Height + currentStep); // Bitmap selectedPortion = new Bitmap(rect.Width, rect.Height); // using (Graphics g = Graphics.FromImage(selectedPortion)) // { // g.DrawImage(temp, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel); // } // gaussianBlurFilter.Size = kernelSize; // selectedPortion = gaussianBlurFilter.Apply(selectedPortion); // using (Graphics g = Graphics.FromImage(input)) // { // g.DrawImage(selectedPortion, rect); // } // currentStep += pixelStep; // kernelSize -= kernelReduction; // } // //Rectangle rect = new Rectangle(selectionX, selectionY, selectionWidth, selectionHeight); // //Bitmap selectedPortion = new Bitmap(rect.Width, rect.Height); // // using (Graphics g = Graphics.FromImage(selectedPortion)) // // { // // g.DrawImage(input, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel); // // } // ////AddBitmapImageToImage(selectedPortion); // ////Bitmap temp = (Bitmap)input.Clone(); // //while (kernelSize > 0 && distanceToBlur > pixelStep) // //{ // // Rectangle rect1 = new Rectangle(selectionX - distanceToBlur, selectionY - distanceToBlur, selectionWidth + distanceToBlur, selectionHeight + distanceToBlur); // // Bitmap selectedPortion1 = new Bitmap(rect.Width, rect.Height); // // using (Graphics g = Graphics.FromImage(selectedPortion1)) // // { // // g.DrawImage(temp, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel); // // } // // using (Graphics g = Graphics.FromImage(input)) // // { // // g.DrawImage(selectedPortion, rect); // // } // //} // //} // //input = gaussianBlurFilter.Apply(input); // return input; // } // else { // Rectangle rect = new Rectangle(selectionX, selectionY, selectionWidth, selectionHeight); // Bitmap selectedPortion = new Bitmap(rect.Width, rect.Height); // using (Graphics g = Graphics.FromImage(selectedPortion)) // { // g.DrawImage(input, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel); // } // //AddBitmapImageToImage(selectedPortion); // selectedPortion = gaussianBlurFilter.Apply(selectedPortion); // using (Graphics g = Graphics.FromImage(input)) // { // g.DrawImage(selectedPortion, rect); // } // return input; // } //} }
/// <summary> /// Blur image with Gauss /// </summary> /// <param name="image"></param> /// <param name="sigma">Gaussia sigma</param> /// <param name="kernelSize">Gaussia kermel</param> /// <returns></returns> public static Bitmap Gauss(this Image image, double sigma, int kernelSize) { GaussianBlur blur = new GaussianBlur(sigma, kernelSize); return(blur.Apply(new Bitmap(image))); }
public Bitmap Blur(Bitmap image) { GaussianBlur filter = new GaussianBlur(4, 20); return(filter.Apply(image)); }
//Blob Detection private Bitmap BlobDetection(Bitmap _bitmapSourceImage) { switch (iColorMode) { case 1: //_colorFilter.CenterColor = new RGB(230, 30, 30); iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; case 2: iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; case 3: iRedValue = sbRedColor.Value; iBlueValue = sbBlueColor.Value; iGreenValue = sbGreenColor.Value; _colorFilter.CenterColor = new RGB((byte)iRedValue, (byte)iGreenValue, (byte)iBlueValue); _colorFilter.Radius = (short)iRadius; _colorFilterImage = _colorFilter.Apply(_bitmapSourceImage); break; } Grayscale _grayscale = new Grayscale(0.2125, 0.7154, 0.0721); _bitmapGreyImage = _grayscale.Apply(_colorFilterImage); //create a edge detector instance if (_blurFlag == true) { //Blur _blurfilter = new Blur(); GaussianBlur _blurfilter = new GaussianBlur(); _bitmapBlurImage = _blurfilter.Apply(_bitmapGreyImage); _bitmapEdgeImage = _edgeFilter.Apply(_bitmapBlurImage); } else if (_blurFlag == false) { _bitmapEdgeImage = _edgeFilter.Apply(_bitmapGreyImage); } Threshold _threshold = new Threshold(iThreshold); _bitmapBinaryImage = _threshold.Apply(_bitmapEdgeImage); //Create a instance of blob counter algorithm BlobCounter _blobCounter = new BlobCounter(); //Configure Filter _blobCounter.MinWidth = 70; _blobCounter.MinHeight = 70; _blobCounter.FilterBlobs = true; _blobCounter.ProcessImage(_bitmapBinaryImage); Blob[] _blobPoints = _blobCounter.GetObjectsInformation(); Graphics _g = Graphics.FromImage(_bitmapSourceImage); SimpleShapeChecker _shapeChecker = new SimpleShapeChecker(); for (int i = 0; i < _blobPoints.Length; i++) { List <IntPoint> _edgePoint = _blobCounter.GetBlobsEdgePoints(_blobPoints[i]); List <IntPoint> _corners = null; AForge.Point _center; float _radius; if (_shapeChecker.IsQuadrilateral(_edgePoint, out _corners)) { Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); System.Drawing.Point[] _coordinates = ToPointsArray(_corners); int _x = _coordinates[0].X; int _y = _coordinates[0].Y; Pen _pen = new Pen(Color.Blue, ipenWidth); if (_coordinates.Length == 4) { string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); _g.DrawString(_shapeString, _font, _brush, _x, _y); _g.DrawPolygon(_pen, ToPointsArray(_corners)); } //size of rectange foreach (Rectangle rc in _rects) { ///for debug //System.Diagnostics.Debug.WriteLine( // string.Format("Rect size: ({0}, {1})", rc.Width, rc.Height)); iFeatureWidth = rc.Width; double dis = FindDistance(iFeatureWidth); _g.DrawString(dis.ToString("N2"), _font, _brush, _x, _y + 60); } } if (_shapeChecker.IsCircle(_edgePoint, out _center, out _radius)) { Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); Pen _pen = new Pen(Color.Red, ipenWidth); int _x = (int)_center.X; int _y = (int)_center.Y; _g.DrawString(_shapeString, _font, _brush, _x, _y); _g.DrawEllipse(_pen, (float)(_center.X - _radius), (float)(_center.Y - _radius), (float)(_radius * 2), (float)(_radius * 2)); //size of rectange foreach (Rectangle rc in _rects) { ///for debug //System.Diagnostics.Debug.WriteLine( // string.Format("Circle size: ({0}, {1})", rc.Width, rc.Height)); iFeatureWidth = rc.Width; double dis = FindDistance(iFeatureWidth); //textBox1.Text = dis.ToString("N2"); _g.DrawString(dis.ToString("N2"), _font, _brush, _x, _y + 60); } } if (_shapeChecker.IsTriangle(_edgePoint, out _corners)) { Rectangle[] _rects = _blobCounter.GetObjectsRectangles(); string _shapeString = "" + _shapeChecker.CheckShapeType(_edgePoint); Pen _pen = new Pen(Color.Green, ipenWidth); int _x = (int)_center.X; int _y = (int)_center.Y; _g.DrawString(_shapeString, _font, _brush, _x, _y); _g.DrawPolygon(_pen, ToPointsArray(_corners)); //size of rectange foreach (Rectangle rc in _rects) { ///for debug //System.Diagnostics.Debug.WriteLine( // string.Format("Triangle Size: ({0}, {1})", rc.Width, rc.Height)); iFeatureWidth = rc.Width; double dis = FindDistance(iFeatureWidth); //textBox1.Text = dis.ToString("N2"); _g.DrawString(dis.ToString("N2"), _font, _brush, _x, _y + 60); } } } return(_bitmapSourceImage); }
public override Bitmap ApplyFilter(List <Bitmap> bitmap) { GaussianBlur filter = new GaussianBlur(Sigma, Radius); return(filter.Apply(bitmap[0])); }