From 8a3c7c8692d96f705e18be5b0f11f11aa20eed6d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 6 Jan 2016 12:25:42 +1100 Subject: [PATCH] Can now choose colors on binary thresholder. Former-commit-id: c25d6d2128a807c0980e021f3b735b8c6309f264 Former-commit-id: cc03c980479f3c5182bf98f660edcd340d66221c Former-commit-id: 47c7edace51bd78a97d7eee020a2200196d07f8c --- .../Filters/Binarization/Threshold.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ImageProcessor/Filters/Binarization/Threshold.cs b/src/ImageProcessor/Filters/Binarization/Threshold.cs index 43e929bbc..7e394f775 100644 --- a/src/ImageProcessor/Filters/Binarization/Threshold.cs +++ b/src/ImageProcessor/Filters/Binarization/Threshold.cs @@ -33,6 +33,16 @@ namespace ImageProcessor.Filters /// public float Value { get; } + /// + /// The color to use for pixels that are above the threshold. + /// + public Color UpperColor => Color.White; + + /// + /// The color to use for pixels that fall below the threshold. + /// + public Color LowerColor => Color.Black; + /// 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; } } });