/// <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="mode">Selects the value 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, BinaryThresholdMode mode) => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, upperColor, lowerColor, mode));
/// <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="mode">The color component to be compared to threshold.</param> 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.Mode = mode; }
/// <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="mode">The color component to be compared to threshold.</param> public BinaryThresholdProcessor(float threshold, BinaryThresholdMode mode) : this(threshold, Color.White, Color.Black, mode) { }
/// <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="mode">Selects the value 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, BinaryThresholdMode mode, Rectangle rectangle) => source.ApplyProcessor(new BinaryThresholdProcessor(threshold, mode), rectangle);