1- // Copyright (c) Six Labors.
1+ // Copyright (c) Six Labors.
22// Licensed under the Apache License, Version 2.0.
33
44using SixLabors . ImageSharp . Processing . Processors . Binarization ;
@@ -11,29 +11,77 @@ namespace SixLabors.ImageSharp.Processing
1111 /// </summary>
1212 public static class BinaryThresholdExtensions
1313 {
14+ /// <summary>
15+ /// Applies binarization to the image splitting the pixels at the given threshold with
16+ /// Luminance as the color component to be compared to threshold.
17+ /// </summary>
18+ /// <param name="source">The image this method extends.</param>
19+ /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
20+ /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
21+ public static IImageProcessingContext BinaryThreshold ( this IImageProcessingContext source , float threshold )
22+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , BinaryThresholdColorComponent . Luminance ) ) ;
23+
1424 /// <summary>
1525 /// Applies binarization to the image splitting the pixels at the given threshold.
1626 /// </summary>
1727 /// <param name="source">The image this method extends.</param>
1828 /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
29+ /// <param name="colorComponent">The color component to be compared to threshold.</param>
30+ /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
31+ public static IImageProcessingContext BinaryThreshold (
32+ this IImageProcessingContext source ,
33+ float threshold ,
34+ BinaryThresholdColorComponent colorComponent )
35+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , colorComponent ) ) ;
36+
37+ /// <summary>
38+ /// Applies binarization to the image splitting the pixels at the given threshold with
39+ /// Luminance as the color component to be compared to threshold.
40+ /// </summary>
41+ /// <param name="source">The image this method extends.</param>
42+ /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
43+ /// <param name="rectangle">
44+ /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
45+ /// </param>
1946 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
20- public static IImageProcessingContext BinaryThreshold ( this IImageProcessingContext source , float threshold ) =>
21- source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold ) ) ;
47+ public static IImageProcessingContext BinaryThreshold (
48+ this IImageProcessingContext source ,
49+ float threshold ,
50+ Rectangle rectangle )
51+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , BinaryThresholdColorComponent . Luminance ) , rectangle ) ;
2252
2353 /// <summary>
2454 /// Applies binarization to the image splitting the pixels at the given threshold.
2555 /// </summary>
2656 /// <param name="source">The image this method extends.</param>
2757 /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
58+ /// <param name="colorComponent">The color component to be compared to threshold.</param>
2859 /// <param name="rectangle">
2960 /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
3061 /// </param>
3162 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3263 public static IImageProcessingContext BinaryThreshold (
3364 this IImageProcessingContext source ,
3465 float threshold ,
35- Rectangle rectangle ) =>
36- source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold ) , rectangle ) ;
66+ BinaryThresholdColorComponent colorComponent ,
67+ Rectangle rectangle )
68+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , colorComponent ) , rectangle ) ;
69+
70+ /// <summary>
71+ /// Applies binarization to the image splitting the pixels at the given threshold with
72+ /// Luminance as the color component to be compared to threshold.
73+ /// </summary>
74+ /// <param name="source">The image this method extends.</param>
75+ /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
76+ /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
77+ /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
78+ /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
79+ public static IImageProcessingContext BinaryThreshold (
80+ this IImageProcessingContext source ,
81+ float threshold ,
82+ Color upperColor ,
83+ Color lowerColor )
84+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor , BinaryThresholdColorComponent . Luminance ) ) ;
3785
3886 /// <summary>
3987 /// Applies binarization to the image splitting the pixels at the given threshold.
@@ -42,13 +90,35 @@ public static IImageProcessingContext BinaryThreshold(
4290 /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
4391 /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
4492 /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
93+ /// <param name="colorComponent">The color component to be compared to threshold.</param>
4594 /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4695 public static IImageProcessingContext BinaryThreshold (
4796 this IImageProcessingContext source ,
4897 float threshold ,
4998 Color upperColor ,
50- Color lowerColor ) =>
51- source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor ) ) ;
99+ Color lowerColor ,
100+ BinaryThresholdColorComponent colorComponent )
101+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor , colorComponent ) ) ;
102+
103+ /// <summary>
104+ /// Applies binarization to the image splitting the pixels at the given threshold with
105+ /// Luminance as the color component to be compared to threshold.
106+ /// </summary>
107+ /// <param name="source">The image this method extends.</param>
108+ /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
109+ /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
110+ /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
111+ /// <param name="rectangle">
112+ /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
113+ /// </param>
114+ /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
115+ public static IImageProcessingContext BinaryThreshold (
116+ this IImageProcessingContext source ,
117+ float threshold ,
118+ Color upperColor ,
119+ Color lowerColor ,
120+ Rectangle rectangle )
121+ => source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor , BinaryThresholdColorComponent . Luminance ) , rectangle ) ;
52122
53123 /// <summary>
54124 /// Applies binarization to the image splitting the pixels at the given threshold.
@@ -57,6 +127,7 @@ public static IImageProcessingContext BinaryThreshold(
57127 /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
58128 /// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
59129 /// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
130+ /// <param name="colorComponent">The color component to be compared to threshold.</param>
60131 /// <param name="rectangle">
61132 /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
62133 /// </param>
@@ -66,7 +137,8 @@ public static IImageProcessingContext BinaryThreshold(
66137 float threshold ,
67138 Color upperColor ,
68139 Color lowerColor ,
140+ BinaryThresholdColorComponent colorComponent ,
69141 Rectangle rectangle ) =>
70- source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor ) , rectangle ) ;
142+ source . ApplyProcessor ( new BinaryThresholdProcessor ( threshold , upperColor , lowerColor , colorComponent ) , rectangle ) ;
71143 }
72- }
144+ }
0 commit comments