/// <summary> /// Applies binarization to the image splitting the pixels at the given threshold. /// </summary> /// <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="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="colorComponent">The color component to be compared to threshold.</param> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, Color upperColor, Color lowerColor, BinaryThresholdColorComponent colorComponent) => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, colorComponent));
/// <summary> /// Initializes a new instance of the <see cref="BinaryThresholdProcessor"/> class. /// </summary> /// <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="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> public BinaryThresholdProcessor(float threshold, Color upperColor, Color lowerColor, BinaryThresholdColorComponent colorComponent) { Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold)); this.Threshold = threshold; this.UpperColor = upperColor; this.LowerColor = lowerColor; this.ColorComponent = colorComponent; }
/// <summary> /// Initializes a new instance of the <see cref="BinaryThresholdProcessor"/> class. /// </summary> /// <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> public BinaryThresholdProcessor(float threshold, BinaryThresholdColorComponent colorComponent) : this(threshold, Color.White, Color.Black, colorComponent) { }
/// <summary> /// Applies binarization to the image splitting the pixels at the given threshold. /// </summary> /// <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="colorComponent">The color component to be compared to threshold.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> public static IImageProcessingContext BinaryThreshold( this IImageProcessingContext source, float threshold, BinaryThresholdColorComponent colorComponent, Rectangle rectangle) => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, colorComponent), rectangle);