From 370aa7f29bb56e178fa2537a61a7d57864f53852 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 19 Sep 2016 21:45:01 +1000 Subject: [PATCH] Make Conv2pass non-abstract Former-commit-id: 9919e35aa1ace90a4a979ad258123a9d7d04be6a Former-commit-id: e612077242f43084b942c8083b20d37de83af157 Former-commit-id: c3fcabaaf91d39e6a6174a4a0faad7bfccc951e2 --- .../Convolution/BoxBlurProcessor.cs | 42 ++++++----------- .../Convolution/Convolution2PassFilter.cs | 17 +++++-- .../Convolution/GuassianBlurProcessor.cs | 44 ++++++++---------- .../Convolution/GuassianSharpenProcessor.cs | 46 ++++++++----------- 4 files changed, 66 insertions(+), 83 deletions(-) diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs index 1b8430f5f2..4a2adee7b1 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/BoxBlurProcessor.cs @@ -10,25 +10,15 @@ namespace ImageProcessorCore.Processors /// /// The pixel format. /// The packed format. uint, long, float. - public class BoxBlurProcessor : Convolution2PassFilter + public class BoxBlurProcessor : ImageSampler where TColor : IPackedVector where TPacked : struct { /// - /// The maximum size of the kernal in either direction. + /// The maximum size of the kernel in either direction. /// private readonly int kernelSize; - /// - /// The vertical kernel - /// - private float[,] kernelY; - - /// - /// The horizontal kernel - /// - private float[,] kernelX; - /// /// Initializes a new instance of the class. /// @@ -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); } - /// - public override float[,] KernelX => this.kernelX; + /// + /// Gets the horizontal gradient operator. + /// + public float[,] KernelX { get; } - /// - public override float[,] KernelY => this.kernelY; + /// + /// Gets the vertical gradient operator. + /// + public float[,] KernelY { get; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + public override void Apply(ImageBase target, ImageBase 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(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY); } /// @@ -104,4 +92,4 @@ namespace ImageProcessorCore.Processors return kernel; } } -} +} \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs index ab6e13bc58..f66ac08a70 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2PassFilter.cs @@ -13,19 +13,30 @@ namespace ImageProcessorCore.Processors /// /// The pixel format. /// The packed format. uint, long, float. - public abstract class Convolution2PassFilter : ImageSampler + public class Convolution2PassFilter : ImageSampler where TColor : IPackedVector where TPacked : struct { + /// + /// Initializes a new instance of the class. + /// + /// The horizontal gradient operator. + /// The vertical gradient operator. + public Convolution2PassFilter(float[,] kernelX, float[,] kernelY) + { + this.KernelX = kernelX; + this.KernelY = kernelY; + } + /// /// Gets the horizontal gradient operator. /// - public abstract float[,] KernelX { get; } + public float[,] KernelX { get; } /// /// Gets the vertical gradient operator. /// - public abstract float[,] KernelY { get; } + public float[,] KernelY { get; } /// public override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs index 24dd01490a..d735b79c69 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianBlurProcessor.cs @@ -12,7 +12,7 @@ namespace ImageProcessorCore.Processors /// /// The pixel format. /// The packed format. uint, long, float. - public class GuassianBlurProcessor : Convolution2PassFilter + public class GuassianBlurProcessor : ImageSampler where TColor : IPackedVector where TPacked : struct { @@ -26,16 +26,6 @@ namespace ImageProcessorCore.Processors /// private readonly float sigma; - /// - /// The vertical kernel - /// - private float[,] kernelY; - - /// - /// The horizontal kernel - /// - private float[,] kernelX; - /// /// Initializes a new instance of the class. /// @@ -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); } /// @@ -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); } /// @@ -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); } - /// - public override float[,] KernelX => this.kernelX; + /// + /// Gets the horizontal gradient operator. + /// + public float[,] KernelX { get; } - /// - public override float[,] KernelY => this.kernelY; + /// + /// Gets the vertical gradient operator. + /// + public float[,] KernelY { get; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + public override void Apply(ImageBase target, ImageBase 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(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY); } /// @@ -141,4 +133,4 @@ namespace ImageProcessorCore.Processors return kernel; } } -} +} \ No newline at end of file diff --git a/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs b/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs index 18704faf18..e3a578ff77 100644 --- a/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs +++ b/src/ImageProcessorCore/Samplers/Processors/Convolution/GuassianSharpenProcessor.cs @@ -12,12 +12,12 @@ namespace ImageProcessorCore.Processors /// /// The pixel format. /// The packed format. uint, long, float. - public class GuassianSharpenProcessor : Convolution2PassFilter + public class GuassianSharpenProcessor : ImageSampler where TColor : IPackedVector where TPacked : struct { /// - /// The maximum size of the kernal in either direction. + /// The maximum size of the kernel in either direction. /// private readonly int kernelSize; @@ -26,16 +26,6 @@ namespace ImageProcessorCore.Processors /// private readonly float sigma; - /// - /// The vertical kernel - /// - private float[,] kernelY; - - /// - /// The horizontal kernel - /// - private float[,] kernelX; - /// /// Initializes a new instance of the class. /// @@ -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); } /// @@ -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); } /// @@ -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); } - /// - public override float[,] KernelX => this.kernelX; + /// + /// Gets the horizontal gradient operator. + /// + public float[,] KernelX { get; } - /// - public override float[,] KernelY => this.kernelY; + /// + /// Gets the vertical gradient operator. + /// + public float[,] KernelY { get; } /// - protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle) + public override void Apply(ImageBase target, ImageBase 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(this.KernelX, this.KernelY).Apply(target, source, targetRectangle, sourceRectangle, startY, endY); } /// @@ -179,4 +171,4 @@ namespace ImageProcessorCore.Processors return kernel; } } -} +} \ No newline at end of file