Browse Source

Make Conv2pass non-abstract

Former-commit-id: 9919e35aa1ace90a4a979ad258123a9d7d04be6a
Former-commit-id: e612077242f43084b942c8083b20d37de83af157
Former-commit-id: c3fcabaaf91d39e6a6174a4a0faad7bfccc951e2
af/merge-core
James Jackson-South 10 years ago
parent
commit
370aa7f29b
  1. 42
      src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs
  2. 17
      src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs
  3. 44
      src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs
  4. 46
      src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs

42
src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs

@ -10,25 +10,15 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class BoxBlurProcessor<TColor, TPacked> : Convolution2PassFilter<TColor, TPacked>
public class BoxBlurProcessor<TColor, TPacked> : ImageSampler<TColor, TPacked>
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <summary>
/// The maximum size of the kernal in either direction.
/// The maximum size of the kernel in either direction.
/// </summary>
private readonly int kernelSize;
/// <summary>
/// The vertical kernel
/// </summary>
private float[,] kernelY;
/// <summary>
/// The horizontal kernel
/// </summary>
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="BoxBlurProcessor{TColor, TPacked}"/> class.
/// </summary>
@ -38,26 +28,24 @@ namespace ImageProcessorCore.Processors
public BoxBlurProcessor(int radius = 7)
{
this.kernelSize = (radius * 2) + 1;
this.KernelX = this.CreateBoxKernel(true);
this.KernelY = this.CreateBoxKernel(false);
}
/// <inheritdoc/>
public override float[,] KernelX => this.kernelX;
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public float[,] KernelX { get; }
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public float[,] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
if (this.kernelY == null)
{
this.kernelY = this.CreateBoxKernel(false);
}
if (this.kernelX == null)
{
this.kernelX = this.CreateBoxKernel(true);
}
new Convolution2PassFilter<TColor, TPacked>(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY);
}
/// <summary>
@ -104,4 +92,4 @@ namespace ImageProcessorCore.Processors
return kernel;
}
}
}
}

17
src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs

@ -13,19 +13,30 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class Convolution2PassFilter<TColor, TPacked> : ImageSampler<TColor, TPacked>
public class Convolution2PassFilter<TColor, TPacked> : ImageSampler<TColor, TPacked>
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <summary>
/// Initializes a new instance of the <see cref="Convolution2PassFilter{TColor,TPacked}"/> class.
/// </summary>
/// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param>
public Convolution2PassFilter(float[,] kernelX, float[,] kernelY)
{
this.KernelX = kernelX;
this.KernelY = kernelY;
}
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public abstract float[,] KernelX { get; }
public float[,] KernelX { get; }
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public abstract float[,] KernelY { get; }
public float[,] KernelY { get; }
/// <inheritdoc/>
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)

44
src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GuassianBlurProcessor<TColor, TPacked> : Convolution2PassFilter<TColor, TPacked>
public class GuassianBlurProcessor<TColor, TPacked> : ImageSampler<TColor, TPacked>
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
@ -26,16 +26,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
private readonly float sigma;
/// <summary>
/// The vertical kernel
/// </summary>
private float[,] kernelY;
/// <summary>
/// The horizontal kernel
/// </summary>
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="GuassianBlurProcessor{TColor, TPacked}"/> class.
/// </summary>
@ -44,6 +34,8 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
@ -56,6 +48,8 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = (radius * 2) + 1;
this.sigma = radius;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
@ -72,26 +66,24 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = (radius * 2) + 1;
this.sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <inheritdoc/>
public override float[,] KernelX => this.kernelX;
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public float[,] KernelX { get; }
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public float[,] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
if (this.kernelY == null)
{
this.kernelY = this.CreateGaussianKernel(false);
}
if (this.kernelX == null)
{
this.kernelX = this.CreateGaussianKernel(true);
}
new Convolution2PassFilter<TColor, TPacked>(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY);
}
/// <summary>
@ -141,4 +133,4 @@ namespace ImageProcessorCore.Processors
return kernel;
}
}
}
}

46
src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs

@ -12,12 +12,12 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GuassianSharpenProcessor<TColor, TPacked> : Convolution2PassFilter<TColor, TPacked>
public class GuassianSharpenProcessor<TColor, TPacked> : ImageSampler<TColor, TPacked>
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <summary>
/// The maximum size of the kernal in either direction.
/// The maximum size of the kernel in either direction.
/// </summary>
private readonly int kernelSize;
@ -26,16 +26,6 @@ namespace ImageProcessorCore.Processors
/// </summary>
private readonly float sigma;
/// <summary>
/// The vertical kernel
/// </summary>
private float[,] kernelY;
/// <summary>
/// The horizontal kernel
/// </summary>
private float[,] kernelX;
/// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor{TColor, TPacked}"/> class.
/// </summary>
@ -46,6 +36,8 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = ((int)Math.Ceiling(sigma) * 2) + 1;
this.sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
@ -58,6 +50,8 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = (radius * 2) + 1;
this.sigma = radius;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
@ -74,26 +68,24 @@ namespace ImageProcessorCore.Processors
{
this.kernelSize = (radius * 2) + 1;
this.sigma = sigma;
this.KernelX = this.CreateGaussianKernel(true);
this.KernelY = this.CreateGaussianKernel(false);
}
/// <inheritdoc/>
public override float[,] KernelX => this.kernelX;
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public float[,] KernelX { get; }
/// <inheritdoc/>
public override float[,] KernelY => this.kernelY;
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public float[,] KernelY { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
if (this.kernelY == null)
{
this.kernelY = this.CreateGaussianKernel(false);
}
if (this.kernelX == null)
{
this.kernelX = this.CreateGaussianKernel(true);
}
new Convolution2PassFilter<TColor, TPacked>(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY);
}
/// <summary>
@ -179,4 +171,4 @@ namespace ImageProcessorCore.Processors
return kernel;
}
}
}
}
Loading…
Cancel
Save