// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // // ReSharper disable InconsistentNaming namespace ImageSharp.Tests.Processing.Processors.Convolution { using ImageSharp.PixelFormats; using ImageSharp.Processing; using ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.Primitives; using Xunit; public class DetectEdgesTest : FileTestBase { public static readonly string[] CommonTestImages = { TestImages.Png.Bike }; public static readonly TheoryData DetectEdgesFilters = new TheoryData { EdgeDetection.Kayyali, EdgeDetection.Kirsch, EdgeDetection.Lapacian3X3, EdgeDetection.Lapacian5X5, EdgeDetection.LaplacianOfGaussian, EdgeDetection.Prewitt, EdgeDetection.RobertsCross, EdgeDetection.Robinson, EdgeDetection.Scharr, EdgeDetection.Sobel }; [Theory] [WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)] [WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)] public void DetectEdges_WorksWithAllFilters(TestImageProvider provider, EdgeDetection detector) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) { image.Mutate(x => x.DetectEdges(detector)); image.DebugSave(provider, detector.ToString(), grayscale: true); } } [Theory] [WithFileCollection(nameof(CommonTestImages), CommonNonDefaultPixelTypes)] public void DetectEdges_IsNotBoundToSinglePixelType(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) { image.Mutate(x => x.DetectEdges()); image.DebugSave(provider, grayscale: true); } } [Theory] [WithFile(TestImages.Gif.Giphy, DefaultPixelType)] public void DetectEdges_IsAppliedToAllFrames(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) { image.Mutate(x => x.DetectEdges()); image.DebugSave(provider, extension: "gif"); } } [Theory] [WithFileCollection(nameof(CommonTestImages), DefaultPixelType)] public void DetectEdges_InBox(TestImageProvider provider) where TPixel : struct, IPixel { using (Image source = provider.GetImage()) using (Image image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); image.Mutate(x => x.DetectEdges(bounds)); image.DebugSave(provider, grayscale: true); // TODO: We don't need this any longer after switching to ReferenceImages ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } }