mirror of https://github.com/SixLabors/ImageSharp
21 changed files with 145 additions and 327 deletions
@ -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,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); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue