diff --git a/Settings.StyleCop b/Settings.StyleCop index caf5179c8..90469053c 100644 --- a/Settings.StyleCop +++ b/Settings.StyleCop @@ -1,5 +1,5 @@ - + enum exif @@ -11,14 +11,21 @@ unzig cb cr + Laplacian + Sobel + Scharr + rrggbb + rrggbbaa James Jackson-South - Copyright © James Jackson-South and contributors. -Licensed under the Apache License, Version 2.0. + + Copyright © James Jackson-South and contributors. + Licensed under the Apache License, Version 2.0. + diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs index 3e33b62a6..b58c7a885 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs @@ -42,10 +42,10 @@ namespace ImageProcessorCore.Processors /// public override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { - int kernelYHeight = KernelY.Length; - int kernelYWidth = KernelY[0].Length; - int kernelXHeight = KernelX.Length; - int kernelXWidth = KernelX[0].Length; + int kernelYHeight = this.KernelY.Length; + int kernelYWidth = this.KernelY[0].Length; + int kernelXHeight = this.KernelX.Length; + int kernelXWidth = this.KernelX[0].Length; int radiusY = kernelYHeight >> 1; int radiusX = kernelXWidth >> 1; @@ -98,16 +98,16 @@ namespace ImageProcessorCore.Processors if (fy < kernelXHeight) { - rX += KernelX[fy][fx] * r; - gX += KernelX[fy][fx] * g; - bX += KernelX[fy][fx] * b; + rX += this.KernelX[fy][fx] * r; + gX += this.KernelX[fy][fx] * g; + bX += this.KernelX[fy][fx] * b; } if (fx < kernelYWidth) { - rY += KernelY[fy][fx] * r; - gY += KernelY[fy][fx] * g; - bY += KernelY[fy][fx] * b; + rY += this.KernelY[fy][fx] * r; + gY += this.KernelY[fy][fx] * g; + bY += this.KernelY[fy][fx] * b; } } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/ConvolutionFilter.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/ConvolutionFilter.cs index 4a0b41501..d14a54858 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/ConvolutionFilter.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/ConvolutionFilter.cs @@ -21,7 +21,7 @@ namespace ImageProcessorCore.Processors /// Initializes a new instance of the class. /// /// The 2d gradient operator. - public ConvolutionFilter(float[,] kernelXY) + public ConvolutionFilter(float[][] kernelXY) { this.KernelXY = kernelXY; } @@ -29,12 +29,12 @@ namespace ImageProcessorCore.Processors /// /// Gets the 2d gradient operator. /// - public virtual float[,] KernelXY { get; } + public virtual float[][] KernelXY { get; } /// public override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { - float[,] kernelX = this.KernelXY; + float[][] kernelX = this.KernelXY; int kernelLength = kernelX.GetLength(0); int radius = kernelLength >> 1; @@ -82,9 +82,9 @@ namespace ImageProcessorCore.Processors float g = currentColor.Y; float b = currentColor.Z; - rX += kernelX[fy, fx] * r; - gX += kernelX[fy, fx] * g; - bX += kernelX[fy, fx] * b; + rX += kernelX[fy][fx] * r; + gX += kernelX[fy][fx] * g; + bX += kernelX[fy][fx] * b; } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorCompassFilter.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorCompassFilter.cs index 5cb1c3ded..2e3aeb365 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorCompassFilter.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorCompassFilter.cs @@ -21,42 +21,42 @@ namespace ImageProcessorCore.Processors /// /// Gets the North gradient operator /// - public abstract float[,] North { get; } + public abstract float[][] North { get; } /// /// Gets the NorthWest gradient operator /// - public abstract float[,] NorthWest { get; } + public abstract float[][] NorthWest { get; } /// /// Gets the West gradient operator /// - public abstract float[,] West { get; } + public abstract float[][] West { get; } /// /// Gets the SouthWest gradient operator /// - public abstract float[,] SouthWest { get; } + public abstract float[][] SouthWest { get; } /// /// Gets the South gradient operator /// - public abstract float[,] South { get; } + public abstract float[][] South { get; } /// /// Gets the SouthEast gradient operator /// - public abstract float[,] SouthEast { get; } + public abstract float[][] SouthEast { get; } /// /// Gets the East gradient operator /// - public abstract float[,] East { get; } + public abstract float[][] East { get; } /// /// Gets the NorthEast gradient operator /// - public abstract float[,] NorthEast { get; } + public abstract float[][] NorthEast { get; } /// public bool Grayscale { get; set; } @@ -64,7 +64,7 @@ namespace ImageProcessorCore.Processors /// public override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) { - float[][,] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; + float[][][] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs index 93956a6f1..e300cbb9a 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs @@ -20,7 +20,7 @@ namespace ImageProcessorCore.Processors /// /// Gets the 2d gradient operator. /// - public abstract float[,] KernelXY { get; } + public abstract float[][] KernelXY { get; } /// public override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index 1b91615d6..b16372fd8 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -5,24 +5,33 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Kayyali operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class KayyaliProcessor : EdgeDetector2DFilter where TColor : IPackedVector where TPacked : struct { - private static readonly float[][] kernelX = new float[3][] + /// + /// The horizontal gradient operator. + /// + private static readonly float[][] KayyaliX = { new float[] { 6, 0, -6 }, new float[] { 0, 0, 0 }, new float[] { -6, 0, 6 } }; - private static readonly float[][] kernelY = new float[3][] + /// + /// The vertical gradient operator. + /// + private static readonly float[][] KayyaliY = { new float[] { -6, 0, 6 }, new float[] { 0, 0, 0 }, @@ -30,9 +39,9 @@ namespace ImageProcessorCore.Processors }; /// - public override float[][] KernelX => kernelX; + public override float[][] KernelX => KayyaliX; /// - public override float[][] KernelY => kernelY; + public override float[][] KernelY => KayyaliY; } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KirschProcessor.cs index 30d39007c..529592a01 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -2,81 +2,123 @@ // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // - namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Kirsch operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class KirschProcessor : EdgeDetectorCompassFilter where TColor : IPackedVector where TPacked : struct { - /// - public override float[,] North => new float[,] + /// + /// The North gradient operator + /// + private static readonly float[][] KirschNorth = { - { 5, 5, 5 }, - { -3, 0, -3 }, - { -3, -3, -3 } + new float[] { 5, 5, 5 }, + new float[] { -3, 0, -3 }, + new float[] { -3, -3, -3 } }; - /// - public override float[,] NorthWest => new float[,] + /// + /// The NorthWest gradient operator + /// + private static readonly float[][] KirschNorthWest = { - { 5, 5, -3 }, - { 5, 0, -3 }, - { -3, -3, -3 } + new float[] { 5, 5, -3 }, + new float[] { 5, 0, -3 }, + new float[] { -3, -3, -3 } }; - /// - public override float[,] West => new float[,] + /// + /// The West gradient operator + /// + private static readonly float[][] KirschWest = { - { 5, -3, -3 }, - { 5, 0, -3 }, - { 5, -3, -3 } + new float[] { 5, -3, -3 }, + new float[] { 5, 0, -3 }, + new float[] { 5, -3, -3 } }; - /// - public override float[,] SouthWest => new float[,] + /// + /// The SouthWest gradient operator + /// + private static readonly float[][] KirschSouthWest = { - { -3, -3, -3 }, - { 5, 0, -3 }, - { 5, 5, -3 } + new float[] { -3, -3, -3 }, + new float[] { 5, 0, -3 }, + new float[] { 5, 5, -3 } }; - /// - public override float[,] South => new float[,] + /// + /// The South gradient operator + /// + private static readonly float[][] KirschSouth = { - { -3, -3, -3 }, - { -3, 0, -3 }, - { 5, 5, 5 } + new float[] { -3, -3, -3 }, + new float[] { -3, 0, -3 }, + new float[] { 5, 5, 5 } }; - /// - public override float[,] SouthEast => new float[,] + /// + /// The SouthEast gradient operator + /// + private static readonly float[][] KirschSouthEast = { - { -3, -3, -3 }, - { -3, 0, 5 }, - { -3, 5, 5 } + new float[] { -3, -3, -3 }, + new float[] { -3, 0, 5 }, + new float[] { -3, 5, 5 } }; - /// - public override float[,] East => new float[,] + /// + /// The East gradient operator + /// + private static readonly float[][] KirschEast = { - { -3, -3, 5 }, - { -3, 0, 5 }, - { -3, -3, 5 } + new float[] { -3, -3, 5 }, + new float[] { -3, 0, 5 }, + new float[] { -3, -3, 5 } }; - /// - public override float[,] NorthEast => new float[,] + /// + /// The NorthEast gradient operator + /// + private static readonly float[][] KirschNorthEast = { - { -3, 5, 5 }, - { -3, 0, 5 }, - { -3, -3, -3 } + new float[] { -3, 5, 5 }, + new float[] { -3, 0, 5 }, + new float[] { -3, -3, -3 } }; + + /// + public override float[][] North => KirschNorth; + + /// + public override float[][] NorthWest => KirschNorthWest; + + /// + public override float[][] West => KirschWest; + + /// + public override float[][] SouthWest => KirschSouthWest; + + /// + public override float[][] South => KirschSouth; + + /// + public override float[][] SouthEast => KirschSouthEast; + + /// + public override float[][] East => KirschEast; + + /// + public override float[][] NorthEast => KirschNorthEast; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index 47eb02202..1393b7d14 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -5,22 +5,30 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Laplacian 3 x 3 operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class Laplacian3X3Processor : EdgeDetectorFilter where TColor : IPackedVector where TPacked : struct { - /// - public override float[,] KernelXY => new float[,] + /// + /// The 2d gradient operator. + /// + private static readonly float[][] Laplacian3X3XY = new float[][] { - { -1, -1, -1 }, - { -1, 8, -1 }, - { -1, -1, -1 } + new float[] { -1, -1, -1 }, + new float[] { -1, 8, -1 }, + new float[] { -1, -1, -1 } }; + + /// + public override float[][] KernelXY => Laplacian3X3XY; } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index 90367162c..5a8c0125f 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -5,24 +5,32 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Laplacian 5 x 5 operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class Laplacian5X5Processor : EdgeDetectorFilter where TColor : IPackedVector where TPacked : struct { - /// - public override float[,] KernelXY => new float[,] + /// + /// The 2d gradient operator. + /// + private static readonly float[][] Laplacian5X5XY = { - { -1, -1, -1, -1, -1 }, - { -1, -1, -1, -1, -1 }, - { -1, -1, 24, -1, -1 }, - { -1, -1, -1, -1, -1 }, - { -1, -1, -1, -1, -1 } + new float[] { -1, -1, -1, -1, -1 }, + new float[] { -1, -1, -1, -1, -1 }, + new float[] { -1, -1, 24, -1, -1 }, + new float[] { -1, -1, -1, -1, -1 }, + new float[] { -1, -1, -1, -1, -1 } }; + + /// + public override float[][] KernelXY => Laplacian5X5XY; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index ec3bda8fe..6185bd17d 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -5,24 +5,32 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Laplacian of Gaussian operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class LaplacianOfGaussianProcessor : EdgeDetectorFilter where TColor : IPackedVector where TPacked : struct { - /// - public override float[,] KernelXY => new float[,] + /// + /// The 2d gradient operator. + /// + private static readonly float[][] LaplacianOfGaussianXY = { - { 0, 0, -1, 0, 0 }, - { 0, -1, -2, -1, 0 }, - { -1, -2, 16, -2, -1 }, - { 0, -1, -2, -1, 0 }, - { 0, 0, -1, 0, 0 } + new float[] { 0, 0, -1, 0, 0 }, + new float[] { 0, -1, -2, -1, 0 }, + new float[] { -1, -2, 16, -2, -1 }, + new float[] { 0, -1, -2, -1, 0 }, + new float[] { 0, 0, -1, 0, 0 } }; + + /// + public override float[][] KernelXY => LaplacianOfGaussianXY; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index 17e73e7b9..25cf9983f 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -5,24 +5,33 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Prewitt operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class PrewittProcessor : EdgeDetector2DFilter where TColor : IPackedVector where TPacked : struct { - private static readonly float[][] kernelX = new float[3][] + /// + /// The horizontal gradient operator. + /// + private static readonly float[][] PrewittX = { new float[] { -1, 0, 1 }, new float[] { -1, 0, 1 }, new float[] { -1, 0, 1 } }; - private static readonly float[][] kernelY = new float[3][] + /// + /// The vertical gradient operator. + /// + private static readonly float[][] PrewittY = { new float[] { 1, 1, 1 }, new float[] { 0, 0, 0 }, @@ -30,9 +39,9 @@ namespace ImageProcessorCore.Processors }; /// - public override float[][] KernelX => kernelX; + public override float[][] KernelX => PrewittX; /// - public override float[][] KernelY => kernelY; + public override float[][] KernelY => PrewittY; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index 6167e54bc..d132a7fc4 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -5,32 +5,41 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Roberts Cross operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class RobertsCrossProcessor : EdgeDetector2DFilter where TColor : IPackedVector where TPacked : struct { - private static readonly float[][] kernelX = new float[2][] + /// + /// The horizontal gradient operator. + /// + private static readonly float[][] RobertsCrossX = { new float[] { 1, 0 }, new float[] { 0, -1 } }; - private static readonly float[][] kernelY = new float[2][] + /// + /// The vertical gradient operator. + /// + private static readonly float[][] RobertsCrossY = { new float[] { 0, 1 }, new float[] { -1, 0 } }; /// - public override float[][] KernelX => kernelX; + public override float[][] KernelX => RobertsCrossX; /// - public override float[][] KernelY => kernelY; + public override float[][] KernelY => RobertsCrossY; } } diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index 31845b4f8..2bb804499 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -2,81 +2,123 @@ // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // - namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Kirsch operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class RobinsonProcessor : EdgeDetectorCompassFilter where TColor : IPackedVector where TPacked : struct { - /// - public override float[,] North => new float[,] + /// + /// The North gradient operator + /// + private static readonly float[][] RobinsonNorth = { - { 1, 2, 1 }, - { 0, 0, 0 }, - { -1, -2, -1 } + new float[] { 1, 2, 1 }, + new float[] { 0, 0, 0 }, + new float[] { -1, -2, -1 } }; - /// - public override float[,] NorthWest => new float[,] + /// + /// The NorthWest gradient operator + /// + private static readonly float[][] RobinsonNorthWest = { - { 2, 1, 0 }, - { 1, 0, -1 }, - { 0, -1, -2 } + new float[] { 2, 1, 0 }, + new float[] { 1, 0, -1 }, + new float[] { 0, -1, -2 } }; - /// - public override float[,] West => new float[,] + /// + /// The West gradient operator + /// + private static readonly float[][] RobinsonWest = { - { 1, 0, -1 }, - { 2, 0, -2 }, - { 1, 0, -1 } + new float[] { 1, 0, -1 }, + new float[] { 2, 0, -2 }, + new float[] { 1, 0, -1 } }; - /// - public override float[,] SouthWest => new float[,] + /// + /// The SouthWest gradient operator + /// + private static readonly float[][] RobinsonSouthWest = { - { 0, -1, -2 }, - { 1, 0, -1 }, - { 2, 1, 0 } + new float[] { 0, -1, -2 }, + new float[] { 1, 0, -1 }, + new float[] { 2, 1, 0 } }; - /// - public override float[,] South => new float[,] + /// + /// The South gradient operator + /// + private static readonly float[][] RobinsonSouth = { - { -1, -2, -1 }, - { 0, 0, 0 }, - { 1, 2, 1 } + new float[] { -1, -2, -1 }, + new float[] { 0, 0, 0 }, + new float[] { 1, 2, 1 } }; - /// - public override float[,] SouthEast => new float[,] + /// + /// The SouthEast gradient operator + /// + private static readonly float[][] RobinsonSouthEast = { - { -2, -1, 0 }, - { -1, 0, 1 }, - { 0, 1, 2 } + new float[] { -2, -1, 0 }, + new float[] { -1, 0, 1 }, + new float[] { 0, 1, 2 } }; - /// - public override float[,] East => new float[,] + /// + /// The East gradient operator + /// + private static readonly float[][] RobinsonEast = { - { -1, 0, 1 }, - { -2, 0, 2 }, - { -1, 0, 1 } + new float[] { -1, 0, 1 }, + new float[] { -2, 0, 2 }, + new float[] { -1, 0, 1 } }; - /// - public override float[,] NorthEast => new float[,] + /// + /// The NorthEast gradient operator + /// + private static readonly float[][] RobinsonNorthEast = { - { 0, 1, 2 }, - { -1, 0, 1 }, - { -2, -1, 0 } + new float[] { 0, 1, 2 }, + new float[] { -1, 0, 1 }, + new float[] { -2, -1, 0 } }; + + /// + public override float[][] North => RobinsonNorth; + + /// + public override float[][] NorthWest => RobinsonNorthWest; + + /// + public override float[][] West => RobinsonWest; + + /// + public override float[][] SouthWest => RobinsonSouthWest; + + /// + public override float[][] South => RobinsonSouth; + + /// + public override float[][] SouthEast => RobinsonSouthEast; + + /// + public override float[][] East => RobinsonEast; + + /// + public override float[][] NorthEast => RobinsonNorthEast; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index cbae93c40..47b8651c9 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -5,24 +5,33 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Scharr operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class ScharrProcessor : EdgeDetector2DFilter where TColor : IPackedVector where TPacked : struct { - private static readonly float[][] kernelX = new float[3][] + /// + /// The horizontal gradient operator. + /// + private static readonly float[][] ScharrX = new float[3][] { new float[] { -3, 0, 3 }, new float[] { -10, 0, 10 }, new float[] { -3, 0, 3 } }; - private static readonly float[][] kernelY = new float[3][] + /// + /// The vertical gradient operator. + /// + private static readonly float[][] ScharrY = new float[3][] { new float[] { 3, 10, 3 }, new float[] { 0, 0, 0 }, @@ -30,9 +39,9 @@ namespace ImageProcessorCore.Processors }; /// - public override float[][] KernelX => kernelX; + public override float[][] KernelX => ScharrX; /// - public override float[][] KernelY => kernelY; + public override float[][] KernelY => ScharrY; } } \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs index 4e657cb82..0a6f9b725 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -5,24 +5,33 @@ namespace ImageProcessorCore.Processors { + using System.Diagnostics.CodeAnalysis; + /// /// The Sobel operator filter. /// /// /// The pixel format. /// The packed format. uint, long, float. + [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] public class SobelProcessor : EdgeDetector2DFilter where TColor : IPackedVector where TPacked : struct { - private static readonly float[][] kernelX = new float[3][] + /// + /// The horizontal gradient operator. + /// + private static readonly float[][] SobelX = { new float[] { -1, 0, 1 }, new float[] { -2, 0, 2 }, new float[] { -1, 0, 1 } }; - private static readonly float[][] kernelY = new float[3][] + /// + /// The vertical gradient operator. + /// + private static readonly float[][] SobelY = { new float[] { -1, -2, -1 }, new float[] { 0, 0, 0 }, @@ -30,9 +39,9 @@ namespace ImageProcessorCore.Processors }; /// - public override float[][] KernelX => kernelX; + public override float[][] KernelX => SobelX; /// - public override float[][] KernelY => kernelY; + public override float[][] KernelY => SobelY; } }