/// <summary> /// Executes specified filter on an image (without using parallel processor). /// </summary> /// <param name="img">Image.</param> /// <param name="filter">AForge <see cref="BaseInPlacePartialFilter"/>.</param> /// <param name="inPlace">Execute in place or not. Please use this switch correctly as some filters may not be processed correctly.</param> public static Image <TColor, TDepth> ApplyFilter <TColor, TDepth>(this Image <TColor, TDepth> img, BaseInPlacePartialFilter filter, bool inPlace = false) where TColor : IColor where TDepth : struct { return(ApplyFilter <TColor, TDepth, BaseInPlacePartialFilter>(img, filter, inPlace)); }
/// <summary>Handles the Click event of the Process button which crops the main image and applies the filter stack to generate the output image.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void cmdProcess_Click(object sender, EventArgs e) { if (!_placed) { return; } if (pcFullImage.Image == null) { return; } Bitmap b = new Bitmap(pbSource.Width, pbSource.Height); Graphics g = Graphics.FromImage(b); g.Clear(Color.White); g.DrawImage(pcFullImage.Image, new Rectangle(0, 0, pbSource.Width, pbSource.Height), _selection.X, _selection.Y, _selection.Width, _selection.Height, GraphicsUnit.Pixel); g.Dispose(); pbSource.Image = b; if (filterStack.Count != 0) { b = filterStack.Apply(b); } var sc = new SaturationCorrection(); if (sc.FormatTranslations.ContainsKey(b.PixelFormat)) { sc.AdjustValue = hsbSaturation.Value / 100.0f; // apply the filter sc.ApplyInPlace(b); } Bitmap greyb = null; if (AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.FormatTranslations.ContainsKey(b.PixelFormat)) { greyb = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(b); } else { this.Text = "Cannot convert to greyscale"; greyb = b; } var bc = new BrightnessCorrection(); if (bc.FormatTranslations.ContainsKey(b.PixelFormat)) { bc.AdjustValue = hsbBrightness.Value; bc.ApplyInPlace(greyb); } var cc = new ContrastCorrection(); if (cc.FormatTranslations.ContainsKey(b.PixelFormat)) { cc.Factor = hsbContrast.Value; cc.ApplyInPlace(greyb); } if (filterStack.Count == 0) { var sharpen = new Sharpen(); if (sharpen.FormatTranslations.ContainsKey(b.PixelFormat)) { sharpen.ApplyInPlace(greyb); } } if (chkInvert.Checked) { var invert = new Invert(); invert.ApplyInPlace(greyb); } pbInt.Image = greyb; b = greyb; //BaseInPlacePartialFilter filter = new AForge.Imaging.Filters.FloydSteinbergDithering(); BaseInPlacePartialFilter filter = null; if (cmbAlgorithm.SelectedItem != null && cmbAlgorithm.SelectedItem is AForge.Imaging.Filters.BaseInPlacePartialFilter) { filter = cmbAlgorithm.SelectedItem as AForge.Imaging.Filters.BaseInPlacePartialFilter; } if (filter == null) { filter = new AForge.Imaging.Filters.SierraDithering(); } if (filter.FormatTranslations.ContainsKey(b.PixelFormat)) { var ditheredb = filter.Apply(b); pbDest.Image = ditheredb; this.Text = "Badger!"; } else { this.Text = "Cannot dither this image!"; } }
/// <summary> /// Executes specified filter on an image (without using parallel processor). /// </summary> /// <param name="img">Image.</param> /// <param name="filter">AForge <see cref="BaseInPlacePartialFilter"/>.</param> /// <param name="inPlace">Execute in place or not. Please use this switch correctly as some filters may not be processed correctly.</param> public static TColor[,] ApplyFilter <TColor>(this TColor[,] img, BaseInPlacePartialFilter filter, bool inPlace = false) where TColor : struct, IColor { return(ApplyFilter <TColor, BaseInPlacePartialFilter>(img, filter, inPlace)); }