Browse Source

Add Robinson edge detection operator

Former-commit-id: 1a1c53bdeb6a5a6040ea2da8202693689a8004a4
Former-commit-id: af63533f9f04e814c10bb41a456217fa569846f5
Former-commit-id: cfa93ef57fea2c3c24da41c9da4b7153c91c7d90
af/merge-core
James Jackson-South 10 years ago
parent
commit
30926a23db
  1. 1
      README.md
  2. 5
      src/ImageProcessorCore/Filters/Options/EdgeDetection.cs
  3. 4
      src/ImageProcessorCore/Samplers/DetectEdges.cs
  4. 82
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs
  5. 3
      tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs

1
README.md

@ -129,6 +129,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] LaplacianOfGaussian
- [x] Prewitt
- [x] RobertsCross
- [x] Robinson
- [x] Scharr
- [x] Sobel
- Blurring/Sharpening

5
src/ImageProcessorCore/Filters/Options/EdgeDetection.cs

@ -45,6 +45,11 @@ namespace ImageProcessorCore
/// </summary>
RobertsCross,
/// <summary>
/// The Robinson operator filter.
/// </summary>
Robinson,
/// <summary>
/// The Scharr operator filter.
/// </summary>

4
src/ImageProcessorCore/Samplers/DetectEdges.cs

@ -113,6 +113,10 @@ namespace ImageProcessorCore
processor = new RobertsCrossProcessor<TColor, TPacked> { Grayscale = grayscale };
break;
case EdgeDetection.Robinson:
processor = new RobinsonProcessor<TColor, TPacked> { Grayscale = grayscale };
break;
case EdgeDetection.Scharr:
processor = new ScharrProcessor<TColor, TPacked> { Grayscale = grayscale };
break;

82
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs

@ -0,0 +1,82 @@
// <copyright file="RobinsonProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Processors
{
/// <summary>
/// The Kirsch operator filter.
/// <see href="http://www.tutorialspoint.com/dip/Robinson_Compass_Mask.htm"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class RobinsonProcessor<TColor, TPacked> : EdgeDetectorCompassFilter<TColor, TPacked>
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] North => new float[,]
{
{ 1, 2, 1 },
{ 0, 0, 0 },
{ -1, -2, -1 }
};
/// <inheritdoc/>
public override float[,] NorthWest => new float[,]
{
{ 2, 1, 0 },
{ 1, 0, -1 },
{ 0, -1, -2 }
};
/// <inheritdoc/>
public override float[,] West => new float[,]
{
{ 1, 0, -1 },
{ 2, 0, -2 },
{ 1, 0, -1 }
};
/// <inheritdoc/>
public override float[,] SouthWest => new float[,]
{
{ 0, -1, -2 },
{ 1, 0, -1 },
{ 2, 1, 0 }
};
/// <inheritdoc/>
public override float[,] South => new float[,]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
};
/// <inheritdoc/>
public override float[,] SouthEast => new float[,]
{
{ -2, -1, 0 },
{ -1, 0, 1 },
{ 0, 1, 2 }
};
/// <inheritdoc/>
public override float[,] East => new float[,]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
};
/// <inheritdoc/>
public override float[,] NorthEast => new float[,]
{
{ 0, 1, 2 },
{ -1, 0, 1 },
{ -2, -1, 0 }
};
}
}

3
tests/ImageProcessorCore.Tests/Processors/Samplers/DetectEdgesTest.cs

@ -21,12 +21,13 @@ namespace ImageProcessorCore.Tests
EdgeDetection.LaplacianOfGaussian,
EdgeDetection.Prewitt,
EdgeDetection.RobertsCross,
EdgeDetection.Robinson,
EdgeDetection.Scharr,
EdgeDetection.Sobel,
};
[Theory]
[MemberData("DetectEdgesFilters")]
[MemberData(nameof(DetectEdgesFilters))]
public void ImageShouldApplyDetectEdgesFilter(EdgeDetection detector)
{
const string path = "TestOutput/DetectEdges";

Loading…
Cancel
Save