mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 54 additions and 52 deletions
@ -1,73 +1,70 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
using System; |
|
||||
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
using SixLabors.ImageSharp.Processing.Processors.Convolution; |
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution |
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution; |
||||
|
|
||||
|
[GroupOutput("Convolution")] |
||||
|
public class ConvolutionProcessorHelpersTest |
||||
{ |
{ |
||||
[GroupOutput("Convolution")] |
[Theory] |
||||
public class ConvolutionProcessorHelpersTest |
[InlineData(3)] |
||||
|
[InlineData(5)] |
||||
|
[InlineData(9)] |
||||
|
[InlineData(22)] |
||||
|
[InlineData(33)] |
||||
|
[InlineData(80)] |
||||
|
public void VerifyGaussianKernelDecomposition(int radius) |
||||
{ |
{ |
||||
[Theory] |
int kernelSize = (radius * 2) + 1; |
||||
[InlineData(3)] |
float sigma = radius / 3F; |
||||
[InlineData(5)] |
float[] kernel = ConvolutionProcessorHelpers.CreateGaussianBlurKernel(kernelSize, sigma); |
||||
[InlineData(9)] |
DenseMatrix<float> matrix = DotProduct(kernel, kernel); |
||||
[InlineData(22)] |
|
||||
[InlineData(33)] |
|
||||
[InlineData(80)] |
|
||||
public void VerifyGaussianKernelDecomposition(int radius) |
|
||||
{ |
|
||||
int kernelSize = (radius * 2) + 1; |
|
||||
float sigma = radius / 3F; |
|
||||
float[] kernel = ConvolutionProcessorHelpers.CreateGaussianBlurKernel(kernelSize, sigma); |
|
||||
DenseMatrix<float> matrix = DotProduct(kernel, kernel); |
|
||||
|
|
||||
bool result = matrix.TryGetLinearlySeparableComponents(out float[] row, out float[] column); |
bool result = matrix.TryGetLinearlySeparableComponents(out float[] row, out float[] column); |
||||
|
|
||||
Assert.True(result); |
Assert.True(result); |
||||
Assert.NotNull(row); |
Assert.NotNull(row); |
||||
Assert.NotNull(column); |
Assert.NotNull(column); |
||||
Assert.Equal(row.Length, matrix.Rows); |
Assert.Equal(row.Length, matrix.Rows); |
||||
Assert.Equal(column.Length, matrix.Columns); |
Assert.Equal(column.Length, matrix.Columns); |
||||
|
|
||||
float[,] dotProduct = DotProduct(row, column); |
float[,] dotProduct = DotProduct(row, column); |
||||
|
|
||||
for (int y = 0; y < column.Length; y++) |
for (int y = 0; y < column.Length; y++) |
||||
|
{ |
||||
|
for (int x = 0; x < row.Length; x++) |
||||
{ |
{ |
||||
for (int x = 0; x < row.Length; x++) |
Assert.True(Math.Abs(matrix[y, x] - dotProduct[y, x]) < 0.0001F); |
||||
{ |
|
||||
Assert.True(Math.Abs(matrix[y, x] - dotProduct[y, x]) < 0.0001F); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void VerifyNonSeparableMatrix() |
public void VerifyNonSeparableMatrix() |
||||
{ |
{ |
||||
bool result = LaplacianKernels.LaplacianOfGaussianXY.TryGetLinearlySeparableComponents( |
bool result = LaplacianKernels.LaplacianOfGaussianXY.TryGetLinearlySeparableComponents( |
||||
out float[] row, |
out float[] row, |
||||
out float[] column); |
out float[] column); |
||||
|
|
||||
Assert.False(result); |
Assert.False(result); |
||||
Assert.Null(row); |
Assert.Null(row); |
||||
Assert.Null(column); |
Assert.Null(column); |
||||
} |
} |
||||
|
|
||||
private static DenseMatrix<float> DotProduct(float[] row, float[] column) |
private static DenseMatrix<float> DotProduct(float[] row, float[] column) |
||||
{ |
{ |
||||
float[,] matrix = new float[column.Length, row.Length]; |
float[,] matrix = new float[column.Length, row.Length]; |
||||
|
|
||||
for (int x = 0; x < row.Length; x++) |
for (int x = 0; x < row.Length; x++) |
||||
|
{ |
||||
|
for (int y = 0; y < column.Length; y++) |
||||
{ |
{ |
||||
for (int y = 0; y < column.Length; y++) |
matrix[y, x] = row[x] * column[y]; |
||||
{ |
|
||||
matrix[y, x] = row[x] * column[y]; |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
return matrix; |
|
||||
} |
} |
||||
|
|
||||
|
return matrix; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue