@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats.Tga ;
using SixLabors.ImageSharp.PixelFormats ;
using SixLabors.ImageSharp.Processing ;
using SixLabors.ImageSharp.Processing.Processors.Binarization ;
@ -15,10 +14,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact]
public void AdaptiveThreshold_UsesDefaults_Works ( )
{
// arrange
var expectedThresholdLimit = . 8 5f ;
Color expectedUpper = Color . White ;
Color expectedLower = Color . Black ;
// act
this . operations . AdaptiveThreshold ( ) ;
// assert
AdaptiveThresholdProcessor p = this . Verify < AdaptiveThresholdProcessor > ( ) ;
Assert . Equal ( expectedThresholdLimit , p . ThresholdLimit ) ;
Assert . Equal ( expectedUpper , p . Upper ) ;
@ -28,8 +32,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact]
public void AdaptiveThreshold_SettingThresholdLimit_Works ( )
{
// arrange
var expectedThresholdLimit = . 6 5f ;
// act
this . operations . AdaptiveThreshold ( expectedThresholdLimit ) ;
// assert
AdaptiveThresholdProcessor p = this . Verify < AdaptiveThresholdProcessor > ( ) ;
Assert . Equal ( expectedThresholdLimit , p . ThresholdLimit ) ;
Assert . Equal ( Color . White , p . Upper ) ;
@ -39,9 +48,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact]
public void AdaptiveThreshold_SettingUpperLowerThresholds_Works ( )
{
// arrange
Color expectedUpper = Color . HotPink ;
Color expectedLower = Color . Yellow ;
// act
this . operations . AdaptiveThreshold ( expectedUpper , expectedLower ) ;
// assert
AdaptiveThresholdProcessor p = this . Verify < AdaptiveThresholdProcessor > ( ) ;
Assert . Equal ( expectedUpper , p . Upper ) ;
Assert . Equal ( expectedLower , p . Lower ) ;
@ -50,16 +64,39 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact]
public void AdaptiveThreshold_SettingUpperLowerWithThresholdLimit_Works ( )
{
// arrange
var expectedThresholdLimit = . 7 7f ;
Color expectedUpper = Color . HotPink ;
Color expectedLower = Color . Yellow ;
// act
this . operations . AdaptiveThreshold ( expectedUpper , expectedLower , expectedThresholdLimit ) ;
// assert
AdaptiveThresholdProcessor p = this . Verify < AdaptiveThresholdProcessor > ( ) ;
Assert . Equal ( expectedThresholdLimit , p . ThresholdLimit ) ;
Assert . Equal ( expectedUpper , p . Upper ) ;
Assert . Equal ( expectedLower , p . Lower ) ;
}
[Fact]
public void AdaptiveThreshold_SettingUpperLowerWithThresholdLimit_WithRectangle_Works ( )
{
// arrange
var expectedThresholdLimit = . 7 7f ;
Color expectedUpper = Color . HotPink ;
Color expectedLower = Color . Yellow ;
// act
this . operations . AdaptiveThreshold ( expectedUpper , expectedLower , expectedThresholdLimit , this . rect ) ;
// assert
AdaptiveThresholdProcessor p = this . Verify < AdaptiveThresholdProcessor > ( this . rect ) ;
Assert . Equal ( expectedThresholdLimit , p . ThresholdLimit ) ;
Assert . Equal ( expectedUpper , p . Upper ) ;
Assert . Equal ( expectedLower , p . Lower ) ;
}
[Theory]
[WithFile(TestImages.Png.Bradley01, PixelTypes.Rgba32)]
[WithFile(TestImages.Png.Bradley02, PixelTypes.Rgba32)]
@ -73,5 +110,18 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
image . CompareToReferenceOutput ( ImageComparer . Exact , provider ) ;
}
}
[Theory]
[WithFile(TestImages.Png.Bradley02, PixelTypes.Rgba32)]
public void AdaptiveThreshold_WithRectangle_Works < TPixel > ( TestImageProvider < TPixel > provider )
where TPixel : unmanaged , IPixel < TPixel >
{
using ( Image < TPixel > image = provider . GetImage ( ) )
{
image . Mutate ( img = > img . AdaptiveThreshold ( Color . White , Color . Black , new Rectangle ( 6 0 , 9 0 , 2 0 0 , 3 0 ) ) ) ;
image . DebugSave ( provider ) ;
image . CompareToReferenceOutput ( ImageComparer . Exact , provider ) ;
}
}
}
}