mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 62 additions and 67 deletions
@ -0,0 +1,62 @@ |
|||
// <copyright file="DetectEdgesTest.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests.Processing.Convolution |
|||
{ |
|||
using ImageSharp.PixelFormats; |
|||
using ImageSharp.Processing; |
|||
|
|||
using Xunit; |
|||
|
|||
public class DetectEdgesTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters |
|||
= new TheoryData<EdgeDetection> |
|||
{ |
|||
EdgeDetection.Kayyali, |
|||
EdgeDetection.Kirsch, |
|||
EdgeDetection.Lapacian3X3, |
|||
EdgeDetection.Lapacian5X5, |
|||
EdgeDetection.LaplacianOfGaussian, |
|||
EdgeDetection.Prewitt, |
|||
EdgeDetection.RobertsCross, |
|||
EdgeDetection.Robinson, |
|||
EdgeDetection.Scharr, |
|||
EdgeDetection.Sobel |
|||
}; |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelTypes)] |
|||
public void ImageShouldApplyDetectEdgesFilter<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage()) |
|||
{ |
|||
image.DetectEdges(detector) |
|||
.DebugSave(provider, detector.ToString(), Extensions.Bmp); |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelTypes)] |
|||
public void ImageShouldApplyDetectEdgesFilterInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector) |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> source = provider.GetImage()) |
|||
using (var image = new Image<TPixel>(source)) |
|||
{ |
|||
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
|||
|
|||
image.DetectEdges(detector, bounds) |
|||
.DebugSave(provider, detector.ToString(), Extensions.Bmp); |
|||
|
|||
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
|
|||
image.Fill(NamedColors<TPixel>.HotPink, bounds); |
|||
source.Fill(NamedColors<TPixel>.HotPink, bounds); |
|||
ImageComparer.CheckSimilarity(image, source); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
// <copyright file="DetectEdgesTest.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests |
|||
{ |
|||
using ImageSharp.Processing; |
|||
using System.IO; |
|||
|
|||
using ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
public class DetectEdgesTest : FileTestBase |
|||
{ |
|||
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters |
|||
= new TheoryData<EdgeDetection> |
|||
{ |
|||
EdgeDetection.Kayyali, |
|||
EdgeDetection.Kirsch, |
|||
EdgeDetection.Lapacian3X3, |
|||
EdgeDetection.Lapacian5X5, |
|||
EdgeDetection.LaplacianOfGaussian, |
|||
EdgeDetection.Prewitt, |
|||
EdgeDetection.RobertsCross, |
|||
EdgeDetection.Robinson, |
|||
EdgeDetection.Scharr, |
|||
EdgeDetection.Sobel |
|||
}; |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(DetectEdgesFilters))] |
|||
public void ImageShouldApplyDetectEdgesFilter(EdgeDetection detector) |
|||
{ |
|||
string path = this.CreateOutputDirectory("DetectEdges"); |
|||
|
|||
foreach (TestFile file in Files) |
|||
{ |
|||
string filename = file.GetFileName(detector); |
|||
using (Image<Rgba32> image = file.CreateImage()) |
|||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|||
{ |
|||
image.DetectEdges(detector).Save(output); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[Theory] |
|||
[MemberData(nameof(DetectEdgesFilters))] |
|||
public void ImageShouldApplyDetectEdgesFilterInBox(EdgeDetection detector) |
|||
{ |
|||
string path = this.CreateOutputDirectory("DetectEdges"); |
|||
|
|||
foreach (TestFile file in Files) |
|||
{ |
|||
string filename = file.GetFileName(detector + "-InBox"); |
|||
using (Image<Rgba32> image = file.CreateImage()) |
|||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|||
{ |
|||
image.DetectEdges(detector, new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2)) |
|||
.Save(output); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue