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";