Exemple #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);
        }
Exemple #2
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));
        }
Exemple #3
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);
        }