Browse Source

Can now choose colors on binary thresholder.

Former-commit-id: cacf1bcb98556979645ffa1d15a1d58f953888dd
Former-commit-id: 5122386fe60369744a707190dc9c4bd41301f9b7
Former-commit-id: 8969755a4338cf934f5a64a281a7343b6bc04ccb
af/merge-core
James Jackson-South 11 years ago
parent
commit
ff43644621
  1. 14
      src/ImageProcessor/Filters/Binarization/Threshold.cs

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

@ -33,6 +33,16 @@ namespace ImageProcessor.Filters
/// </summary> /// </summary>
public float Value { get; } 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/> /// <inheritdoc/>
protected override void OnApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle) 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) protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{ {
float threshold = this.Value; float threshold = this.Value;
Color upper = this.UpperColor;
Color lower = this.LowerColor;
int sourceY = sourceRectangle.Y; int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom; int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X; int startX = sourceRectangle.X;
@ -60,7 +72,7 @@ namespace ImageProcessor.Filters
Color color = source[x, y]; Color color = source[x, y];
// Any channel will do since it's greyscale. // 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