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);
        }
        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);
        }
Beispiel #3
0
 public void DetectEdges_WorksWithAllFilters <TPixel>(TestImageProvider <TPixel> provider, EdgeDetectionOperators detector)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         image.Mutate(x => x.DetectEdges(detector));
         image.DebugSave(provider, detector.ToString());
         image.CompareToReferenceOutput(ValidatorComparer, provider, detector.ToString());
     }
 }
 /// <summary>
 /// Detects any edges within the image.
 /// </summary>
 /// <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="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext DetectEdges(
     this IImageProcessingContext source,
     EdgeDetectionOperators filter,
     Rectangle rectangle,
     bool grayscale = true) =>
 DetectEdges(source, rectangle, GetProcessor(filter, grayscale));
 /// <summary>
 /// Detects any edges within the image.
 /// </summary>
 /// <param name="source">The image this method extends.</param>
 /// <param name="filter">The filter for detecting edges.</param>
 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
 public static IImageProcessingContext DetectEdges(
     this IImageProcessingContext source,
     EdgeDetectionOperators filter) =>
 DetectEdges(source, GetProcessor(filter, true));
Beispiel #6
0
        public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet <TProcessor>(TestType <TProcessor> type, EdgeDetectionOperators filter)
            where TProcessor : EdgeDetectorProcessor
        {
            bool grey = (int)filter % 2 == 0;

            this.operations.DetectEdges(filter, grey);

            // TODO: Enable once we have updated the images
            var processor = this.Verify <TProcessor>();

            Assert.Equal(grey, processor.Grayscale);
        }
Beispiel #7
0
        public void DetectEdges_filter_SobelProcessorDefaultsSet <TProcessor>(TestType <TProcessor> type, EdgeDetectionOperators filter)
            where TProcessor : EdgeDetectorProcessor
        {
            this.operations.DetectEdges(filter);

            // TODO: Enable once we have updated the images
            var processor = this.Verify <TProcessor>();

            Assert.True(processor.Grayscale);
        }
Beispiel #8
0
 public void WorksWithDiscoBuffers <TPixel>(TestImageProvider <TPixel> provider, EdgeDetectionOperators detector)
     where TPixel : struct, IPixel <TPixel>
 {
     provider.RunBufferCapacityLimitProcessorTest(
         41,
         c => c.DetectEdges(detector),
         detector);
 }
Beispiel #9
0
        public void DetectEdges_WorksWithAllFilters <TPixel>(TestImageProvider <TPixel> provider, EdgeDetectionOperators detector)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            bool          hasAlpha = provider.SourceFileOrDescription.Contains("TestPattern");
            ImageComparer comparer = hasAlpha ? TransparentComparer : OpaqueComparer;

            using (Image <TPixel> image = provider.GetImage())
            {
                image.Mutate(x => x.DetectEdges(detector));
                image.DebugSave(provider, detector.ToString());
                image.CompareToReferenceOutput(comparer, provider, detector.ToString());
            }
        }
 /// <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 IImageProcessingContext <TPixel> DetectEdges <TPixel>(this IImageProcessingContext <TPixel> source, EdgeDetectionOperators filter, Rectangle rectangle, bool grayscale = true)
     where TPixel : struct, IPixel <TPixel>
 => DetectEdges(source, rectangle, GetProcessor <TPixel>(filter, grayscale));
 /// <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>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DetectEdges <TPixel>(this IImageProcessingContext <TPixel> source, EdgeDetectionOperators filter)
     where TPixel : struct, IPixel <TPixel>
 => DetectEdges(source, GetProcessor <TPixel>(filter, true));