mirror of https://github.com/SixLabors/ImageSharp
46 changed files with 243 additions and 152 deletions
@ -0,0 +1,47 @@ |
|||||
|
// <copyright file="BinaryThresholdTest.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.Binarization |
||||
|
{ |
||||
|
using ImageSharp.PixelFormats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
public class BinaryThresholdTest : FileTestBase |
||||
|
{ |
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes, .75F)] |
||||
|
public void ImageShouldApplyBinaryThresholdFilter<TPixel>(TestImageProvider<TPixel> provider, float value) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.BinaryThreshold(value) |
||||
|
.DebugSave(provider, null, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes, .75F)] |
||||
|
public void ImageShouldApplyBinaryThresholdInBox<TPixel>(TestImageProvider<TPixel> provider, float 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.BinaryThreshold(value, bounds) |
||||
|
.DebugSave(provider, null, 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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,57 +0,0 @@ |
|||||
// <copyright file="BinaryThresholdTest.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 BinaryThresholdTest : FileTestBase |
|
||||
{ |
|
||||
public static readonly TheoryData<float> BinaryThresholdValues |
|
||||
= new TheoryData<float> |
|
||||
{ |
|
||||
.25f , |
|
||||
.75f , |
|
||||
}; |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(BinaryThresholdValues))] |
|
||||
public void ImageShouldApplyBinaryThresholdFilter(float value) |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("BinaryThreshold"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName(value); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
image.BinaryThreshold(value).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[MemberData(nameof(BinaryThresholdValues))] |
|
||||
public void ImageShouldApplyBinaryThresholdInBox(float value) |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("BinaryThreshold"); |
|
||||
|
|
||||
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.BinaryThreshold(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue