mirror of https://github.com/SixLabors/ImageSharp
38 changed files with 1107 additions and 634 deletions
@ -1,61 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Enumerates the various types of defined edge detection filters.
|
|||
/// </summary>
|
|||
public enum EdgeDetectionOperators |
|||
{ |
|||
/// <summary>
|
|||
/// The Kayyali operator filter.
|
|||
/// </summary>
|
|||
Kayyali, |
|||
|
|||
/// <summary>
|
|||
/// The Kirsch operator filter.
|
|||
/// </summary>
|
|||
Kirsch, |
|||
|
|||
/// <summary>
|
|||
/// The Laplacian3X3 operator filter.
|
|||
/// </summary>
|
|||
Laplacian3x3, |
|||
|
|||
/// <summary>
|
|||
/// The Laplacian5X5 operator filter.
|
|||
/// </summary>
|
|||
Laplacian5x5, |
|||
|
|||
/// <summary>
|
|||
/// The LaplacianOfGaussian operator filter.
|
|||
/// </summary>
|
|||
LaplacianOfGaussian, |
|||
|
|||
/// <summary>
|
|||
/// The Prewitt operator filter.
|
|||
/// </summary>
|
|||
Prewitt, |
|||
|
|||
/// <summary>
|
|||
/// The RobertsCross operator filter.
|
|||
/// </summary>
|
|||
RobertsCross, |
|||
|
|||
/// <summary>
|
|||
/// The Robinson operator filter.
|
|||
/// </summary>
|
|||
Robinson, |
|||
|
|||
/// <summary>
|
|||
/// The Scharr operator filter.
|
|||
/// </summary>
|
|||
Scharr, |
|||
|
|||
/// <summary>
|
|||
/// The Sobel operator filter.
|
|||
/// </summary>
|
|||
Sobel |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// Contains reusable static instances of known edge detection kernels.
|
|||
/// </summary>
|
|||
public static class KnownEdgeDetectorKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the Kayyali edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Kayyali { get; } = EdgeDetector2DKernel.KayyaliKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Kirsch edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Kirsch { get; } = EdgeDetectorCompassKernel.Kirsch; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian 3x3 edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian3x3 { get; } = EdgeDetectorKernel.Laplacian3x3; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian 5x5 edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian5x5 { get; } = EdgeDetectorKernel.Laplacian5x5; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian of Gaussian edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel LaplacianOfGaussian { get; } = EdgeDetectorKernel.LaplacianOfGaussian; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Prewitt edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Prewitt { get; } = EdgeDetector2DKernel.PrewittKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Roberts-Cross edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel RobertsCross { get; } = EdgeDetector2DKernel.RobertsCrossKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Robinson edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Robinson { get; } = EdgeDetectorCompassKernel.Robinson; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Scharr edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Scharr { get; } = EdgeDetector2DKernel.ScharrKernel; |
|||
|
|||
/// <summary>
|
|||
/// Gets the Sobel edge detector kernel.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel Sobel { get; } = EdgeDetector2DKernel.SobelKernel; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the two 1D gradient operators.
|
|||
/// </summary>
|
|||
public sealed class EdgeDetector2DProcessor : IImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetector2DProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="kernel">The 2D edge detector kernel.</param>
|
|||
/// <param name="grayscale">
|
|||
/// Whether to convert the image to grayscale before performing edge detection.
|
|||
/// </param>
|
|||
public EdgeDetector2DProcessor(EdgeDetector2DKernel kernel, bool grayscale) |
|||
{ |
|||
this.Kernel = kernel; |
|||
this.Grayscale = grayscale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the 2D edge detector kernel.
|
|||
/// </summary>
|
|||
public EdgeDetector2DKernel Kernel { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether to convert the image to grayscale before performing
|
|||
/// edge detection.
|
|||
/// </summary>
|
|||
public bool Grayscale { get; } |
|||
|
|||
/// <inheritdoc />
|
|||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
=> new EdgeDetector2DProcessor<TPixel>(configuration, this, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using eight gradient operators.
|
|||
/// </summary>
|
|||
public sealed class EdgeDetectorCompassProcessor : IImageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorCompassProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="kernel">The edge detector kernel.</param>
|
|||
/// <param name="grayscale">
|
|||
/// Whether to convert the image to grayscale before performing edge detection.
|
|||
/// </param>
|
|||
public EdgeDetectorCompassProcessor(EdgeDetectorCompassKernel kernel, bool grayscale) |
|||
{ |
|||
this.Kernel = kernel; |
|||
this.Grayscale = grayscale; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the edge detector kernel.
|
|||
/// </summary>
|
|||
public EdgeDetectorCompassKernel Kernel { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets a value indicating whether to convert the image to grayscale before performing
|
|||
/// edge detection.
|
|||
/// </summary>
|
|||
public bool Grayscale { get; } |
|||
|
|||
/// <inheritdoc />
|
|||
public IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, this, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Kayyali operator filter.
|
|||
/// See <see href="http://edgedetection.webs.com/"/>.
|
|||
/// </summary>
|
|||
public sealed class KayyaliProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KayyaliProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public KayyaliProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
KayyaliKernels.KayyaliX, |
|||
KayyaliKernels.KayyaliY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,55 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
internal abstract class CompassKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the North gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> North { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> NorthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> West { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> SouthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> South { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> SouthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> East { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator.
|
|||
/// </summary>
|
|||
public abstract DenseMatrix<float> NorthEast { get; } |
|||
|
|||
public DenseMatrix<float>[] Flatten() => |
|||
new[] |
|||
{ |
|||
this.North, this.NorthWest, this.West, this.SouthWest, |
|||
this.South, this.SouthEast, this.East, this.NorthEast |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of two 1D gradient operators.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetector2DKernel : IEquatable<EdgeDetector2DKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Kayyali operators.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel KayyaliKernel = new EdgeDetector2DKernel(KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Prewitt operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Prewitt_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel PrewittKernel = new EdgeDetector2DKernel(PrewittKernels.PrewittX, PrewittKernels.PrewittY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Roberts-Cross operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Roberts_cross"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel RobertsCrossKernel = new EdgeDetector2DKernel(RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Scharr operators.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel ScharrKernel = new EdgeDetector2DKernel(ScharrKernels.ScharrX, ScharrKernels.ScharrY); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing two Sobel operators.
|
|||
/// <see href="https://en.wikipedia.org/wiki/Sobel_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetector2DKernel SobelKernel = new EdgeDetector2DKernel(SobelKernels.SobelX, SobelKernels.SobelY); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetector2DKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="kernelX">The horizontal gradient operator.</param>
|
|||
/// <param name="kernelY">The vertical gradient operator.</param>
|
|||
public EdgeDetector2DKernel(DenseMatrix<float> kernelX, DenseMatrix<float> kernelY) |
|||
{ |
|||
Guard.IsTrue( |
|||
kernelX.Size.Equals(kernelY.Size), |
|||
$"{nameof(kernelX)} {nameof(kernelY)}", |
|||
"Kernel sizes must be the same."); |
|||
|
|||
this.KernelX = kernelX; |
|||
this.KernelY = kernelY; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelX { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelY { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetector2DKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetector2DKernel left, EdgeDetector2DKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetector2DKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetector2DKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetector2DKernel left, EdgeDetector2DKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is EdgeDetector2DKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetector2DKernel other) |
|||
=> this.KernelX.Equals(other.KernelX) |
|||
&& this.KernelY.Equals(other.KernelY); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => HashCode.Combine(this.KernelX, this.KernelY); |
|||
} |
|||
} |
|||
@ -0,0 +1,163 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of eight gradient operators.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetectorCompassKernel : IEquatable<EdgeDetectorCompassKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kenel comprised of Kirsch gradient operators.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Kirsch = |
|||
new EdgeDetectorCompassKernel( |
|||
KirschKernels.North, |
|||
KirschKernels.NorthWest, |
|||
KirschKernels.West, |
|||
KirschKernels.SouthWest, |
|||
KirschKernels.South, |
|||
KirschKernels.SouthEast, |
|||
KirschKernels.East, |
|||
KirschKernels.NorthEast); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kenel comprised of Robinson gradient operators.
|
|||
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorCompassKernel Robinson = |
|||
new EdgeDetectorCompassKernel( |
|||
RobinsonKernels.North, |
|||
RobinsonKernels.NorthWest, |
|||
RobinsonKernels.West, |
|||
RobinsonKernels.SouthWest, |
|||
RobinsonKernels.South, |
|||
RobinsonKernels.SouthEast, |
|||
RobinsonKernels.East, |
|||
RobinsonKernels.NorthEast); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorCompassKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="north">The north gradient operator.</param>
|
|||
/// <param name="northWest">The north-west gradient operator.</param>
|
|||
/// <param name="west">The west gradient operator.</param>
|
|||
/// <param name="southWest">The south-west gradient operator.</param>
|
|||
/// <param name="south">The south gradient operator.</param>
|
|||
/// <param name="southEast">The south-east gradient operator.</param>
|
|||
/// <param name="east">The east gradient operator.</param>
|
|||
/// <param name="northEast">The north-east gradient operator.</param>
|
|||
public EdgeDetectorCompassKernel( |
|||
DenseMatrix<float> north, |
|||
DenseMatrix<float> northWest, |
|||
DenseMatrix<float> west, |
|||
DenseMatrix<float> southWest, |
|||
DenseMatrix<float> south, |
|||
DenseMatrix<float> southEast, |
|||
DenseMatrix<float> east, |
|||
DenseMatrix<float> northEast) |
|||
{ |
|||
this.North = north; |
|||
this.NorthWest = northWest; |
|||
this.West = west; |
|||
this.SouthWest = southWest; |
|||
this.South = south; |
|||
this.SouthEast = southEast; |
|||
this.East = east; |
|||
this.NorthEast = northEast; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets the North gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> North { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> NorthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> West { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> SouthWest { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> South { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> SouthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> East { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> NorthEast { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorCompassKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetectorCompassKernel left, EdgeDetectorCompassKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorCompassKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorCompassKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetectorCompassKernel left, EdgeDetectorCompassKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) => obj is EdgeDetectorCompassKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetectorCompassKernel other) => this.North.Equals(other.North) && this.NorthWest.Equals(other.NorthWest) && this.West.Equals(other.West) && this.SouthWest.Equals(other.SouthWest) && this.South.Equals(other.South) && this.SouthEast.Equals(other.SouthEast) && this.East.Equals(other.East) && this.NorthEast.Equals(other.NorthEast); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
=> HashCode.Combine( |
|||
this.North, |
|||
this.NorthWest, |
|||
this.West, |
|||
this.SouthWest, |
|||
this.South, |
|||
this.SouthEast, |
|||
this.East, |
|||
this.NorthEast); |
|||
|
|||
internal DenseMatrix<float>[] Flatten() => |
|||
new[] |
|||
{ |
|||
this.North, this.NorthWest, this.West, this.SouthWest, |
|||
this.South, this.SouthEast, this.East, this.NorthEast |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an edge detection convolution kernel consisting of a single 2D gradient operator.
|
|||
/// </summary>
|
|||
public readonly struct EdgeDetectorKernel : IEquatable<EdgeDetectorKernel> |
|||
{ |
|||
/// <summary>
|
|||
/// An edge detection kernel containing a 3x3 Laplacian operator.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian3x3 = new EdgeDetectorKernel(LaplacianKernels.Laplacian3x3); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing a 5x5 Laplacian operator.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel Laplacian5x5 = new EdgeDetectorKernel(LaplacianKernels.Laplacian5x5); |
|||
|
|||
/// <summary>
|
|||
/// An edge detection kernel containing a Laplacian of Gaussian operator.
|
|||
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>.
|
|||
/// </summary>
|
|||
public static EdgeDetectorKernel LaplacianOfGaussian = new EdgeDetectorKernel(LaplacianKernels.LaplacianOfGaussianXY); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="EdgeDetectorKernel"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="kernelXY">The 2D gradient operator.</param>
|
|||
public EdgeDetectorKernel(DenseMatrix<float> kernelXY) |
|||
=> this.KernelXY = kernelXY; |
|||
|
|||
/// <summary>
|
|||
/// Gets the 2D gradient operator.
|
|||
/// </summary>
|
|||
public DenseMatrix<float> KernelXY { get; } |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator ==(EdgeDetectorKernel left, EdgeDetectorKernel right) |
|||
=> left.Equals(right); |
|||
|
|||
/// <summary>
|
|||
/// Checks whether two <see cref="EdgeDetectorKernel"/> structures are equal.
|
|||
/// </summary>
|
|||
/// <param name="left">The left hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <param name="right">The right hand <see cref="EdgeDetectorKernel"/> operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter;
|
|||
/// otherwise, false.
|
|||
/// </returns>
|
|||
public static bool operator !=(EdgeDetectorKernel left, EdgeDetectorKernel right) |
|||
=> !(left == right); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
=> obj is EdgeDetectorKernel kernel && this.Equals(kernel); |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool Equals(EdgeDetectorKernel other) |
|||
=> this.KernelXY.Equals(other.KernelXY); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() => this.KernelXY.GetHashCode(); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Kirsch operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class KirschProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KirschProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public KirschProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, new KirschKernels(), this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian 3x3 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
public sealed class Laplacian3x3Processor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian3x3Processor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian3x3Processor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian3x3, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Laplacian 5x5 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class Laplacian5x5Processor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian5x5Processor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian5x5Processor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.Laplacian5x5, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter.
|
|||
/// See <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>.
|
|||
/// </summary>
|
|||
public sealed class LaplacianOfGaussianProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="LaplacianOfGaussianProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public LaplacianOfGaussianProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorProcessor<TPixel>(configuration, LaplacianKernels.LaplacianOfGaussianXY, this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Prewitt operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class PrewittProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PrewittProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public PrewittProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
PrewittKernels.PrewittX, |
|||
PrewittKernels.PrewittY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Roberts Cross operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>.
|
|||
/// </summary>
|
|||
public sealed class RobertsCrossProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobertsCrossProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public RobertsCrossProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
RobertsCrossKernels.RobertsCrossX, |
|||
RobertsCrossKernels.RobertsCrossY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Robinson operator filter.
|
|||
/// See <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>.
|
|||
/// </summary>
|
|||
public sealed class RobinsonProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobinsonProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public RobinsonProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetectorCompassProcessor<TPixel>(configuration, new RobinsonKernels(), this.Grayscale, source, sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection processing using the Scharr operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
|
|||
/// </summary>
|
|||
public sealed class ScharrProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ScharrProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public ScharrProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
ScharrKernels.ScharrX, |
|||
ScharrKernels.ScharrY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Convolution |
|||
{ |
|||
/// <summary>
|
|||
/// Defines edge detection using the Sobel operator filter.
|
|||
/// See <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>.
|
|||
/// </summary>
|
|||
public sealed class SobelProcessor : EdgeDetectorProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="SobelProcessor"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public SobelProcessor(bool grayscale) |
|||
: base(grayscale) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public override IImageProcessor<TPixel> CreatePixelSpecificProcessor<TPixel>(Configuration configuration, Image<TPixel> source, Rectangle sourceRectangle) |
|||
=> new EdgeDetector2DProcessor<TPixel>( |
|||
configuration, |
|||
SobelKernels.SobelX, |
|||
SobelKernels.SobelY, |
|||
this.Grayscale, |
|||
source, |
|||
sourceRectangle); |
|||
} |
|||
} |
|||
@ -1,75 +1,201 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
using System.Diagnostics.CodeAnalysis; |
|||
using SixLabors.ImageSharp.Processing; |
|||
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
|||
using SixLabors.ImageSharp.Tests.TestUtilities; |
|||
|
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Processing.Convolution |
|||
{ |
|||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "OK. Used for TheoryData compatibility.")] |
|||
public class DetectEdgesTest : BaseImageOperationsExtensionTest |
|||
{ |
|||
[Fact] |
|||
public void DetectEdges_SobelProcessorDefaultsSet() |
|||
public void DetectEdges_EdgeDetector2DProcessorDefaultsSet() |
|||
{ |
|||
this.operations.DetectEdges(); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(); |
|||
|
|||
// TODO: Enable once we have updated the images
|
|||
SobelProcessor processor = this.Verify<SobelProcessor>(); |
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(KnownEdgeDetectorKernels.Sobel, processor.Kernel); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DetectEdges_Rect_SobelProcessorDefaultsSet() |
|||
public void DetectEdges_Rect_EdgeDetector2DProcessorDefaultsSet() |
|||
{ |
|||
this.operations.DetectEdges(this.rect); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(this.rect); |
|||
|
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(KnownEdgeDetectorKernels.Sobel, processor.Kernel); |
|||
} |
|||
|
|||
public static TheoryData<EdgeDetector2DKernel, bool> EdgeDetector2DKernelData = |
|||
new TheoryData<EdgeDetector2DKernel, bool> |
|||
{ |
|||
{ KnownEdgeDetectorKernels.Kayyali, true }, |
|||
{ KnownEdgeDetectorKernels.Kayyali, false }, |
|||
{ KnownEdgeDetectorKernels.Prewitt, true }, |
|||
{ KnownEdgeDetectorKernels.Prewitt, false }, |
|||
{ KnownEdgeDetectorKernels.RobertsCross, true }, |
|||
{ KnownEdgeDetectorKernels.RobertsCross, false }, |
|||
{ KnownEdgeDetectorKernels.Scharr, true }, |
|||
{ KnownEdgeDetectorKernels.Scharr, false }, |
|||
{ KnownEdgeDetectorKernels.Sobel, true }, |
|||
{ KnownEdgeDetectorKernels.Sobel, false }, |
|||
}; |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetector2DKernelData))] |
|||
public void DetectEdges_EdgeDetector2DProcessor_DefaultGrayScale_Set(EdgeDetector2DKernel kernel, bool _) |
|||
{ |
|||
this.operations.DetectEdges(kernel); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(); |
|||
|
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetector2DKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetector2DProcessor_DefaultGrayScale_Set(EdgeDetector2DKernel kernel, bool _) |
|||
{ |
|||
this.operations.DetectEdges(kernel, this.rect); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(this.rect); |
|||
|
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetector2DKernelData))] |
|||
public void DetectEdges_EdgeDetector2DProcessorSet(EdgeDetector2DKernel kernel, bool grayscale) |
|||
{ |
|||
this.operations.DetectEdges(kernel, grayscale); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(); |
|||
|
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetector2DKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetector2DProcessorSet(EdgeDetector2DKernel kernel, bool grayscale) |
|||
{ |
|||
this.operations.DetectEdges(kernel, grayscale, this.rect); |
|||
EdgeDetector2DProcessor processor = this.Verify<EdgeDetector2DProcessor>(this.rect); |
|||
|
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
public static TheoryData<EdgeDetectorKernel, bool> EdgeDetectorKernelData = |
|||
new TheoryData<EdgeDetectorKernel, bool> |
|||
{ |
|||
{ KnownEdgeDetectorKernels.Laplacian3x3, true }, |
|||
{ KnownEdgeDetectorKernels.Laplacian3x3, false }, |
|||
{ KnownEdgeDetectorKernels.Laplacian5x5, true }, |
|||
{ KnownEdgeDetectorKernels.Laplacian5x5, false }, |
|||
{ KnownEdgeDetectorKernels.LaplacianOfGaussian, true }, |
|||
{ KnownEdgeDetectorKernels.LaplacianOfGaussian, false }, |
|||
}; |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorKernelData))] |
|||
public void DetectEdges_EdgeDetectorProcessor_DefaultGrayScale_Set(EdgeDetectorKernel kernel, bool _) |
|||
{ |
|||
this.operations.DetectEdges(kernel); |
|||
EdgeDetectorProcessor processor = this.Verify<EdgeDetectorProcessor>(); |
|||
|
|||
// TODO: Enable once we have updated the images
|
|||
SobelProcessor processor = this.Verify<SobelProcessor>(this.rect); |
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
public static IEnumerable<object[]> EdgeDetectionTheoryData => new[] |
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetectorProcessor_DefaultGrayScale_Set(EdgeDetectorKernel kernel, bool _) |
|||
{ |
|||
new object[] { new TestType<KayyaliProcessor>(), EdgeDetectionOperators.Kayyali }, |
|||
new object[] { new TestType<KirschProcessor>(), EdgeDetectionOperators.Kirsch }, |
|||
new object[] { new TestType<Laplacian3x3Processor>(), EdgeDetectionOperators.Laplacian3x3 }, |
|||
new object[] { new TestType<Laplacian5x5Processor>(), EdgeDetectionOperators.Laplacian5x5 }, |
|||
new object[] { new TestType<LaplacianOfGaussianProcessor>(), EdgeDetectionOperators.LaplacianOfGaussian }, |
|||
new object[] { new TestType<PrewittProcessor>(), EdgeDetectionOperators.Prewitt }, |
|||
new object[] { new TestType<RobertsCrossProcessor>(), EdgeDetectionOperators.RobertsCross }, |
|||
new object[] { new TestType<RobinsonProcessor>(), EdgeDetectionOperators.Robinson }, |
|||
new object[] { new TestType<ScharrProcessor>(), EdgeDetectionOperators.Scharr }, |
|||
new object[] { new TestType<SobelProcessor>(), EdgeDetectionOperators.Sobel }, |
|||
}; |
|||
this.operations.DetectEdges(kernel, this.rect); |
|||
EdgeDetectorProcessor processor = this.Verify<EdgeDetectorProcessor>(this.rect); |
|||
|
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectionTheoryData))] |
|||
public void DetectEdges_filter_SobelProcessorDefaultsSet<TProcessor>(TestType<TProcessor> type, EdgeDetectionOperators filter) |
|||
where TProcessor : EdgeDetectorProcessor |
|||
[MemberData(nameof(EdgeDetectorKernelData))] |
|||
public void DetectEdges_EdgeDetectorProcessorSet(EdgeDetectorKernel kernel, bool grayscale) |
|||
{ |
|||
this.operations.DetectEdges(filter); |
|||
this.operations.DetectEdges(kernel, grayscale); |
|||
EdgeDetectorProcessor processor = this.Verify<EdgeDetectorProcessor>(); |
|||
|
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetectorProcessorSet(EdgeDetectorKernel kernel, bool grayscale) |
|||
{ |
|||
this.operations.DetectEdges(kernel, grayscale, this.rect); |
|||
EdgeDetectorProcessor processor = this.Verify<EdgeDetectorProcessor>(this.rect); |
|||
|
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
public static TheoryData<EdgeDetectorCompassKernel, bool> EdgeDetectorCompassKernelData = |
|||
new TheoryData<EdgeDetectorCompassKernel, bool> |
|||
{ |
|||
{ KnownEdgeDetectorKernels.Kirsch, true }, |
|||
{ KnownEdgeDetectorKernels.Kirsch, false }, |
|||
{ KnownEdgeDetectorKernels.Robinson, true }, |
|||
{ KnownEdgeDetectorKernels.Robinson, false }, |
|||
}; |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorCompassKernelData))] |
|||
public void DetectEdges_EdgeDetectorCompassProcessor_DefaultGrayScale_Set(EdgeDetectorCompassKernel kernel, bool _) |
|||
{ |
|||
this.operations.DetectEdges(kernel); |
|||
EdgeDetectorCompassProcessor processor = this.Verify<EdgeDetectorCompassProcessor>(); |
|||
|
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorCompassKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetectorCompassProcessor_DefaultGrayScale_Set(EdgeDetectorCompassKernel kernel, bool _) |
|||
{ |
|||
this.operations.DetectEdges(kernel, this.rect); |
|||
EdgeDetectorCompassProcessor processor = this.Verify<EdgeDetectorCompassProcessor>(this.rect); |
|||
|
|||
// TODO: Enable once we have updated the images
|
|||
var processor = this.Verify<TProcessor>(); |
|||
Assert.True(processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectorCompassKernelData))] |
|||
public void DetectEdges_EdgeDetectorCompassProcessorSet(EdgeDetectorCompassKernel kernel, bool grayscale) |
|||
{ |
|||
this.operations.DetectEdges(kernel, grayscale); |
|||
EdgeDetectorCompassProcessor processor = this.Verify<EdgeDetectorCompassProcessor>(); |
|||
|
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(EdgeDetectionTheoryData))] |
|||
public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet<TProcessor>(TestType<TProcessor> type, EdgeDetectionOperators filter) |
|||
where TProcessor : EdgeDetectorProcessor |
|||
[MemberData(nameof(EdgeDetectorCompassKernelData))] |
|||
public void DetectEdges_Rect_EdgeDetectorCompassProcessorSet(EdgeDetectorCompassKernel kernel, bool grayscale) |
|||
{ |
|||
bool grey = (int)filter % 2 == 0; |
|||
this.operations.DetectEdges(filter, grey); |
|||
this.operations.DetectEdges(kernel, grayscale, this.rect); |
|||
EdgeDetectorCompassProcessor processor = this.Verify<EdgeDetectorCompassProcessor>(this.rect); |
|||
|
|||
// TODO: Enable once we have updated the images
|
|||
var processor = this.Verify<TProcessor>(); |
|||
Assert.Equal(grey, processor.Grayscale); |
|||
Assert.Equal(grayscale, processor.Grayscale); |
|||
Assert.Equal(kernel, processor.Kernel); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,81 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Processing; |
|||
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Processing.Convolution.Processors |
|||
{ |
|||
public class EdgeDetectorKernelTests |
|||
{ |
|||
[Fact] |
|||
public void EdgeDetectorKernelEqualityOperatorTest() |
|||
{ |
|||
EdgeDetectorKernel kernel0 = KnownEdgeDetectorKernels.Laplacian3x3; |
|||
EdgeDetectorKernel kernel1 = KnownEdgeDetectorKernels.Laplacian3x3; |
|||
EdgeDetectorKernel kernel2 = KnownEdgeDetectorKernels.Laplacian5x5; |
|||
|
|||
Assert.True(kernel0 == kernel1); |
|||
Assert.False(kernel0 != kernel1); |
|||
|
|||
Assert.True(kernel0 != kernel2); |
|||
Assert.False(kernel0 == kernel2); |
|||
|
|||
Assert.True(kernel0.Equals((object)kernel1)); |
|||
Assert.True(kernel0.Equals(kernel1)); |
|||
|
|||
Assert.False(kernel0.Equals((object)kernel2)); |
|||
Assert.False(kernel0.Equals(kernel2)); |
|||
|
|||
Assert.Equal(kernel0.GetHashCode(), kernel1.GetHashCode()); |
|||
Assert.NotEqual(kernel0.GetHashCode(), kernel2.GetHashCode()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void EdgeDetector2DKernelEqualityOperatorTest() |
|||
{ |
|||
EdgeDetector2DKernel kernel0 = KnownEdgeDetectorKernels.Prewitt; |
|||
EdgeDetector2DKernel kernel1 = KnownEdgeDetectorKernels.Prewitt; |
|||
EdgeDetector2DKernel kernel2 = KnownEdgeDetectorKernels.RobertsCross; |
|||
|
|||
Assert.True(kernel0 == kernel1); |
|||
Assert.False(kernel0 != kernel1); |
|||
|
|||
Assert.True(kernel0 != kernel2); |
|||
Assert.False(kernel0 == kernel2); |
|||
|
|||
Assert.True(kernel0.Equals((object)kernel1)); |
|||
Assert.True(kernel0.Equals(kernel1)); |
|||
|
|||
Assert.False(kernel0.Equals((object)kernel2)); |
|||
Assert.False(kernel0.Equals(kernel2)); |
|||
|
|||
Assert.Equal(kernel0.GetHashCode(), kernel1.GetHashCode()); |
|||
Assert.NotEqual(kernel0.GetHashCode(), kernel2.GetHashCode()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void EdgeDetectorCompassKernelEqualityOperatorTest() |
|||
{ |
|||
EdgeDetectorCompassKernel kernel0 = KnownEdgeDetectorKernels.Kirsch; |
|||
EdgeDetectorCompassKernel kernel1 = KnownEdgeDetectorKernels.Kirsch; |
|||
EdgeDetectorCompassKernel kernel2 = KnownEdgeDetectorKernels.Robinson; |
|||
|
|||
Assert.True(kernel0 == kernel1); |
|||
Assert.False(kernel0 != kernel1); |
|||
|
|||
Assert.True(kernel0 != kernel2); |
|||
Assert.False(kernel0 == kernel2); |
|||
|
|||
Assert.True(kernel0.Equals((object)kernel1)); |
|||
Assert.True(kernel0.Equals(kernel1)); |
|||
|
|||
Assert.False(kernel0.Equals((object)kernel2)); |
|||
Assert.False(kernel0.Equals(kernel2)); |
|||
|
|||
Assert.Equal(kernel0.GetHashCode(), kernel1.GetHashCode()); |
|||
Assert.NotEqual(kernel0.GetHashCode(), kernel2.GetHashCode()); |
|||
} |
|||
} |
|||
} |
|||
@ -1 +1 @@ |
|||
Subproject commit 0d1f91e2fe1491f6dc2c137a8ea20460fde4404c |
|||
Subproject commit 6a003080674d1fedc66292c13ce5a357b2a33083 |
|||
Loading…
Reference in new issue