Пример #1
0
        /// <summary>
        /// Detects any edges within the image.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</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{TPixel}"/>.</returns>
        public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
            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 DetectEdges(source, rectangle, processor);
        }
Пример #2
0
        private static IEdgeDetectorProcessor <TPixel> GetProcessor <TPixel>(EdgeDetectionOperators filter, bool grayscale)
            where TPixel : struct, IPixel <TPixel>
        {
            IEdgeDetectorProcessor <TPixel> processor;

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

            case EdgeDetectionOperators.Kirsch:
                processor = new KirschProcessor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.Laplacian3x3:
                processor = new Laplacian3x3Processor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.Laplacian5x5:
                processor = new Laplacian5x5Processor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.LaplacianOfGaussian:
                processor = new LaplacianOfGaussianProcessor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.Prewitt:
                processor = new PrewittProcessor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.RobertsCross:
                processor = new RobertsCrossProcessor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.Robinson:
                processor = new RobinsonProcessor <TPixel>(grayscale);
                break;

            case EdgeDetectionOperators.Scharr:
                processor = new ScharrProcessor <TPixel>(grayscale);
                break;

            default:
                processor = new SobelProcessor <TPixel>(grayscale);
                break;
            }

            return(processor);
        }
Пример #3
0
        private static IImageProcessor GetProcessor(EdgeDetectionOperators filter, bool grayscale)
        {
            IImageProcessor processor;

            switch (filter)
            {
            case EdgeDetectionOperators.Kayyali:
                processor = new KayyaliProcessor(grayscale);
                break;

            case EdgeDetectionOperators.Kirsch:
                processor = new KirschProcessor(grayscale);
                break;

            case EdgeDetectionOperators.Laplacian3x3:
                processor = new Laplacian3x3Processor(grayscale);
                break;

            case EdgeDetectionOperators.Laplacian5x5:
                processor = new Laplacian5x5Processor(grayscale);
                break;

            case EdgeDetectionOperators.LaplacianOfGaussian:
                processor = new LaplacianOfGaussianProcessor(grayscale);
                break;

            case EdgeDetectionOperators.Prewitt:
                processor = new PrewittProcessor(grayscale);
                break;

            case EdgeDetectionOperators.RobertsCross:
                processor = new RobertsCrossProcessor(grayscale);
                break;

            case EdgeDetectionOperators.Robinson:
                processor = new RobinsonProcessor(grayscale);
                break;

            case EdgeDetectionOperators.Scharr:
                processor = new ScharrProcessor(grayscale);
                break;

            default:
                processor = new SobelProcessor(grayscale);
                break;
            }

            return(processor);
        }
Пример #4
0
        /// <summary>
        /// Detects any edges within the image.
        /// </summary>
        /// <typeparam name="T">The pixel format.</typeparam>
        /// <typeparam name="TP">The packed format. <example>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>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image{T,TP}"/>.</returns>
        public static Image <T, TP> DetectEdges <T, TP>(this Image <T, TP> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true, ProgressEventHandler progressHandler = null)
            where T : IPackedVector <TP>
            where TP : struct
        {
            IEdgeDetectorFilter <T, TP> processor;

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

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

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

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

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

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

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

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

            default:
                processor = new ScharrProcessor <T, TP> {
                    Grayscale = grayscale
                };
                break;
            }

            return(DetectEdges(source, rectangle, processor, progressHandler));
        }