Browse Source

Merge branch 'master' into ImageIntegral

pull/1561/head
James Jackson-South 5 years ago
committed by GitHub
parent
commit
39ed542297
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      .gitattributes
  2. 2
      shared-infrastructure
  3. 10
      src/ImageSharp/Processing/BinaryThresholdMode.cs
  4. 32
      src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs
  5. 22
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
  6. 16
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
  7. 40
      tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs
  8. 8
      tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs

23
.gitattributes

@ -83,29 +83,20 @@
# treat as binary # treat as binary
############################################################################### ###############################################################################
*.basis binary *.basis binary
*.bmp binary
*.dds binary
*.dll binary *.dll binary
*.eot binary *.eot binary
*.exe binary *.exe binary
*.gif binary
*.jpg binary
*.ktx binary *.ktx binary
*.otf binary *.otf binary
*.pbm binary *.pbm binary
*.pdf binary *.pdf binary
*.png binary
*.ppt binary *.ppt binary
*.pptx binary *.pptx binary
*.pvr binary *.pvr binary
*.snk binary *.snk binary
*.tga binary
*.tif binary
*.tiff binary
*.ttc binary *.ttc binary
*.ttf binary *.ttf binary
*.wbmp binary *.wbmp binary
*.webp binary
*.woff binary *.woff binary
*.woff2 binary *.woff2 binary
*.xls binary *.xls binary
@ -121,4 +112,16 @@
*.pptx diff=astextplain *.pptx diff=astextplain
*.rtf diff=astextplain *.rtf diff=astextplain
*.svg diff=astextplain *.svg diff=astextplain
*.jpg,*.jpeg,*.bmp,*.gif,*.png,*.tif,*.tiff,*.tga,*.webp filter=lfs diff=lfs merge=lfs -text ###############################################################################
# Handle image files by git lfs
###############################################################################
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.bmp filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.tif filter=lfs diff=lfs merge=lfs -text
*.tiff filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.webp filter=lfs diff=lfs merge=lfs -text
*.dds filter=lfs diff=lfs merge=lfs -text

2
shared-infrastructure

@ -1 +1 @@
Subproject commit 649bdbe6050722b030d9292d3fc083cd6ffe87ba Subproject commit 06a733983486638b9e38197c7c6eb197ecac43e6

10
src/ImageSharp/Processing/BinaryThresholdColorComponent.cs → src/ImageSharp/Processing/BinaryThresholdMode.cs

@ -4,22 +4,22 @@
namespace SixLabors.ImageSharp.Processing namespace SixLabors.ImageSharp.Processing
{ {
/// <summary> /// <summary>
/// The color component to be compared to threshold. /// Selects the value to be compared to threshold.
/// </summary> /// </summary>
public enum BinaryThresholdColorComponent : int public enum BinaryThresholdMode
{ {
/// <summary> /// <summary>
/// Luminance color component according to ITU-R Recommendation BT.709. /// Compare the color luminance (according to ITU-R Recommendation BT.709).
/// </summary> /// </summary>
Luminance = 0, Luminance = 0,
/// <summary> /// <summary>
/// HSL saturation color component. /// Compare the HSL saturation of the color.
/// </summary> /// </summary>
Saturation = 1, Saturation = 1,
/// <summary> /// <summary>
/// Maximum of YCbCr chroma value, i.e. Cb and Cr distance from achromatic value. /// Compare the maximum of YCbCr chroma value, i.e. Cb and Cr distance from achromatic value.
/// </summary> /// </summary>
MaxChroma = 2, MaxChroma = 2,
} }

32
src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs

@ -19,20 +19,20 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold) public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdColorComponent.Luminance)); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdMode.Luminance));
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">Selects the value to be compared to threshold.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryThreshold( public static IImageProcessingContext BinaryThreshold(
this IImageProcessingContext source, this IImageProcessingContext source,
float threshold, float threshold,
BinaryThresholdColorComponent colorComponent) BinaryThresholdMode mode)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, colorComponent)); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, mode));
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold with /// Applies binarization to the image splitting the pixels at the given threshold with
@ -48,14 +48,14 @@ namespace SixLabors.ImageSharp.Processing
this IImageProcessingContext source, this IImageProcessingContext source,
float threshold, float threshold,
Rectangle rectangle) Rectangle rectangle)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdColorComponent.Luminance), rectangle); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdMode.Luminance), rectangle);
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">Selects the value to be compared to threshold.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
@ -63,9 +63,9 @@ namespace SixLabors.ImageSharp.Processing
public static IImageProcessingContext BinaryThreshold( public static IImageProcessingContext BinaryThreshold(
this IImageProcessingContext source, this IImageProcessingContext source,
float threshold, float threshold,
BinaryThresholdColorComponent colorComponent, BinaryThresholdMode mode,
Rectangle rectangle) Rectangle rectangle)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, colorComponent), rectangle); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, mode), rectangle);
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold with /// Applies binarization to the image splitting the pixels at the given threshold with
@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing
float threshold, float threshold,
Color upperColor, Color upperColor,
Color lowerColor) Color lowerColor)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance)); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance));
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -90,15 +90,15 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param> /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param> /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">Selects the value to be compared to threshold.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryThreshold( public static IImageProcessingContext BinaryThreshold(
this IImageProcessingContext source, this IImageProcessingContext source,
float threshold, float threshold,
Color upperColor, Color upperColor,
Color lowerColor, Color lowerColor,
BinaryThresholdColorComponent colorComponent) BinaryThresholdMode mode)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, colorComponent)); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, mode));
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold with /// Applies binarization to the image splitting the pixels at the given threshold with
@ -118,7 +118,7 @@ namespace SixLabors.ImageSharp.Processing
Color upperColor, Color upperColor,
Color lowerColor, Color lowerColor,
Rectangle rectangle) Rectangle rectangle)
=> source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance), rectangle); => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance), rectangle);
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param> /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param> /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">Selects the value to be compared to threshold.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
@ -137,8 +137,8 @@ namespace SixLabors.ImageSharp.Processing
float threshold, float threshold,
Color upperColor, Color upperColor,
Color lowerColor, Color lowerColor,
BinaryThresholdColorComponent colorComponent, BinaryThresholdMode mode,
Rectangle rectangle) => Rectangle rectangle) =>
source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, colorComponent), rectangle); source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, mode), rectangle);
} }
} }

22
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs

@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// Initializes a new instance of the <see cref="BinaryThresholdProcessor"/> class. /// Initializes a new instance of the <see cref="BinaryThresholdProcessor"/> class.
/// </summary> /// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">The color component to be compared to threshold.</param>
public BinaryThresholdProcessor(float threshold, BinaryThresholdColorComponent colorComponent) public BinaryThresholdProcessor(float threshold, BinaryThresholdMode mode)
: this(threshold, Color.White, Color.Black, colorComponent) : this(threshold, Color.White, Color.Black, mode)
{ {
} }
@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// </summary> /// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
public BinaryThresholdProcessor(float threshold) public BinaryThresholdProcessor(float threshold)
: this(threshold, Color.White, Color.Black, BinaryThresholdColorComponent.Luminance) : this(threshold, Color.White, Color.Black, BinaryThresholdMode.Luminance)
{ {
} }
@ -36,14 +36,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param> /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold.</param> /// <param name="lowerColor">The color to use for pixels that are below the threshold.</param>
/// <param name="colorComponent">The color component to be compared to threshold.</param> /// <param name="mode">The color component to be compared to threshold.</param>
public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor, BinaryThresholdColorComponent colorComponent) public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor, BinaryThresholdMode mode)
{ {
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Threshold = threshold; this.Threshold = threshold;
this.UpperColor = upperColor; this.UpperColor = upperColor;
this.LowerColor = lowerColor; this.LowerColor = lowerColor;
this.ColorComponent = colorComponent; this.Mode = mode;
} }
/// <summary> /// <summary>
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param> /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold.</param> /// <param name="lowerColor">The color to use for pixels that are below the threshold.</param>
public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor) public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor)
: this(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance) : this(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance)
{ {
} }
@ -73,10 +73,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// </summary> /// </summary>
public Color LowerColor { get; } public Color LowerColor { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether to use saturation value instead of luminance. /// Gets the <see cref="BinaryThresholdMode"/> defining the value to be compared to threshold.
/// </summary> /// </summary>
public BinaryThresholdColorComponent ColorComponent { get; } public BinaryThresholdMode Mode { get; }
/// <inheritdoc /> /// <inheritdoc />
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle)

16
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
upper, upper,
lower, lower,
threshold, threshold,
this.definition.ColorComponent, this.definition.Mode,
configuration); configuration);
ParallelRowIterator.IterateRows<RowOperation, Rgb24>( ParallelRowIterator.IterateRows<RowOperation, Rgb24>(
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
private readonly TPixel upper; private readonly TPixel upper;
private readonly TPixel lower; private readonly TPixel lower;
private readonly byte threshold; private readonly byte threshold;
private readonly BinaryThresholdColorComponent colorComponent; private readonly BinaryThresholdMode mode;
private readonly int startX; private readonly int startX;
private readonly Configuration configuration; private readonly Configuration configuration;
@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
TPixel upper, TPixel upper,
TPixel lower, TPixel lower,
byte threshold, byte threshold,
BinaryThresholdColorComponent colorComponent, BinaryThresholdMode mode,
Configuration configuration) Configuration configuration)
{ {
this.startX = startX; this.startX = startX;
@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
this.upper = upper; this.upper = upper;
this.lower = lower; this.lower = lower;
this.threshold = threshold; this.threshold = threshold;
this.colorComponent = colorComponent; this.mode = mode;
this.configuration = configuration; this.configuration = configuration;
} }
@ -96,9 +96,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
Span<TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length); Span<TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
PixelOperations<TPixel>.Instance.ToRgb24(this.configuration, rowSpan, span); PixelOperations<TPixel>.Instance.ToRgb24(this.configuration, rowSpan, span);
switch (this.colorComponent) switch (this.mode)
{ {
case BinaryThresholdColorComponent.Luminance: case BinaryThresholdMode.Luminance:
{ {
byte threshold = this.threshold; byte threshold = this.threshold;
for (int x = 0; x < rowSpan.Length; x++) for (int x = 0; x < rowSpan.Length; x++)
@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
break; break;
} }
case BinaryThresholdColorComponent.Saturation: case BinaryThresholdMode.Saturation:
{ {
float threshold = this.threshold / 255F; float threshold = this.threshold / 255F;
for (int x = 0; x < rowSpan.Length; x++) for (int x = 0; x < rowSpan.Length; x++)
@ -125,7 +125,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
break; break;
} }
case BinaryThresholdColorComponent.MaxChroma: case BinaryThresholdMode.MaxChroma:
{ {
float threshold = this.threshold / 2F; float threshold = this.threshold / 2F;
for (int x = 0; x < rowSpan.Length; x++) for (int x = 0; x < rowSpan.Length; x++)

40
tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
this.operations.BinaryThreshold(.23f); this.operations.BinaryThreshold(.23f);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Luminance, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Luminance, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
this.operations.BinaryThreshold(.93f, this.rect); this.operations.BinaryThreshold(.93f, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Luminance, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Luminance, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow); this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Luminance, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Luminance, p.Mode);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
} }
@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
{ {
this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, this.rect); this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(BinaryThresholdColorComponent.Luminance, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Luminance, p.Mode);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
@ -57,10 +57,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinarySaturationThreshold_CorrectProcessor() public void BinarySaturationThreshold_CorrectProcessor()
{ {
this.operations.BinaryThreshold(.23f, BinaryThresholdColorComponent.Saturation); this.operations.BinaryThreshold(.23f, BinaryThresholdMode.Saturation);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Saturation, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Saturation, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -68,10 +68,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinarySaturationThreshold_rect_CorrectProcessor() public void BinarySaturationThreshold_rect_CorrectProcessor()
{ {
this.operations.BinaryThreshold(.93f, BinaryThresholdColorComponent.Saturation, this.rect); this.operations.BinaryThreshold(.93f, BinaryThresholdMode.Saturation, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Saturation, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Saturation, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -79,10 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinarySaturationThreshold_CorrectProcessorWithUpperLower() public void BinarySaturationThreshold_CorrectProcessorWithUpperLower()
{ {
this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow, BinaryThresholdColorComponent.Saturation); this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow, BinaryThresholdMode.Saturation);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Saturation, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Saturation, p.Mode);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
} }
@ -90,10 +90,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinarySaturationThreshold_rect_CorrectProcessorWithUpperLower() public void BinarySaturationThreshold_rect_CorrectProcessorWithUpperLower()
{ {
this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, BinaryThresholdColorComponent.Saturation, this.rect); this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, BinaryThresholdMode.Saturation, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.Saturation, p.ColorComponent); Assert.Equal(BinaryThresholdMode.Saturation, p.Mode);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
} }
@ -101,10 +101,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinaryMaxChromaThreshold_CorrectProcessor() public void BinaryMaxChromaThreshold_CorrectProcessor()
{ {
this.operations.BinaryThreshold(.23f, BinaryThresholdColorComponent.MaxChroma); this.operations.BinaryThreshold(.23f, BinaryThresholdMode.MaxChroma);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.MaxChroma, p.ColorComponent); Assert.Equal(BinaryThresholdMode.MaxChroma, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -112,10 +112,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinaryMaxChromaThreshold_rect_CorrectProcessor() public void BinaryMaxChromaThreshold_rect_CorrectProcessor()
{ {
this.operations.BinaryThreshold(.93f, BinaryThresholdColorComponent.MaxChroma, this.rect); this.operations.BinaryThreshold(.93f, BinaryThresholdMode.MaxChroma, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.MaxChroma, p.ColorComponent); Assert.Equal(BinaryThresholdMode.MaxChroma, p.Mode);
Assert.Equal(Color.White, p.UpperColor); Assert.Equal(Color.White, p.UpperColor);
Assert.Equal(Color.Black, p.LowerColor); Assert.Equal(Color.Black, p.LowerColor);
} }
@ -123,10 +123,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinaryMaxChromaThreshold_CorrectProcessorWithUpperLower() public void BinaryMaxChromaThreshold_CorrectProcessorWithUpperLower()
{ {
this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow, BinaryThresholdColorComponent.MaxChroma); this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow, BinaryThresholdMode.MaxChroma);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>();
Assert.Equal(.23f, p.Threshold); Assert.Equal(.23f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.MaxChroma, p.ColorComponent); Assert.Equal(BinaryThresholdMode.MaxChroma, p.Mode);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
} }
@ -134,10 +134,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization
[Fact] [Fact]
public void BinaryMaxChromaThreshold_rect_CorrectProcessorWithUpperLower() public void BinaryMaxChromaThreshold_rect_CorrectProcessorWithUpperLower()
{ {
this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, BinaryThresholdColorComponent.MaxChroma, this.rect); this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, BinaryThresholdMode.MaxChroma, this.rect);
BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect); BinaryThresholdProcessor p = this.Verify<BinaryThresholdProcessor>(this.rect);
Assert.Equal(.93f, p.Threshold); Assert.Equal(.93f, p.Threshold);
Assert.Equal(BinaryThresholdColorComponent.MaxChroma, p.ColorComponent); Assert.Equal(BinaryThresholdMode.MaxChroma, p.Mode);
Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.HotPink, p.UpperColor);
Assert.Equal(Color.Yellow, p.LowerColor); Assert.Equal(Color.Yellow, p.LowerColor);
} }

8
tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs

@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.Saturation)); image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.Saturation));
image.DebugSave(provider, value); image.DebugSave(provider, value);
image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo));
} }
@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{ {
var bounds = new Rectangle(image.Width / 8, image.Height / 8, 6 * image.Width / 8, 6 * image.Width / 8); var bounds = new Rectangle(image.Width / 8, image.Height / 8, 6 * image.Width / 8, 6 * image.Width / 8);
image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.Saturation, bounds)); image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.Saturation, bounds));
image.DebugSave(provider, value); image.DebugSave(provider, value);
image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo));
} }
@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{ {
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.MaxChroma)); image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.MaxChroma));
image.DebugSave(provider, value); image.DebugSave(provider, value);
if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework) if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework)
@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{ {
var bounds = new Rectangle(image.Width / 8, image.Height / 8, 6 * image.Width / 8, 6 * image.Width / 8); var bounds = new Rectangle(image.Width / 8, image.Height / 8, 6 * image.Width / 8, 6 * image.Width / 8);
image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.MaxChroma, bounds)); image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.MaxChroma, bounds));
image.DebugSave(provider, value); image.DebugSave(provider, value);
if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework) if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework)

Loading…
Cancel
Save