/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { Bitmap newImage = null; Image image = factory.Image; Tuple <IEdgeFilter, bool> parameters = this.DynamicParameter; IEdgeFilter filter = parameters.Item1; bool greyscale = parameters.Item2; try { ConvolutionFilter convolutionFilter = new ConvolutionFilter(filter, greyscale); // Check and assign the correct method. Don't use reflection for speed. newImage = filter is I2DEdgeFilter ? convolutionFilter.Process2DFilter((Bitmap)image) : convolutionFilter.ProcessFilter((Bitmap)image); image.Dispose(); image = newImage; } catch (Exception ex) { if (newImage != null) { newImage.Dispose(); } throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); } return(image); }
/// <summary> /// Performs the DetectEdges effect from the ImageProcessor library. /// </summary> /// <param name="image">The image with which to apply the effect.</param> /// <param name="filter">The IEdgeFilter object that will detect the edges.</param> /// <param name="greyscale">Whether or not the resulting image will be greyscale.</param> /// <returns>A new image with the DetectEdges effect applied.</returns> public Image DetectEdges(Image image, IEdgeFilter filter, bool greyscale = true) { using var factory = new ImageFactory(); factory.Load(image); factory.DetectEdges(filter, greyscale); var result = factory.Image; return(new Bitmap(result)); }
/// <summary> /// Detects the edges in the current image. /// </summary> /// <param name="filter"> /// The <see cref="IEdgeFilter"/> to detect edges with. /// </param> /// <param name="greyscale"> /// Whether to convert the image to greyscale first - Defaults to true. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory DetectEdges(IEdgeFilter filter, bool greyscale = true) { if (this.ShouldProcess) { DetectEdges detectEdges = new DetectEdges { DynamicParameter = new Tuple <IEdgeFilter, bool>(filter, greyscale) }; this.CurrentImageFormat.ApplyProcessor(detectEdges.ProcessImage, this); } return(this); }
/// <summary> /// The position in the original string where the first character of the captured substring was found. /// </summary> /// <param name="queryString"> /// The query string to search. /// </param> /// <returns> /// The zero-based starting position in the original string where the captured substring was found. /// </returns> public int MatchRegexIndex(string queryString) { this.SortOrder = int.MaxValue; Match match = this.RegexPattern.Match(queryString); if (match.Success) { this.SortOrder = match.Index; NameValueCollection queryCollection = HttpUtility.ParseQueryString(queryString); IEdgeFilter filter = (IEdgeFilter)detectors[QueryParamParser.Instance.ParseValue <string>(queryCollection["detectedges"])]; bool greyscale = QueryParamParser.Instance.ParseValue <bool>(queryCollection["greyscale"]); this.Processor.DynamicParameter = new Tuple <IEdgeFilter, bool>(filter, greyscale); } return(this.SortOrder); }
/// <summary> /// The position in the original string where the first character of the captured substring was found. /// </summary> /// <param name="queryString"> /// The query string to search. /// </param> /// <returns> /// The zero-based starting position in the original string where the captured substring was found. /// </returns> public int MatchRegexIndex(string queryString) { int index = 0; // Set the sort order to max to allow filtering. this.SortOrder = int.MaxValue; // First merge the matches so we can parse . StringBuilder stringBuilder = new StringBuilder(); foreach (Match match in this.RegexPattern.Matches(queryString)) { if (match.Success) { if (index == 0) { // Set the index on the first instance only. this.SortOrder = match.Index; stringBuilder.Append(queryString); } index += 1; } } if (this.SortOrder < int.MaxValue) { // Match syntax string toParse = stringBuilder.ToString(); IEdgeFilter filter = this.ParseFilter(toParse); bool greyscale = !GreyscaleRegex.IsMatch(toParse); this.Processor.DynamicParameter = new Tuple <IEdgeFilter, bool>(filter, greyscale); } return(this.SortOrder); }
/// <summary> /// Detects the edges in the current image. /// </summary> /// <param name="filter"> /// The <see cref="IEdgeFilter"/> to detect edges with. /// </param> /// <param name="greyscale"> /// Whether to convert the image to greyscale first - Defaults to true. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory DetectEdges(IEdgeFilter filter, bool greyscale = true) { if (this.ShouldProcess) { DetectEdges detectEdges = new DetectEdges { DynamicParameter = new Tuple<IEdgeFilter, bool>(filter, greyscale) }; this.CurrentImageFormat.ApplyProcessor(detectEdges.ProcessImage, this); } return this; }
/// <summary> /// Initializes a new instance of the <see cref="ConvolutionFilter"/> class. /// </summary> /// <param name="edgeFilter"> /// The <see cref="IEdgeFilter"/> to apply. /// </param> /// <param name="greyscale"> /// Whether to produce a greyscale output. /// </param> public ConvolutionFilter(IEdgeFilter edgeFilter, bool greyscale) { this.edgeFilter = edgeFilter; this.greyscale = greyscale; }
public void AddFilter(IEdgeFilter filter) { LocklessConcurrentAddToList(ref _filters, filter); }
/// <summary> /// Detects the edges of an image using a particular algorithm and displays the calculated outlines. /// </summary> /// <param name="this">The current ImageEditorState.</param> /// <param name="filter">The particular IEdgeFilter object that is used to perform the calculation.</param> /// <param name="greyscale">Whether or not the resulting image will be displayed as greyscale.</param> public static void DetectEdges(this ImageEditorState @this, IEdgeFilter filter, bool greyscale = true) { var newImage = ImageProcessor.Instance.DetectEdges(@this.Image, filter, greyscale); @this.Update(newImage); }
/// <summary> /// Initializes a new instance of the <see cref="ConvolutionFilter"/> class. /// </summary> /// <param name="edgeFilter"> /// The <see cref="IEdgeFilter"/> to apply. /// </param> /// <param name="greyscale"> /// Whether to produce a greyscale output. /// </param> public ConvolutionFilter(IEdgeFilter edgeFilter, bool greyscale) { _edgeFilter = edgeFilter; _greyscale = greyscale; }