From 30926a23dbdd0eca4141c818af8ef2ca11fe3881 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 15 Sep 2016 16:00:07 +1000 Subject: [PATCH] Add Robinson edge detection operator Former-commit-id: 1a1c53bdeb6a5a6040ea2da8202693689a8004a4 Former-commit-id: af63533f9f04e814c10bb41a456217fa569846f5 Former-commit-id: cfa93ef57fea2c3c24da41c9da4b7153c91c7d90 --- README.md | 1 + .../Filters/Options/EdgeDetection.cs | 5 ++ .../Samplers/DetectEdges.cs | 4 + .../EdgeDetection/RobinsonProcessor.cs | 82 +++++++++++++++++++ .../Processors/Samplers/DetectEdgesTest.cs | 3 +- 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs diff --git a/README.md b/README.md index c8196c8a5..3caa42b6a 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor - [x] LaplacianOfGaussian - [x] Prewitt - [x] RobertsCross + - [x] Robinson - [x] Scharr - [x] Sobel - Blurring/Sharpening diff --git a/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs b/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs index f637e4573..0132b10e3 100644 --- a/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs +++ b/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs @@ -45,6 +45,11 @@ namespace ImageProcessorCore /// RobertsCross, + /// + /// The Robinson operator filter. + /// + Robinson, + /// /// The Scharr operator filter. /// diff --git a/src/ImageProcessorCore/Samplers/DetectEdges.cs b/src/ImageProcessorCore/Samplers/DetectEdges.cs index 60006ea72..5281db031 100644 --- a/src/ImageProcessorCore/Samplers/DetectEdges.cs +++ b/src/ImageProcessorCore/Samplers/DetectEdges.cs @@ -113,6 +113,10 @@ namespace ImageProcessorCore processor = new RobertsCrossProcessor { Grayscale = grayscale }; break; + case EdgeDetection.Robinson: + processor = new RobinsonProcessor { Grayscale = grayscale }; + break; + case EdgeDetection.Scharr: processor = new ScharrProcessor { Grayscale = grayscale }; break; diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs new file mode 100644 index 000000000..31845b4f8 --- /dev/null +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -0,0 +1,82 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageProcessorCore.Processors +{ + /// + /// The Kirsch operator filter. + /// + /// + /// The pixel format. + /// The packed format. uint, long, float. + public class RobinsonProcessor : EdgeDetectorCompassFilter + where TColor : IPackedVector + where TPacked : struct + { + /// + public override float[,] North => new float[,] + { + { 1, 2, 1 }, + { 0, 0, 0 }, + { -1, -2, -1 } + }; + + /// + public override float[,] NorthWest => new float[,] + { + { 2, 1, 0 }, + { 1, 0, -1 }, + { 0, -1, -2 } + }; + + /// + public override float[,] West => new float[,] + { + { 1, 0, -1 }, + { 2, 0, -2 }, + { 1, 0, -1 } + }; + + /// + public override float[,] SouthWest => new float[,] + { + { 0, -1, -2 }, + { 1, 0, -1 }, + { 2, 1, 0 } + }; + + /// + public override float[,] South => new float[,] + { + { -1, -2, -1 }, + { 0, 0, 0 }, + { 1, 2, 1 } + }; + + /// + public override float[,] SouthEast => new float[,] + { + { -2, -1, 0 }, + { -1, 0, 1 }, + { 0, 1, 2 } + }; + + /// + public override float[,] East => new float[,] + { + { -1, 0, 1 }, + { -2, 0, 2 }, + { -1, 0, 1 } + }; + + /// + public override float[,] NorthEast => new float[,] + { + { 0, 1, 2 }, + { -1, 0, 1 }, + { -2, -1, 0 } + }; + } +} \ No newline at end of file diff --git a/tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs b/tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs index fde41b5d8..71896b6ef 100644 --- a/tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs +++ b/tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs @@ -21,12 +21,13 @@ namespace ImageProcessorCore.Tests EdgeDetection.LaplacianOfGaussian, EdgeDetection.Prewitt, EdgeDetection.RobertsCross, + EdgeDetection.Robinson, EdgeDetection.Scharr, EdgeDetection.Sobel, }; [Theory] - [MemberData("DetectEdgesFilters")] + [MemberData(nameof(DetectEdgesFilters))] public void ImageShouldApplyDetectEdgesFilter(EdgeDetection detector) { const string path = "TestOutput/DetectEdges";