Browse Source

validating tests for Convolution processors

af/merge-core
Anton Firszov 7 years ago
parent
commit
01ae31cd14
  1. 2
      src/ImageSharp/Common/Helpers/Vector4Utils.cs
  2. 2
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs
  3. 56
      tests/ImageSharp.Tests/Processing/Processors/Convolution/Basic1ParameterConvolutionTests.cs
  4. 44
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs
  5. 19
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  6. 35
      tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs
  7. 40
      tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs
  8. 2
      tests/Images/External

2
src/ImageSharp/Common/Helpers/Vector4Utils.cs

@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp
}
/// <summary>
/// Bulk variant of <see cref="Transform(ref Vector4, ref ColorMatrix)"/>
/// Bulk variant of <see cref="Transform(ref Vector4, ref ColorMatrix)"/>.
/// </summary>
/// <param name="vectors">The span of vectors</param>
/// <param name="matrix">The transformation matrix.</param>

2
src/ImageSharp/Processing/Processors/Convolution/EdgeDetector2DProcessor.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
public DenseMatrix<float> KernelY { get; }
/// <inheritdoc/>
public bool Grayscale { get; set; }
public bool Grayscale { get; }
/// <inheritdoc />
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)

56
tests/ImageSharp.Tests/Processing/Processors/Convolution/Basic1ParameterConvolutionTests.cs

@ -0,0 +1,56 @@
// // Copyright (c) Six Labors and contributors.
// // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
[GroupOutput("Convolution")]
public abstract class Basic1ParameterConvolutionTests
{
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05F);
public static readonly TheoryData<int> Values = new TheoryData<int> { 3, 5 };
public static readonly string[] InputImages =
{
TestImages.Bmp.Car,
TestImages.Png.CalliphoraPartial
};
[Theory]
[WithFileCollection(nameof(InputImages), nameof(Values), PixelTypes.Rgba32)]
public void OnFullImage<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
provider.Utility.TestGroupName = this.GetType().Name;
provider.RunValidatingProcessorTest(
x => this.Apply(x, value),
value,
ValidatorComparer);
}
[Theory]
[WithFileCollection(nameof(InputImages), nameof(Values), PixelTypes.Rgba32)]
public void InBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
provider.Utility.TestGroupName = this.GetType().Name;
provider.RunRectangleConstrainedValidatingProcessorTest(
(x, rect) => this.Apply(x, value, rect),
value,
ValidatorComparer);
}
protected abstract void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value)
where TPixel : struct, IPixel<TPixel>;
protected abstract void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds)
where TPixel : struct, IPixel<TPixel>;
}
}

44
tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs

@ -1,51 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class BoxBlurTest : FileTestBase
[GroupOutput("Convolution")]
public class BoxBlurTest : Basic1ParameterConvolutionTests
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
{
3,
5
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)]
public void ImageShouldApplyBoxBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.BoxBlur(value));
image.DebugSave(provider, value);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)]
public void ImageShouldApplyBoxBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = source.Clone())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.BoxBlur(value, bounds));
image.DebugSave(provider, value);
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value) => ctx.BoxBlur(value);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
}
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds) =>
ctx.BoxBlur(value, bounds);
}
}

19
tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs

@ -10,13 +10,16 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class DetectEdgesTest : FileTestBase
[GroupOutput("Convolution")]
public class DetectEdgesTest
{
// I think our comparison is not accurate enough (nor can be) for RgbaVector.
// The image pixels are identical according to BeyondCompare.
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.0456F);
public static readonly string[] CommonTestImages = { TestImages.Png.Bike };
public static readonly string[] TestImages = { Tests.TestImages.Png.Bike };
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
public static readonly TheoryData<EdgeDetectionOperators> DetectEdgesFilters = new TheoryData<EdgeDetectionOperators>
{
@ -33,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
};
[Theory]
[WithFileCollection(nameof(CommonTestImages), DefaultPixelType)]
[WithFileCollection(nameof(TestImages), PixelTypes.Rgba32)]
public void DetectEdges_WorksOnWrappedMemoryImage<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -49,8 +52,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
}
[Theory]
[WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, DefaultPixelType)]
[WithFileCollection(nameof(CommonTestImages), nameof(DetectEdgesFilters), DefaultPixelType)]
[WithTestPatternImages(nameof(DetectEdgesFilters), 100, 100, PixelTypes.Rgba32)]
[WithFileCollection(nameof(TestImages), nameof(DetectEdgesFilters), PixelTypes.Rgba32)]
public void DetectEdges_WorksWithAllFilters<TPixel>(TestImageProvider<TPixel> provider, EdgeDetectionOperators detector)
where TPixel : struct, IPixel<TPixel>
{
@ -63,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
}
[Theory]
[WithFileCollection(nameof(CommonTestImages), CommonNonDefaultPixelTypes)]
[WithFileCollection(nameof(TestImages), CommonNonDefaultPixelTypes)]
public void DetectEdges_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -76,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
}
[Theory]
[WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
[WithFile(Tests.TestImages.Gif.Giphy, PixelTypes.Rgba32)]
public void DetectEdges_IsAppliedToAllFrames<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -88,7 +91,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
}
[Theory]
[WithFileCollection(nameof(CommonTestImages), DefaultPixelType)]
[WithFileCollection(nameof(TestImages), PixelTypes.Rgba32)]
public void DetectEdges_InBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

35
tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs

@ -10,37 +10,12 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class GaussianBlurTest : FileTestBase
[GroupOutput("Convolution")]
public class GaussianBlurTest : Basic1ParameterConvolutionTests
{
public static readonly TheoryData<int> GaussianBlurValues = new TheoryData<int> { 3, 5 };
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value) => ctx.GaussianBlur(value);
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)]
public void ImageShouldApplyGaussianBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.GaussianBlur(value));
image.DebugSave(provider, value);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)]
public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = source.Clone())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.GaussianBlur(value, bounds));
image.DebugSave(provider, value);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
}
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds) =>
ctx.GaussianBlur(value, bounds);
}
}

40
tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs

@ -9,42 +9,12 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
{
public class GaussianSharpenTest : FileTestBase
[GroupOutput("Convolution")]
public class GaussianSharpenTest : Basic1ParameterConvolutionTests
{
public static readonly TheoryData<int> GaussianSharpenValues
= new TheoryData<int>
{
3,
5
};
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value) => ctx.GaussianSharpen(value);
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.GaussianSharpen(value));
image.DebugSave(provider, value);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = source.Clone())
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.GaussianSharpen(value, bounds));
image.DebugSave(provider, value);
ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
}
}
protected override void Apply<TPixel>(IImageProcessingContext<TPixel> ctx, int value, Rectangle bounds) =>
ctx.GaussianSharpen(value, bounds);
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit 1ca515499663e8b0b7c924a49b8d212f7447bdb0
Subproject commit 2a3247c6da18b8a96cc71e1f2862ac03f2a42315
Loading…
Cancel
Save