public static Bitmap gaussianBlur(this Bitmap bitmap, int blur) { // create filter AForge.Imaging.Filters.GaussianBlur filter = new AForge.Imaging.Filters.GaussianBlur(Convert.ToDouble(blur), 9); // apply the filter return(filter.Apply(bitmap)); }
private void init() { gb = new AForge.Imaging.Filters.GaussianBlur(); cc = new AForge.Imaging.Filters.ContrastCorrection(); bc = new AForge.Imaging.Filters.BrightnessCorrection(); th.Minimum = 0; th.Maximum = 277695; th.Value = 270000; }
private void init() { gb = new AForge.Imaging.Filters.GaussianBlur(); cc = new AForge.Imaging.Filters.ContrastCorrection(); bc = new AForge.Imaging.Filters.BrightnessCorrection(); th.Minimum = 0; th.Maximum = 277695; th.Value = 270000; try { src = Program.pbitmap; draw_image(); } catch (Exception xk) { MessageBox.Show("Error displaying source"); this.Close(); } }
/// <summary> /// In Fill Mode, we will blur and fill the background /// </summary> /// <param name="file"></param> /// <param name="parameter"></param> private static void FillBackground(Image source, Graphics target, ImageFiltrationParameters parameter) { if (parameter.Mode != ImageResizeMode.FitWithBg) { return; } // get blurred image and draw using fit width mode var blurFilter = new AForge.Imaging.Filters.GaussianBlur(8, 10); using (var blurred = blurFilter.Apply((Bitmap)source)) { var p = new ImageFiltrationParameters(source, parameter.TargetWidth, parameter.TargetHeight, ImageResizeMode.Fill); var darken = new AForge.Imaging.Filters.BrightnessCorrection(-100); darken.ApplyInPlace(blurred); target.DrawImage(blurred, p.ImageOffsetAndSize.Left, p.ImageOffsetAndSize.Top, p.ImageOffsetAndSize.Width, p.ImageOffsetAndSize.Height); } }
public void GaussianBlur() { // apply filter AForge.Imaging.Filters.GaussianBlur gauss = new AForge.Imaging.Filters.GaussianBlur(); Texture = gauss.Apply(this.Texture); }
private void Go_Click(object sender, RoutedEventArgs e) { try { System.Windows.Media.Imaging.BitmapImage imagesource = imageBox.Source as System.Windows.Media.Imaging.BitmapImage; if (imageBox.Source == null) { System.Windows.MessageBox.Show("Add your image to the Image 1 box!"); return; } System.Drawing.Bitmap image = BmpImage2Bmp(imagesource); System.Windows.Media.Imaging.BitmapImage final = new System.Windows.Media.Imaging.BitmapImage(); if (!AForge.Imaging.Image.IsGrayscale(image)) { AForge.Imaging.Filters.ExtractChannel Grayer = new AForge.Imaging.Filters.ExtractChannel(0); image = Grayer.Apply(image); } if (Threshold.IsChecked == true) { imageBox.Source = null; AForge.Imaging.Filters.Threshold threshold = new AForge.Imaging.Filters.Threshold((int)slider.Value); threshold.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (GaussianFilter.IsChecked == true) { AForge.Imaging.Filters.GaussianBlur Gauss = new AForge.Imaging.Filters.GaussianBlur(); Gauss.Sigma = GaussSigma_Slide.Value; Gauss.Size = (int)GaussSize_Slide.Value; AForge.Imaging.UnmanagedImage unmanagedImage = AForge.Imaging.UnmanagedImage.FromManagedImage(image); AForge.Imaging.UnmanagedImage Dst = unmanagedImage.Clone(); Gauss.Apply(unmanagedImage, Dst); final = Bmp2BmpImage(Dst.ToManagedImage()); } else if (HiPass.IsChecked == true) { AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen(); filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (Erode.IsChecked == true) { AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion(); filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (Invert.IsChecked == true) { AForge.Imaging.Filters.Invert filter = new AForge.Imaging.Filters.Invert(); filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (EdgeDetector.IsChecked == true) { AForge.Imaging.Filters.CannyEdgeDetector filter = new AForge.Imaging.Filters.CannyEdgeDetector(); filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (Median.IsChecked == true) { AForge.Imaging.Filters.Median filter = new AForge.Imaging.Filters.Median(); filter.Size = (int)GaussSize_Slide.Value; filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } else if (More.IsChecked == true) { if (Dilate.IsSelected) { AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation(); filter.ApplyInPlace(image); final = Bmp2BmpImage(image); } } imageBox.Source = final; TransformImage = image; boxWidth = imageBox.RenderSize.Width; boxHeight = imageBox.RenderSize.Height; } catch (Exception exc) { System.Windows.MessageBox.Show(exc.ToString()); } }
public static Bitmap gaussianBlur(this Bitmap bitmap, int blur) { AForge.Imaging.Filters.GaussianBlur filter = new AForge.Imaging.Filters.GaussianBlur(Convert.ToDouble(blur), 9); return filter.Apply(bitmap); }
public Bitmap Process(Bitmap image) { Bitmap filteredImage = convertFormatTo32(image); if (filterLevel >= 0) { filteredImage = resize(filteredImage, ImageSize.Width, ImageSize.Height); } if (filterLevel >= 1) { if (ContrastStretch) { AForge.Imaging.Filters.ContrastStretch stretcher = new AForge.Imaging.Filters.ContrastStretch(); filteredImage = stretcher.Apply(filteredImage); } if (Histogram) { AForge.Imaging.Filters.HistogramEqualization histogrammer = new AForge.Imaging.Filters.HistogramEqualization(); filteredImage = histogrammer.Apply(filteredImage); } if (Gaussian) { AForge.Imaging.Filters.GaussianBlur blurrer = new AForge.Imaging.Filters.GaussianBlur(); blurrer.Size = (int)GaussianStrength; filteredImage = blurrer.Apply(filteredImage); } if (ContrastAdjustment) { AForge.Imaging.Filters.ContrastCorrection contraster = new AForge.Imaging.Filters.ContrastCorrection(); contraster.Factor = (float)ContrastStrength; filteredImage = contraster.Apply(filteredImage); } if (Greyscale) { filteredImage = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(filteredImage); //Greyscale downgrades format // filteredImage = convertFormatTo32(filteredImage.InternalBitmap); } if (Threshold) { //filteredImage.InternalBitmap = convertFormatToGS(filteredImage.InternalBitmap); AForge.Imaging.Filters.Threshold thresholder = new AForge.Imaging.Filters.Threshold(); thresholder.ThresholdValue = (int)(((double)ThresholdStrength / 10.0) * 255.0); filteredImage = thresholder.Apply(filteredImage); } if (Bradley) { AForge.Imaging.Filters.BradleyLocalThresholding bradlifier = new AForge.Imaging.Filters.BradleyLocalThresholding(); filteredImage = bradlifier.Apply(filteredImage); } } return filteredImage; }
private void init() { Graphics g; System.Drawing.Image src; Pen p; AForge.Imaging.Filters.GaussianBlur gb; AForge.Imaging.Filters.ContrastCorrection cc; AForge.Imaging.Filters.BrightnessCorrection bc; AForge.Imaging.Filters.Threshold th; gb = new AForge.Imaging.Filters.GaussianBlur(); cc = new AForge.Imaging.Filters.ContrastCorrection(); bc = new AForge.Imaging.Filters.BrightnessCorrection(); th = new AForge.Imaging.Filters.Threshold(); // load image source src = System.Drawing.Image.FromFile(@"d:\source.png"); gb.Size = 2; cc.Factor = 40; bc.AdjustValue = -30; src = (System.Drawing.Image)(cc.Apply(bc.Apply(gb.Apply((Bitmap)src)))); pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = Graphics.FromImage(pictureBox1.Image); img = (Bitmap)pictureBox1.Image; width = img.Width; height = img.Height; blk_w = width / 9; blk_h = height / 9; g.FillRectangle(Brushes.White, pictureBox1.DisplayRectangle); g.DrawImage(src, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height), new Rectangle(0, 0, src.Width, src.Height), GraphicsUnit.Pixel); p = new Pen(Color.White, 20); for (int iy = 0; iy < 9; iy++) { g.DrawLine(p, 0, iy * blk_h, width, iy * blk_h); } g.DrawLine(p, 0, height - 1, width, height - 1); for (int ix = 0; ix < 9; ix++) { g.DrawLine(p, ix * blk_w, 0, ix * blk_w, height); } g.DrawLine(p, width - 1, 0, width - 1, height - 1); // init destination image // set destination width and height textBox1.Text = "290000"; }
private void generateHeightmap_Click(object sender, EventArgs e) { Heightmap heightmap = Heightmap.Instance; heightmap.SetDimensions((int)mapWidth.Value, (int)mapHeight.Value); int seed; if (this.enableSeed.Checked) { seed = (int)seedVal.Value; } else { seed = (new Random()).Next(); seedVal.Value = (Decimal)seed; } heightmap.DiffusionLimitedAgregation(seed, (float)(this.occupation.Value / this.occupation.Maximum), (int)this.frequency.Value); // apply gaussian pass, multiple kernel sizes sum and normalize if (gaussianEnable.Checked) { List <Bitmap> dlaCopies = new List <Bitmap>(); Bitmap dilatedBitmap = (Bitmap)heightmap.Texture.Clone(); AForge.Imaging.Filters.GaussianBlur gaussian = new AForge.Imaging.Filters.GaussianBlur(4.0, 21); AForge.Imaging.Filters.Dilatation dilatationFilter = new AForge.Imaging.Filters.Dilatation(); GaussianBlur gaus = new GaussianBlur(2); for (int i = 0; i < (int)copyCount.Value; i++) { // apply filter, first increasinly dilate the picture dilatedBitmap = dilatationFilter.Apply(dilatedBitmap); // then apply gaussian blur with an increasing radius size Bitmap blurredBitmap = (Bitmap)dilatedBitmap.Clone(); if (radialBlur.Checked) { for (int j = 0; j < (i * 3) + 1; j++) { blurredBitmap = gaussian.Apply(blurredBitmap); } } else { gaus.Radius = (int)Math.Pow(2, i + 1); blurredBitmap = gaus.ProcessImage(blurredBitmap); } dlaCopies.Add(blurredBitmap); } // add noise to final texture collections if (noiseEnabled.Checked) { dlaCopies.Add(NoiseTexture((int)perlinOctaves.Value, (double)perlinPersistence.Value, (double)perlinFreq.Value, (double)perlinAmplitude.Value)); } // normalize all blurred heightmaps Bitmap bmp = (Bitmap)heightmap.Texture.Clone(); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat); byte[] finalData = new byte[bmpData.Height * bmpData.Stride]; // sum average between all blurred pictures for (int i = 0; i < dlaCopies.Count; i++) { // AForge.Imaging.Filters addFilter = new AForge.Imaging.Filters.Add(blurredBitmap); Bitmap current = dlaCopies[i]; BitmapData currentData = current.LockBits(new Rectangle(0, 0, current.Width, current.Height), ImageLockMode.ReadOnly, current.PixelFormat); byte[] currentRawData = new byte[currentData.Height * currentData.Stride]; Marshal.Copy(currentData.Scan0, currentRawData, 0, currentData.Height * currentData.Stride); // lamba operation sums averages between blurred pictures Parallel.For(0, currentRawData.Length, index => { finalData[index] = (byte)(currentRawData[index] * 1.0f / (float)dlaCopies.Count + finalData[index]); }); } // save final raw pixel data Marshal.Copy(finalData, 0, bmpData.Scan0, finalData.Length); bmp.UnlockBits(bmpData); // store final values on heightmap heightmap.MapValues = finalData; heightmap.Texture = bmp; } // show height map, set up new values this.heightmapPicture.Height = heightmap.Height; this.heightmapPicture.Width = heightmap.Width; this.heightmapPicture.Image = heightmap.Texture; }