mirror of https://github.com/SixLabors/ImageSharp
206 changed files with 1621 additions and 1544 deletions
@ -1,75 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing; |
|||
using SixLabors.ImageSharp.Processing.Processors; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Lomograph(source, GraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Lomograph(source, rectangle, GraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="options">The options effecting pixel blending.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
source.ApplyProcessor(new LomographProcessor<TPixel>(source.MemoryManager, options)); |
|||
return source; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="options">The options effecting pixel blending.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
source.ApplyProcessor(new LomographProcessor<TPixel>(source.MemoryManager, options), rectangle); |
|||
return source; |
|||
} |
|||
} |
|||
} |
|||
@ -1,75 +0,0 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing; |
|||
using SixLabors.ImageSharp.Processing.Processors; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static partial class ImageExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Polaroid(source, GraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
return Polaroid(source, rectangle, GraphicsOptions.Default); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="options">The options effecting pixel blending.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
source.ApplyProcessor(new PolaroidProcessor<TPixel>(source.MemoryManager, options)); |
|||
return source; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <param name="options">The options effecting pixel blending.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle, GraphicsOptions options) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
source.ApplyProcessor(new PolaroidProcessor<TPixel>(source.MemoryManager, options), rectangle); |
|||
return source; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for Kayyali edge detection
|
|||
/// </summary>
|
|||
internal static class KayyaliKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KayyaliX => |
|||
new float[,] |
|||
{ |
|||
{ 6, 0, -6 }, |
|||
{ 0, 0, 0 }, |
|||
{ -6, 0, 6 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KayyaliY => |
|||
new float[,] |
|||
{ |
|||
{ -6, 0, 6 }, |
|||
{ 0, 0, 0 }, |
|||
{ 6, 0, -6 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Kayyali operator filter. <see href="http://edgedetection.webs.com/"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class KayyaliProcessor<TPixel> : EdgeDetector2DProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KayyaliProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public KayyaliProcessor(bool grayscale) |
|||
: base(KayyaliKernels.KayyaliX, KayyaliKernels.KayyaliY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Kirsch operator filter. <see href="http://en.wikipedia.org/wiki/Kirsch_operator"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class KirschProcessor<TPixel> : EdgeDetectorCompassProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="KirschProcessor{TPixel}"/> 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 Fast2DArray<float> North => KirshKernels.KirschNorth; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> NorthWest => KirshKernels.KirschNorthWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> West => KirshKernels.KirschWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> SouthWest => KirshKernels.KirschSouthWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> South => KirshKernels.KirschSouth; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> SouthEast => KirshKernels.KirschSouthEast; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> East => KirshKernels.KirschEast; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> NorthEast => KirshKernels.KirschNorthEast; |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the eight matrices used for Kirsh edge detection
|
|||
/// </summary>
|
|||
internal static class KirshKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the North gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschNorth => |
|||
new float[,] |
|||
{ |
|||
{ 5, 5, 5 }, |
|||
{ -3, 0, -3 }, |
|||
{ -3, -3, -3 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschNorthWest => |
|||
new float[,] |
|||
{ |
|||
{ 5, 5, -3 }, |
|||
{ 5, 0, -3 }, |
|||
{ -3, -3, -3 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschWest => |
|||
new float[,] |
|||
{ |
|||
{ 5, -3, -3 }, |
|||
{ 5, 0, -3 }, |
|||
{ 5, -3, -3 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschSouthWest => |
|||
new float[,] |
|||
{ |
|||
{ -3, -3, -3 }, |
|||
{ 5, 0, -3 }, |
|||
{ 5, 5, -3 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschSouth => |
|||
new float[,] |
|||
{ |
|||
{ -3, -3, -3 }, |
|||
{ -3, 0, -3 }, |
|||
{ 5, 5, 5 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschSouthEast => |
|||
new float[,] |
|||
{ |
|||
{ -3, -3, -3 }, |
|||
{ -3, 0, 5 }, |
|||
{ -3, 5, 5 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschEast => |
|||
new float[,] |
|||
{ |
|||
{ -3, -3, 5 }, |
|||
{ -3, 0, 5 }, |
|||
{ -3, -3, 5 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> KirschNorthEast => |
|||
new float[,] |
|||
{ |
|||
{ -3, 5, 5 }, |
|||
{ -3, 0, 5 }, |
|||
{ -3, -3, -3 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <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>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class Laplacian3x3Processor<TPixel> : EdgeDetectorProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian3x3Processor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian3x3Processor(bool grayscale) |
|||
: base(LaplacianKernels.Laplacian3x3, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian 5x5 operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Discrete_Laplace_operator"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class Laplacian5x5Processor<TPixel> : EdgeDetectorProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Laplacian5x5Processor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public Laplacian5x5Processor(bool grayscale) |
|||
: base(LaplacianKernels.Laplacian5x5, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// A factory for creating Laplacian kernel matrices.
|
|||
/// </summary>
|
|||
internal static class LaplacianKernelFactory |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a Laplacian matrix, 2nd derivative, of an arbitrary length.
|
|||
/// <see href="https://stackoverflow.com/questions/19422029/how-to-calculate-a-laplacian-mask-or-any-size"/>
|
|||
/// </summary>
|
|||
/// <param name="length">The length of the matrix sides</param>
|
|||
/// <returns>The <see cref="Fast2DArray{T}"/></returns>
|
|||
public static Fast2DArray<float> CreateKernel(uint length) |
|||
{ |
|||
Guard.MustBeGreaterThanOrEqualTo(length, 3u, nameof(length)); |
|||
Guard.IsFalse(length % 2 == 0, nameof(length), "The kernel length must be an odd number."); |
|||
|
|||
var kernel = new Fast2DArray<float>((int)length); |
|||
|
|||
for (int y = 0; y < kernel.Height; y++) |
|||
{ |
|||
for (int x = 0; x < kernel.Width; x++) |
|||
{ |
|||
kernel[x, y] = -1; |
|||
} |
|||
} |
|||
|
|||
int mid = (int)(length / 2); |
|||
kernel[mid, mid] = (length * length) - 1; |
|||
|
|||
return kernel; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains Laplacian kernels of different sizes
|
|||
/// </summary>
|
|||
internal static class LaplacianKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the 3x3 Laplacian kernel
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> Laplacian3x3 => LaplacianKernelFactory.CreateKernel(3); |
|||
|
|||
/// <summary>
|
|||
/// Gets the 5x5 Laplacian kernel
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> Laplacian5x5 => LaplacianKernelFactory.CreateKernel(5); |
|||
|
|||
/// <summary>
|
|||
/// Gets the Laplacian of Gaussian kernel.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> LaplacianOfGaussianXY => |
|||
new float[,] |
|||
{ |
|||
{ 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 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Laplacian of Gaussian operator filter.
|
|||
/// <see href="http://fourier.eng.hmc.edu/e161/lectures/gradient/node8.html"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class LaplacianOfGaussianProcessor<TPixel> : EdgeDetectorProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="LaplacianOfGaussianProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public LaplacianOfGaussianProcessor(bool grayscale) |
|||
: base(LaplacianKernels.LaplacianOfGaussianXY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for Prewitt edge detection
|
|||
/// </summary>
|
|||
internal static class PrewittKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> PrewittX => |
|||
new float[,] |
|||
{ |
|||
{ -1, 0, 1 }, |
|||
{ -1, 0, 1 }, |
|||
{ -1, 0, 1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> PrewittY => |
|||
new float[,] |
|||
{ |
|||
{ 1, 1, 1 }, |
|||
{ 0, 0, 0 }, |
|||
{ -1, -1, -1 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Prewitt operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Prewitt_operator"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class PrewittProcessor<TPixel> : EdgeDetector2DProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PrewittProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public PrewittProcessor(bool grayscale) |
|||
: base(PrewittKernels.PrewittX, PrewittKernels.PrewittY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for RobertsCross edge detection
|
|||
/// </summary>
|
|||
internal static class RobertsCrossKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobertsCrossX => |
|||
new float[,] |
|||
{ |
|||
{ 1, 0 }, |
|||
{ 0, -1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobertsCrossY => |
|||
new float[,] |
|||
{ |
|||
{ 0, 1 }, |
|||
{ -1, 0 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Roberts Cross operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Roberts_cross"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class RobertsCrossProcessor<TPixel> : EdgeDetector2DProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobertsCrossProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public RobertsCrossProcessor(bool grayscale) |
|||
: base(RobertsCrossKernels.RobertsCrossX, RobertsCrossKernels.RobertsCrossY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for Robinson edge detection
|
|||
/// </summary>
|
|||
internal static class RobinsonKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the North gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonNorth => |
|||
new float[,] |
|||
{ |
|||
{ 1, 2, 1 }, |
|||
{ 0, 0, 0 }, |
|||
{ -1, -2, -1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthWest gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonNorthWest => |
|||
new float[,] |
|||
{ |
|||
{ 2, 1, 0 }, |
|||
{ 1, 0, -1 }, |
|||
{ 0, -1, -2 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the West gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonWest => |
|||
new float[,] |
|||
{ |
|||
{ 1, 0, -1 }, |
|||
{ 2, 0, -2 }, |
|||
{ 1, 0, -1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthWest gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonSouthWest => |
|||
new float[,] |
|||
{ |
|||
{ 0, -1, -2 }, |
|||
{ 1, 0, -1 }, |
|||
{ 2, 1, 0 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the South gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonSouth => |
|||
new float[,] |
|||
{ |
|||
{ -1, -2, -1 }, |
|||
{ 0, 0, 0 }, |
|||
{ 1, 2, 1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the SouthEast gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonSouthEast => |
|||
new float[,] |
|||
{ |
|||
{ -2, -1, 0 }, |
|||
{ -1, 0, 1 }, |
|||
{ 0, 1, 2 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the East gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonEast => |
|||
new float[,] |
|||
{ |
|||
{ -1, 0, 1 }, |
|||
{ -2, 0, 2 }, |
|||
{ -1, 0, 1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the NorthEast gradient operator
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> RobinsonNorthEast => |
|||
new float[,] |
|||
{ |
|||
{ 0, 1, 2 }, |
|||
{ -1, 0, 1 }, |
|||
{ -2, -1, 0 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Robinson operator filter.
|
|||
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class RobinsonProcessor<TPixel> : EdgeDetectorCompassProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="RobinsonProcessor{TPixel}"/> 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 Fast2DArray<float> North => RobinsonKernels.RobinsonNorth; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> NorthWest => RobinsonKernels.RobinsonNorthWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> West => RobinsonKernels.RobinsonWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> SouthWest => RobinsonKernels.RobinsonSouthWest; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> South => RobinsonKernels.RobinsonSouth; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> SouthEast => RobinsonKernels.RobinsonSouthEast; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> East => RobinsonKernels.RobinsonEast; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Fast2DArray<float> NorthEast => RobinsonKernels.RobinsonNorthEast; |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for Scharr edge detection
|
|||
/// </summary>
|
|||
internal static class ScharrKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> ScharrX => |
|||
new float[,] |
|||
{ |
|||
{ -3, 0, 3 }, |
|||
{ -10, 0, 10 }, |
|||
{ -3, 0, 3 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> ScharrY => |
|||
new float[,] |
|||
{ |
|||
{ 3, 10, 3 }, |
|||
{ 0, 0, 0 }, |
|||
{ -3, -10, -3 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Applies edge detection processing to the image using the Scharr operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator#Alternative_operators"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class ScharrProcessor<TPixel> : EdgeDetector2DProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ScharrProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public ScharrProcessor(bool grayscale) |
|||
: base(ScharrKernels.ScharrX, ScharrKernels.ScharrY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the kernels used for Sobel edge detection
|
|||
/// </summary>
|
|||
internal static class SobelKernels |
|||
{ |
|||
/// <summary>
|
|||
/// Gets the horizontal gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> SobelX => |
|||
new float[,] |
|||
{ |
|||
{ -1, 0, 1 }, |
|||
{ -2, 0, 2 }, |
|||
{ -1, 0, 1 } |
|||
}; |
|||
|
|||
/// <summary>
|
|||
/// Gets the vertical gradient operator.
|
|||
/// </summary>
|
|||
public static Fast2DArray<float> SobelY => |
|||
new float[,] |
|||
{ |
|||
{ -1, -2, -1 }, |
|||
{ 0, 0, 0 }, |
|||
{ 1, 2, 1 } |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Convolution.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// The Sobel operator filter.
|
|||
/// <see href="http://en.wikipedia.org/wiki/Sobel_operator"/>
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class SobelProcessor<TPixel> : EdgeDetector2DProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="SobelProcessor{TPixel}"/> class.
|
|||
/// </summary>
|
|||
/// <param name="grayscale">Whether to convert the image to grayscale before performing edge detection.</param>
|
|||
public SobelProcessor(bool grayscale) |
|||
: base(SobelKernels.SobelX, SobelKernels.SobelY, grayscale) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
namespace SixLabors.ImageSharp.Processing.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Enumerates the various types of defined color blindness filters.
|
|||
@ -0,0 +1,38 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Filters.Processors; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Adds extensions that allow the recreation of an old Lomograph camera effect to the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static class LomographExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new LomographProcessor<TPixel>()); |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Lomograph camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Lomograph<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new LomographProcessor<TPixel>(), rectangle); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Filters.Processors; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Adds extensions that allow the recreation of an old Polaroid camera effect to the <see cref="Image{TPixel}"/> type.
|
|||
/// </summary>
|
|||
public static class PolaroidExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>()); |
|||
|
|||
/// <summary>
|
|||
/// Alters the colors of the image recreating an old Polaroid camera effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
/// <param name="source">The image this method extends.</param>
|
|||
/// <param name="rectangle">
|
|||
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
|
|||
/// </param>
|
|||
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
|
|||
public static IImageProcessingContext<TPixel> Polaroid<TPixel>(this IImageProcessingContext<TPixel> source, Rectangle rectangle) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
=> source.ApplyProcessor(new PolaroidProcessor<TPixel>(), rectangle); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Processors.Overlays; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Filters.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Lomograph effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class LomographProcessor<TPixel> : FilterProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
private static readonly TPixel VeryDarkGreen = ColorBuilder<TPixel>.FromRGBA(0, 10, 0, 255); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="LomographProcessor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
public LomographProcessor() |
|||
: base(MatrixFilters.LomographFilter) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) |
|||
{ |
|||
new VignetteProcessor<TPixel>(VeryDarkGreen).Apply(source, sourceRectangle, configuration); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Processors.Overlays; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Filters.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Polaroid effect.
|
|||
/// </summary>
|
|||
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|||
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0); |
|||
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="PolaroidProcessor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
public PolaroidProcessor() |
|||
: base(MatrixFilters.PolaroidFilter) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) |
|||
{ |
|||
new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration); |
|||
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F).Apply(source, sourceRectangle, configuration); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +1,9 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Numerics; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors |
|||
namespace SixLabors.ImageSharp.Processing.Filters.Processors |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness.
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue