Browse Source

Can now choose colors on binary thresholder.

Former-commit-id: c25d6d2128a807c0980e021f3b735b8c6309f264
Former-commit-id: cc03c980479f3c5182bf98f660edcd340d66221c
Former-commit-id: 47c7edace51bd78a97d7eee020a2200196d07f8c
pull/17/head
James Jackson-South 10 years ago
parent
commit
8a3c7c8692
  1. 14
      src/ImageProcessor/Filters/Binarization/Threshold.cs

14
src/ImageProcessor/Filters/Binarization/Threshold.cs

@ -33,6 +33,16 @@ namespace ImageProcessor.Filters
/// </summary>
public float Value { get; }
/// <summary>
/// The color to use for pixels that are above the threshold.
/// </summary>
public Color UpperColor => Color.White;
/// <summary>
/// The color to use for pixels that fall below the threshold.
/// </summary>
public Color LowerColor => Color.Black;
/// <inheritdoc/>
protected override void OnApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
{
@ -43,6 +53,8 @@ namespace ImageProcessor.Filters
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float threshold = this.Value;
Color upper = this.UpperColor;
Color lower = this.LowerColor;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
@ -60,7 +72,7 @@ namespace ImageProcessor.Filters
Color color = source[x, y];
// Any channel will do since it's greyscale.
target[x, y] = color.B >= threshold ? Color.White : Color.Black;
target[x, y] = color.B >= threshold ? upper : lower;
}
}
});

Loading…
Cancel
Save