Browse Source

Blur, Sharpen

af/merge-core
James Jackson-South 9 years ago
parent
commit
f7b8491e60
  1. 53
      tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs
  2. 31
      tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs
  3. 31
      tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs
  4. 57
      tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs

53
tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs

@ -0,0 +1,53 @@
// <copyright file="BoxBlurTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using Xunit;
public class BoxBlurTest : FileTestBase
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
{
3,
5
};
[Theory]
[WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelTypes)]
public void ImageShouldApplyBoxBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.BoxBlur(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelTypes)]
public void ImageShouldApplyBoxBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = new Image<TPixel>(source))
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.BoxBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source);
}
}
}
}

31
tests/ImageSharp.Tests/Processors/Filters/GaussianBlurTest.cs → tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs

@ -3,48 +3,49 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Tests namespace ImageSharp.Tests.Processing.Convolution
{ {
using System.IO;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using Xunit; using Xunit;
public class GaussianBlurTest public class GaussianBlurTest : FileTestBase
{ {
public static readonly TheoryData<int> GaussianBlurValues public static readonly TheoryData<int> GaussianBlurValues
= new TheoryData<int> = new TheoryData<int>
{ {
3 , 3,
5 , 5
}; };
[Theory] [Theory]
[WithTestPatternImages(nameof(GaussianBlurValues), 320, 240, PixelTypes.StandardImageClass)] [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelTypes)]
public void ImageShouldApplyGaussianBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value) public void ImageShouldApplyGaussianBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
image.GaussianBlur(value) image.GaussianBlur(value)
.DebugSave(provider, value.ToString()); .DebugSave(provider, value, Extensions.Bmp);
} }
} }
[Theory] [Theory]
[WithTestPatternImages(nameof(GaussianBlurValues), 320, 240, PixelTypes.StandardImageClass)] [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelTypes)]
public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> source = provider.GetImage()) using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source)) using (var image = new Image<TPixel>(source))
{ {
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.GaussianBlur(value, rect)
.DebugSave(provider, value.ToString()); image.GaussianBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// lets draw identical shapes over the blured areas and ensure that it didn't change the outer area // Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, rect); image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, rect); source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source); ImageComparer.CheckSimilarity(image, source);
} }
} }

31
tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs → tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs

@ -3,10 +3,10 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Tests namespace ImageSharp.Tests.Processing.Convolution
{ {
using System.IO;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using Xunit; using Xunit;
public class GaussianSharpenTest : FileTestBase public class GaussianSharpenTest : FileTestBase
@ -14,37 +14,38 @@ namespace ImageSharp.Tests
public static readonly TheoryData<int> GaussianSharpenValues public static readonly TheoryData<int> GaussianSharpenValues
= new TheoryData<int> = new TheoryData<int>
{ {
3 , 3,
5 , 5
}; };
[Theory] [Theory]
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)] [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelTypes)]
public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value) public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
image.GaussianSharpen(value) image.GaussianSharpen(value)
.DebugSave(provider, value.ToString()); .DebugSave(provider, value, Extensions.Bmp);
} }
} }
[Theory] [Theory]
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)] [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelTypes)]
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value) public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> source = provider.GetImage()) using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source)) using (var image = new Image<TPixel>(source))
{ {
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.GaussianSharpen(value, rect)
.DebugSave(provider, value.ToString()); image.GaussianSharpen(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// lets draw identical shapes over the Sharpened areas and ensure that it didn't change the outer area // Draw identical shapes over the bounded and compare to ensure changes are constrained.
image.Fill(NamedColors<TPixel>.HotPink, rect); image.Fill(NamedColors<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, rect); source.Fill(NamedColors<TPixel>.HotPink, bounds);
ImageComparer.CheckSimilarity(image, source); ImageComparer.CheckSimilarity(image, source);
} }
} }

57
tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs

@ -1,57 +0,0 @@
// <copyright file="BoxBlurTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BoxBlurTest : FileTestBase
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
{
3 ,
5 ,
};
[Theory]
[MemberData(nameof(BoxBlurValues))]
public void ImageShouldApplyBoxBlurFilter(int value)
{
string path = this.CreateOutputDirectory("BoxBlur");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BoxBlur(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(BoxBlurValues))]
public void ImageShouldApplyBoxBlurFilterInBox(int value)
{
string path = this.CreateOutputDirectory("BoxBlur");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BoxBlur(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}
Loading…
Cancel
Save