diff --git a/src/ImageSharp/Processing/BinaryThresholdColorComponent.cs b/src/ImageSharp/Processing/BinaryThresholdMode.cs similarity index 53% rename from src/ImageSharp/Processing/BinaryThresholdColorComponent.cs rename to src/ImageSharp/Processing/BinaryThresholdMode.cs index e46070dcb6..0ca1f08d14 100644 --- a/src/ImageSharp/Processing/BinaryThresholdColorComponent.cs +++ b/src/ImageSharp/Processing/BinaryThresholdMode.cs @@ -4,22 +4,22 @@ namespace SixLabors.ImageSharp.Processing { /// - /// The color component to be compared to threshold. + /// Selects the value to be compared to threshold. /// - public enum BinaryThresholdColorComponent : int + public enum BinaryThresholdMode { /// - /// Luminance color component according to ITU-R Recommendation BT.709. + /// Compare the color luminance (according to ITU-R Recommendation BT.709). /// Luminance = 0, /// - /// HSL saturation color component. + /// Compare the HSL saturation of the color. /// Saturation = 1, /// - /// 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. /// MaxChroma = 2, } diff --git a/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs b/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs index 11c6433f22..5132fd731d 100644 --- a/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs +++ b/src/ImageSharp/Processing/Extensions/Binarization/BinaryThresholdExtensions.cs @@ -19,20 +19,20 @@ public static class BinaryThresholdExtensions /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The to allow chaining of operations. public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdColorComponent.Luminance)); + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdMode.Luminance)); /// /// Applies binarization to the image splitting the pixels at the given threshold. /// /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. - /// The color component to be compared to threshold. + /// Selects the value to be compared to threshold. /// The to allow chaining of operations. public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, - BinaryThresholdColorComponent colorComponent) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, colorComponent)); + BinaryThresholdMode mode) + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, mode)); /// /// Applies binarization to the image splitting the pixels at the given threshold with @@ -48,14 +48,14 @@ public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, Rectangle rectangle) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdColorComponent.Luminance), rectangle); + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, BinaryThresholdMode.Luminance), rectangle); /// /// Applies binarization to the image splitting the pixels at the given threshold. /// /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. - /// The color component to be compared to threshold. + /// Selects the value to be compared to threshold. /// /// The structure that specifies the portion of the image object to alter. /// @@ -63,9 +63,9 @@ public static IImageProcessingContext BinaryThreshold( public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, - BinaryThresholdColorComponent colorComponent, + BinaryThresholdMode mode, Rectangle rectangle) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, colorComponent), rectangle); + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, mode), rectangle); /// /// Applies binarization to the image splitting the pixels at the given threshold with @@ -81,7 +81,7 @@ public static IImageProcessingContext BinaryThreshold( float threshold, Color upperColor, Color lowerColor) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance)); + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance)); /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -90,15 +90,15 @@ public static IImageProcessingContext BinaryThreshold( /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The color to use for pixels that are above the threshold. /// The color to use for pixels that are below the threshold - /// The color component to be compared to threshold. + /// Selects the value to be compared to threshold. /// The to allow chaining of operations. public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, Color upperColor, Color lowerColor, - BinaryThresholdColorComponent colorComponent) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, colorComponent)); + BinaryThresholdMode mode) + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, mode)); /// /// Applies binarization to the image splitting the pixels at the given threshold with @@ -118,7 +118,7 @@ public static IImageProcessingContext BinaryThreshold( Color upperColor, Color lowerColor, Rectangle rectangle) - => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance), rectangle); + => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance), rectangle); /// /// Applies binarization to the image splitting the pixels at the given threshold. @@ -127,7 +127,7 @@ public static IImageProcessingContext BinaryThreshold( /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The color to use for pixels that are above the threshold. /// The color to use for pixels that are below the threshold - /// The color component to be compared to threshold. + /// Selects the value to be compared to threshold. /// /// The structure that specifies the portion of the image object to alter. /// @@ -137,8 +137,8 @@ public static IImageProcessingContext BinaryThreshold( float threshold, Color upperColor, Color lowerColor, - BinaryThresholdColorComponent colorComponent, + BinaryThresholdMode mode, Rectangle rectangle) => - source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, colorComponent), rectangle); + source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, mode), rectangle); } } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index 24a3e6c1da..77fc6938d9 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -14,9 +14,9 @@ public class BinaryThresholdProcessor : IImageProcessor /// Initializes a new instance of the class. /// /// The threshold to split the image. Must be between 0 and 1. - /// The color component to be compared to threshold. - public BinaryThresholdProcessor(float threshold, BinaryThresholdColorComponent colorComponent) - : this(threshold, Color.White, Color.Black, colorComponent) + /// The color component to be compared to threshold. + public BinaryThresholdProcessor(float threshold, BinaryThresholdMode mode) + : this(threshold, Color.White, Color.Black, mode) { } @@ -26,7 +26,7 @@ public BinaryThresholdProcessor(float threshold, BinaryThresholdColorComponent c /// /// The threshold to split the image. Must be between 0 and 1. public BinaryThresholdProcessor(float threshold) - : this(threshold, Color.White, Color.Black, BinaryThresholdColorComponent.Luminance) + : this(threshold, Color.White, Color.Black, BinaryThresholdMode.Luminance) { } @@ -36,14 +36,14 @@ public BinaryThresholdProcessor(float threshold) /// The threshold to split the image. Must be between 0 and 1. /// The color to use for pixels that are above the threshold. /// The color to use for pixels that are below the threshold. - /// The color component to be compared to threshold. - public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor, BinaryThresholdColorComponent colorComponent) + /// The color component to be compared to threshold. + public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor, BinaryThresholdMode mode) { Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); this.Threshold = threshold; this.UpperColor = upperColor; this.LowerColor = lowerColor; - this.ColorComponent = colorComponent; + this.Mode = mode; } /// @@ -54,7 +54,7 @@ public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerCo /// The color to use for pixels that are above the threshold. /// The color to use for pixels that are below the threshold. public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor) - : this(threshold, upperColor, lowerColor, BinaryThresholdColorComponent.Luminance) + : this(threshold, upperColor, lowerColor, BinaryThresholdMode.Luminance) { } @@ -73,10 +73,10 @@ public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerCo /// public Color LowerColor { get; } - /// - /// Gets a value indicating whether to use saturation value instead of luminance. + /// + /// Gets the defining the value to be compared to threshold. /// - public BinaryThresholdColorComponent ColorComponent { get; } + public BinaryThresholdMode Mode { get; } /// public IImageProcessor CreatePixelSpecificProcessor(Configuration configuration, Image source, Rectangle sourceRectangle) diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs index aa03cc27d2..5942c71641 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs @@ -45,7 +45,7 @@ protected override void OnFrameApply(ImageFrame source) upper, lower, threshold, - this.definition.ColorComponent, + this.definition.Mode, configuration); ParallelRowIterator.IterateRows( @@ -63,7 +63,7 @@ protected override void OnFrameApply(ImageFrame source) private readonly TPixel upper; private readonly TPixel lower; private readonly byte threshold; - private readonly BinaryThresholdColorComponent colorComponent; + private readonly BinaryThresholdMode mode; private readonly int startX; private readonly Configuration configuration; @@ -74,7 +74,7 @@ public RowOperation( TPixel upper, TPixel lower, byte threshold, - BinaryThresholdColorComponent colorComponent, + BinaryThresholdMode mode, Configuration configuration) { this.startX = startX; @@ -82,7 +82,7 @@ public RowOperation( this.upper = upper; this.lower = lower; this.threshold = threshold; - this.colorComponent = colorComponent; + this.mode = mode; this.configuration = configuration; } @@ -96,9 +96,9 @@ public void Invoke(int y, Span span) Span rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length); PixelOperations.Instance.ToRgb24(this.configuration, rowSpan, span); - switch (this.colorComponent) + switch (this.mode) { - case BinaryThresholdColorComponent.Luminance: + case BinaryThresholdMode.Luminance: { byte threshold = this.threshold; for (int x = 0; x < rowSpan.Length; x++) @@ -112,7 +112,7 @@ public void Invoke(int y, Span span) break; } - case BinaryThresholdColorComponent.Saturation: + case BinaryThresholdMode.Saturation: { float threshold = this.threshold / 255F; for (int x = 0; x < rowSpan.Length; x++) @@ -125,7 +125,7 @@ public void Invoke(int y, Span span) break; } - case BinaryThresholdColorComponent.MaxChroma: + case BinaryThresholdMode.MaxChroma: { float threshold = this.threshold / 2F; for (int x = 0; x < rowSpan.Length; x++) diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index a02ca36eeb..a2fb9f9bad 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -16,7 +16,7 @@ public void BinaryThreshold_CorrectProcessor() this.operations.BinaryThreshold(.23f); BinaryThresholdProcessor p = this.Verify(); 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.Black, p.LowerColor); } @@ -27,7 +27,7 @@ public void BinaryThreshold_rect_CorrectProcessor() this.operations.BinaryThreshold(.93f, this.rect); BinaryThresholdProcessor p = this.Verify(this.rect); 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.Black, p.LowerColor); } @@ -38,7 +38,7 @@ public void BinaryThreshold_CorrectProcessorWithUpperLower() this.operations.BinaryThreshold(.23f, Color.HotPink, Color.Yellow); BinaryThresholdProcessor p = this.Verify(); 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.Yellow, p.LowerColor); } @@ -48,7 +48,7 @@ public void BinaryThreshold_rect_CorrectProcessorWithUpperLower() { this.operations.BinaryThreshold(.93f, Color.HotPink, Color.Yellow, this.rect); BinaryThresholdProcessor p = this.Verify(this.rect); - Assert.Equal(BinaryThresholdColorComponent.Luminance, p.ColorComponent); + Assert.Equal(BinaryThresholdMode.Luminance, p.Mode); Assert.Equal(.93f, p.Threshold); Assert.Equal(Color.HotPink, p.UpperColor); Assert.Equal(Color.Yellow, p.LowerColor); @@ -57,10 +57,10 @@ public void BinaryThreshold_rect_CorrectProcessorWithUpperLower() [Fact] public void BinarySaturationThreshold_CorrectProcessor() { - this.operations.BinaryThreshold(.23f, BinaryThresholdColorComponent.Saturation); + this.operations.BinaryThreshold(.23f, BinaryThresholdMode.Saturation); BinaryThresholdProcessor p = this.Verify(); 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.Black, p.LowerColor); } @@ -68,10 +68,10 @@ public void BinarySaturationThreshold_CorrectProcessor() [Fact] 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(this.rect); 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.Black, p.LowerColor); } @@ -79,10 +79,10 @@ public void BinarySaturationThreshold_rect_CorrectProcessor() [Fact] 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(); 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.Yellow, p.LowerColor); } @@ -90,10 +90,10 @@ public void BinarySaturationThreshold_CorrectProcessorWithUpperLower() [Fact] 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(this.rect); 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.Yellow, p.LowerColor); } @@ -101,10 +101,10 @@ public void BinarySaturationThreshold_rect_CorrectProcessorWithUpperLower() [Fact] public void BinaryMaxChromaThreshold_CorrectProcessor() { - this.operations.BinaryThreshold(.23f, BinaryThresholdColorComponent.MaxChroma); + this.operations.BinaryThreshold(.23f, BinaryThresholdMode.MaxChroma); BinaryThresholdProcessor p = this.Verify(); 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.Black, p.LowerColor); } @@ -112,10 +112,10 @@ public void BinaryMaxChromaThreshold_CorrectProcessor() [Fact] 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(this.rect); 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.Black, p.LowerColor); } @@ -123,10 +123,10 @@ public void BinaryMaxChromaThreshold_rect_CorrectProcessor() [Fact] 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(); 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.Yellow, p.LowerColor); } @@ -134,10 +134,10 @@ public void BinaryMaxChromaThreshold_CorrectProcessorWithUpperLower() [Fact] 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(this.rect); 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.Yellow, p.LowerColor); } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 79ed4c7cdb..fd08eb2dea 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -63,7 +63,7 @@ public void ImageShouldApplyBinarySaturationThresholdFilter(TestImagePro { using (Image image = provider.GetImage()) { - image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.Saturation)); + image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.Saturation)); image.DebugSave(provider, value); image.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); } @@ -79,7 +79,7 @@ public void ImageShouldApplyBinarySaturationThresholdInBox(TestImageProv { 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.CompareToReferenceOutput(ImageComparer.Exact, provider, value.ToString("0.00", NumberFormatInfo.InvariantInfo)); } @@ -92,7 +92,7 @@ public void ImageShouldApplyBinaryMaxChromaThresholdFilter(TestImageProv { using (Image image = provider.GetImage()) { - image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdColorComponent.MaxChroma)); + image.Mutate(x => x.BinaryThreshold(value, BinaryThresholdMode.MaxChroma)); image.DebugSave(provider, value); if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework) @@ -117,7 +117,7 @@ public void ImageShouldApplyBinaryMaxChromaThresholdInBox(TestImageProvi { 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); if (!TestEnvironment.Is64BitProcess && TestEnvironment.IsFramework)