示例#1
0
        /// <summary>
        /// Detects any edges within the image.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="filter">The filter for detecting edges.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
        /// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
        public static Image <TColor, TPacked> DetectEdges <TColor, TPacked>(this Image <TColor, TPacked> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct
        {
            IEdgeDetectorProcessor <TColor, TPacked> processor;

            switch (filter)
            {
            case EdgeDetection.Kayyali:
                processor = new KayyaliSampler <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Kirsch:
                processor = new KirschProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Lapacian3X3:
                processor = new Laplacian3X3Processor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Lapacian5X5:
                processor = new Laplacian5X5Processor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.LaplacianOfGaussian:
                processor = new LaplacianOfGaussianProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Prewitt:
                processor = new PrewittProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.RobertsCross:
                processor = new RobertsCrossProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Robinson:
                processor = new RobinsonProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Scharr:
                processor = new ScharrProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;

            default:
                processor = new SobelProcessor <TColor, TPacked> {
                    Grayscale = grayscale
                };
                break;
            }

            return(DetectEdges(source, rectangle, processor));
        }
示例#2
0
        private static IEdgeDetectorProcessor <TPixel> GetProcessor <TPixel>(EdgeDetection filter, bool grayscale)
            where TPixel : struct, IPixel <TPixel>
        {
            IEdgeDetectorProcessor <TPixel> processor;

            switch (filter)
            {
            case EdgeDetection.Kayyali:
                processor = new KayyaliProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Kirsch:
                processor = new KirschProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Lapacian3X3:
                processor = new Laplacian3X3Processor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Lapacian5X5:
                processor = new Laplacian5X5Processor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.LaplacianOfGaussian:
                processor = new LaplacianOfGaussianProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Prewitt:
                processor = new PrewittProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.RobertsCross:
                processor = new RobertsCrossProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Robinson:
                processor = new RobinsonProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            case EdgeDetection.Scharr:
                processor = new ScharrProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;

            default:
                processor = new SobelProcessor <TPixel> {
                    Grayscale = grayscale
                };
                break;
            }

            return(processor);
        }